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/variant/variant.hpp>
9
10#include <viam/api/common/v1/common.pb.h>
11#include <viam/api/component/arm/v1/arm.pb.h>
12
13#include <viam/sdk/common/pose.hpp>
14#include <viam/sdk/resource/stoppable.hpp>
15#include <viam/sdk/spatialmath/geometry.hpp>
16
17namespace viam {
18namespace sdk {
19
21
28class Arm : public Component, public Stoppable {
29 // Base class for use below in defining kinematics data strong typedefs
30 template <class Tag>
31 struct raw_bytes {
32 // Pre c++17 our derived classes aren't aggregate initializable so we need to define
33 // and using declare some ctors
34
35 raw_bytes() = default;
36 raw_bytes(std::vector<unsigned char> b) : bytes(std::move(b)) {}
37
38 std::vector<unsigned char> bytes{};
39 };
40
41 // Comparison operator helper for the data types below
42 template <class DataType>
43 struct EqCompare {
44 inline friend bool operator==(const DataType& lhs, const DataType& rhs) {
45 return lhs.bytes == rhs.bytes;
46 }
47 };
48
49 public:
50 struct KinematicsDataUnspecified : raw_bytes<KinematicsDataUnspecified>,
51 EqCompare<KinematicsDataUnspecified> {};
52 struct KinematicsDataSVA : raw_bytes<KinematicsDataSVA>, EqCompare<KinematicsDataSVA> {
53 using raw_bytes<KinematicsDataSVA>::raw_bytes;
54 };
55 struct KinematicsDataURDF : raw_bytes<KinematicsDataURDF>, EqCompare<KinematicsDataURDF> {
56 using raw_bytes<KinematicsDataURDF>::raw_bytes;
57 };
58
62 boost::variant<KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF>;
63
64 static KinematicsData from_proto(const viam::common::v1::GetKinematicsResponse& proto);
65
69 return get_end_position({});
70 }
71
75 virtual pose get_end_position(const AttributeMap& extra) = 0;
76
78 inline void move_to_position(const pose& pose) {
80 }
81
85 virtual void move_to_position(const pose& pose, const AttributeMap& extra) = 0;
86
88 inline std::vector<double> get_joint_positions() {
89 return get_joint_positions({});
90 }
91
94 virtual std::vector<double> get_joint_positions(const AttributeMap& extra) = 0;
95
98 virtual void move_to_joint_positions(const std::vector<double>& positions,
99 const AttributeMap& extra) = 0;
100
102 virtual bool is_moving() = 0;
103
107 virtual AttributeMap do_command(const AttributeMap& command) = 0;
108
113 virtual KinematicsData get_kinematics(const AttributeMap& extra) = 0;
114
119 return get_kinematics({});
120 }
121
123 inline std::vector<GeometryConfig> get_geometries() {
124 return get_geometries({});
125 }
126
129 virtual std::vector<GeometryConfig> get_geometries(const AttributeMap& extra) = 0;
130
131 API api() const override;
132
133 protected:
134 explicit Arm(std::string name);
135};
136
137template <>
139 static API api();
140};
141
142} // namespace sdk
143} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
An Arm represents a physical robot arm that exists in three-dimensional space.
Definition arm.hpp:28
virtual bool is_moving()=0
Reports if the arm is in motion.
virtual AttributeMap do_command(const AttributeMap &command)=0
Send/receive arbitrary commands to the resource.
KinematicsData get_kinematics()
Get the kinematics data associated with the arm.
Definition arm.hpp:118
std::vector< double > get_joint_positions()
Lists the joint positions in degrees of every joint on a robot arm.
Definition arm.hpp:88
virtual KinematicsData get_kinematics(const AttributeMap &extra)=0
Get the kinematics data associated with the arm.
virtual std::vector< double > get_joint_positions(const AttributeMap &extra)=0
Lists the joint positions in degrees of every joint on a robot arm.
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling arm.
Definition arm.hpp:123
virtual void move_to_position(const pose &pose, const AttributeMap &extra)=0
Move the end of the arm to.
virtual pose get_end_position(const AttributeMap &extra)=0
Get the current position of the end of the arm.
boost::variant< KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF > KinematicsData
The kinematics of the component.
Definition arm.hpp:61
virtual void move_to_joint_positions(const std::vector< double > &positions, const AttributeMap &extra)=0
Move each joint on the arm to the corresponding angle specified in.
pose get_end_position()
Get the current position of the end of the arm.
Definition arm.hpp:68
void move_to_position(const pose &pose)
Move the end of the arm to.
Definition arm.hpp:78
virtual std::vector< GeometryConfig > get_geometries(const AttributeMap &extra)=0
Returns GeometryConfigs associated with the calling arm.
API api() const override
Returns the API associated with a particular resource.
Definition component.hpp:14
virtual std::string name() const
Return the resource's name.
Definition stoppable.hpp:8
Definition resource_api.hpp:50
Definition pose.hpp:18