Viam C++ SDK current
Loading...
Searching...
No Matches
arm.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <boost/optional/optional.hpp>
9#include <boost/variant/variant.hpp>
10
11#include <viam/sdk/common/mesh.hpp>
12#include <viam/sdk/common/pose.hpp>
13#include <viam/sdk/resource/stoppable.hpp>
14#include <viam/sdk/spatialmath/geometry.hpp>
15
16namespace viam {
17namespace sdk {
18
20
27class Arm : public Component, public Stoppable {
28 // Base class for use below in defining kinematics data strong typedefs
29 template <class Tag>
30 struct raw_bytes {
31 // Pre c++17 our derived classes aren't aggregate initializable so we need to define
32 // and using declare some ctors
33
34 raw_bytes() = default;
35 raw_bytes(std::vector<unsigned char> b) : bytes(std::move(b)) {}
36
37 std::vector<unsigned char> bytes{};
38 };
39
40 // Comparison operator helper for the data types below
41 template <class DataType>
42 struct EqCompare {
43 inline friend bool operator==(const DataType& lhs, const DataType& rhs) {
44 return lhs.bytes == rhs.bytes;
45 }
46 };
47
48 public:
49 struct KinematicsDataUnspecified : raw_bytes<KinematicsDataUnspecified>,
50 EqCompare<KinematicsDataUnspecified> {};
51 struct KinematicsDataSVA : raw_bytes<KinematicsDataSVA>, EqCompare<KinematicsDataSVA> {
52 using raw_bytes<KinematicsDataSVA>::raw_bytes;
53 };
54 struct KinematicsDataURDF : raw_bytes<KinematicsDataURDF>, EqCompare<KinematicsDataURDF> {
55 using raw_bytes<KinematicsDataURDF>::raw_bytes;
56 };
57
61 boost::variant<KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF>;
62
64 struct MoveOptions {
65 boost::optional<double> max_vel_degs_per_sec;
66 boost::optional<double> max_acc_degs_per_sec2;
67 };
68
72 return get_end_position({});
73 }
74
78 virtual pose get_end_position(const ProtoStruct& extra) = 0;
79
81 inline void move_to_position(const pose& pose) {
83 }
84
88 virtual void move_to_position(const pose& pose, const ProtoStruct& extra) = 0;
89
91 inline std::vector<double> get_joint_positions() {
92 return get_joint_positions({});
93 }
94
97 virtual std::vector<double> get_joint_positions(const ProtoStruct& extra) = 0;
98
100 inline void move_to_joint_positions(const std::vector<double>& positions) {
101 return move_to_joint_positions(positions, {});
102 }
103
106 virtual void move_to_joint_positions(const std::vector<double>& positions,
107 const ProtoStruct& extra) = 0;
108
113 inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
114 const MoveOptions& options) {
115 return move_through_joint_positions(positions, options, {});
116 }
117
121 virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
122 const MoveOptions& options,
123 const ProtoStruct& extra) = 0;
124
126 virtual bool is_moving() = 0;
127
131 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
132
137 virtual KinematicsData get_kinematics(const ProtoStruct& extra) = 0;
138
143 return get_kinematics({});
144 }
145
149 virtual std::map<std::string, mesh> get_3d_models(const ProtoStruct& extra) = 0;
150
153 inline std::map<std::string, mesh> get_3d_models() {
154 return get_3d_models({});
155 }
156
158 inline std::vector<GeometryConfig> get_geometries() {
159 return get_geometries({});
160 }
161
164 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
165
166 API api() const override;
167
168 protected:
169 explicit Arm(std::string name);
170};
171
172template <>
174 static API api();
175};
176
177} // namespace sdk
178} // namespace viam
Definition resource_api.hpp:21
An Arm represents a physical robot arm that exists in three-dimensional space.
Definition arm.hpp:27
virtual bool is_moving()=0
Reports if the arm is in motion.
virtual void move_through_joint_positions(const std::vector< std::vector< double > > &positions, const MoveOptions &options, const ProtoStruct &extra)=0
Move each joint on the arm through the positions specified in.
virtual void move_to_position(const pose &pose, const ProtoStruct &extra)=0
Move the end of the arm to.
virtual std::vector< double > get_joint_positions(const ProtoStruct &extra)=0
Lists the joint positions in degrees of every joint on a robot arm.
KinematicsData get_kinematics()
Get the kinematics data associated with the arm.
Definition arm.hpp:142
std::vector< double > get_joint_positions()
Lists the joint positions in degrees of every joint on a robot arm.
Definition arm.hpp:91
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
void move_to_joint_positions(const std::vector< double > &positions)
Move each joint on the arm to the corresponding angle specified in.
Definition arm.hpp:100
virtual KinematicsData get_kinematics(const ProtoStruct &extra)=0
Get the kinematics data associated with the arm.
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling arm.
Definition arm.hpp:158
boost::variant< KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF > KinematicsData
The kinematics of the component.
Definition arm.hpp:60
virtual std::map< std::string, mesh > get_3d_models(const ProtoStruct &extra)=0
Returns 3DModels associated with the calling arm.
virtual void move_to_joint_positions(const std::vector< double > &positions, const ProtoStruct &extra)=0
Move each joint on the arm to the corresponding angle specified in.
void move_through_joint_positions(const std::vector< std::vector< double > > &positions, const MoveOptions &options)
Move each joint on the arm through the positions specified in.
Definition arm.hpp:113
std::map< std::string, mesh > get_3d_models()
Returns 3DModels associated with the calling arm.
Definition arm.hpp:153
pose get_end_position()
Get the current position of the end of the arm.
Definition arm.hpp:71
void move_to_position(const pose &pose)
Move the end of the arm to.
Definition arm.hpp:81
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling arm.
virtual pose get_end_position(const ProtoStruct &extra)=0
Get the current position of the end of the arm.
API api() const override
Returns the API associated with a particular resource.
Definition component.hpp:10
virtual std::string name() const
Return the resource's name.
Definition stoppable.hpp:8
Definition resource_api.hpp:46
Movement specifications for move_through_join_positions.
Definition arm.hpp:64
Definition pose.hpp:30