Viam C++ SDK current
Loading...
Searching...
No Matches
arm.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <chrono>
7#include <cstdint>
8#include <functional>
9#include <string>
10#include <vector>
11
12#include <boost/optional/optional.hpp>
13#include <boost/variant/variant.hpp>
14
15#include <viam/sdk/common/kinematics.hpp>
16#include <viam/sdk/common/mesh.hpp>
17#include <viam/sdk/common/pose.hpp>
18#include <viam/sdk/common/proto_convert.hpp>
19#include <viam/sdk/resource/stoppable.hpp>
20#include <viam/sdk/spatialmath/geometry.hpp>
21
22namespace viam {
23namespace component {
24namespace arm {
25namespace v1 {
26
27class TrajectoryPoint;
28class MoveThroughJointPositionsStreamedResponse;
29class GetPropertiesResponse;
30
31} // namespace v1
32} // namespace arm
33} // namespace component
34} // namespace viam
35
36namespace viam {
37namespace sdk {
38
40
47class Arm : public Component, public Stoppable {
48 public:
51 [[deprecated("Use ::viam::sdk::KinematicsDataUnspecified instead")]] =
53 using KinematicsDataSVA [[deprecated("Use ::viam::sdk::KinematicsDataSVA instead")]] =
55 using KinematicsDataURDF [[deprecated("Use ::viam::sdk::KinematicsDataURDF instead")]] =
57 using KinematicsData [[deprecated("Use ::viam::sdk::KinematicsData instead")]] =
58 ::viam::sdk::KinematicsData;
59
61 using MoveLimit = boost::variant<double, std::vector<double>>;
62
64 struct MoveOptions {
65 boost::optional<MoveLimit> max_vel_degs_per_sec;
66 boost::optional<MoveLimit> max_acc_degs_per_sec2;
67 boost::optional<double> max_tcp_speed;
68 };
69
72 struct properties {
74 bool support_manual_mode = false;
77 };
78
82 return get_end_position({});
83 }
84
88 virtual pose get_end_position(const ProtoStruct& extra) = 0;
89
91 inline void move_to_position(const pose& pose) {
93 }
94
98 virtual void move_to_position(const pose& pose, const ProtoStruct& extra) = 0;
99
101 inline std::vector<double> get_joint_positions() {
102 return get_joint_positions({});
103 }
104
107 virtual std::vector<double> get_joint_positions(const ProtoStruct& extra) = 0;
108
110 inline void move_to_joint_positions(const std::vector<double>& positions) {
111 return move_to_joint_positions(positions, {});
112 }
113
116 virtual void move_to_joint_positions(const std::vector<double>& positions,
117 const ProtoStruct& extra) = 0;
118
123 inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
124 const MoveOptions& options) {
125 return move_through_joint_positions(positions, options, {});
126 }
127
131 virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
132 const MoveOptions& options,
133 const ProtoStruct& extra) = 0;
134
148 std::vector<double> velocities_degs_per_sec;
149 boost::optional<std::vector<double>> accelerations_degs_per_sec2;
150 };
151
158 std::chrono::microseconds time;
159
161 std::vector<double> positions;
162
164 boost::optional<kinematic_constraints> constraints;
165 };
166
171
173 enum class stream_outcome : std::uint8_t {
174 k_completed = 0,
176 1,
177 };
178
184 const std::function<boost::optional<std::vector<trajectory_point>>()>& batch_source,
185 const std::function<bool(trajectory_update)>& update_handler) {
186 return move_through_joint_positions_streamed(batch_source, update_handler, {});
187 }
188
230 const std::function<boost::optional<std::vector<trajectory_point>>()>& batch_source,
231 const std::function<bool(trajectory_update)>& update_handler,
232 const ProtoStruct& extra) = 0;
233
235 virtual bool is_moving() = 0;
236
239 virtual ProtoStruct get_status() = 0;
240
244 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
245
249 virtual ::viam::sdk::KinematicsData get_kinematics(const ProtoStruct& extra) = 0;
250
253 inline ::viam::sdk::KinematicsData get_kinematics() {
254 return get_kinematics({});
255 }
256
260 virtual std::map<std::string, mesh> get_3d_models(const ProtoStruct& extra) = 0;
261
264 inline std::map<std::string, mesh> get_3d_models() {
265 return get_3d_models({});
266 }
267
269 inline std::vector<GeometryConfig> get_geometries() {
270 return get_geometries({});
271 }
272
275 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
276
280 return get_properties({});
281 }
282
286 virtual properties get_properties(const ProtoStruct& extra) = 0;
287
291 inline void set_manual_mode(bool manual_mode) {
292 return set_manual_mode(manual_mode, std::chrono::seconds::zero(), {});
293 }
294
299 inline void set_manual_mode(bool manual_mode, std::chrono::seconds enabled_for) {
300 return set_manual_mode(manual_mode, enabled_for, {});
301 }
302
308 virtual void set_manual_mode(bool manual_mode,
309 std::chrono::seconds enabled_for,
310 const ProtoStruct& extra) = 0;
311
314 inline bool get_manual_mode() {
315 return get_manual_mode({});
316 }
317
321 virtual bool get_manual_mode(const ProtoStruct& extra) = 0;
322
323 API api() const override;
324
325 protected:
326 explicit Arm(std::string name);
327};
328
329template <>
331 static API api();
332};
333
334bool operator==(const Arm::properties& lhs, const Arm::properties& rhs);
335
336namespace proto_convert_details {
337
338template <>
339struct to_proto_impl<Arm::trajectory_point> {
340 void operator()(const Arm::trajectory_point&, viam::component::arm::v1::TrajectoryPoint*) const;
341};
342
343template <>
344struct from_proto_impl<viam::component::arm::v1::TrajectoryPoint> {
345 Arm::trajectory_point operator()(const viam::component::arm::v1::TrajectoryPoint*) const;
346};
347
348template <>
349struct to_proto_impl<Arm::trajectory_update> {
350 void operator()(const Arm::trajectory_update&,
351 viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse*) const;
352};
353
354template <>
355struct from_proto_impl<viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse> {
356 Arm::trajectory_update operator()(
357 const viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse*) const;
358};
359
360template <>
361struct to_proto_impl<Arm::properties> {
362 void operator()(const Arm::properties&, viam::component::arm::v1::GetPropertiesResponse*) const;
363};
364
365template <>
366struct from_proto_impl<viam::component::arm::v1::GetPropertiesResponse> {
367 Arm::properties operator()(const viam::component::arm::v1::GetPropertiesResponse*) const;
368};
369
370} // namespace proto_convert_details
371
372} // namespace sdk
373} // namespace viam
Definition resource_api.hpp:21
An Arm represents a physical robot arm that exists in three-dimensional space.
Definition arm.hpp:47
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.
bool get_manual_mode()
Reports whether the arm is currently in manual mode.
Definition arm.hpp:314
std::vector< double > get_joint_positions()
Lists the joint positions in degrees of every joint on a robot arm.
Definition arm.hpp:101
virtual ProtoStruct get_status()=0
Get the status of the arm.
stream_outcome
How a streamed trajectory execution ended.
Definition arm.hpp:173
@ k_halted_by_update_handler
update_handler returned false, stopping the stream early.
@ k_completed
The trajectory ran to its natural end.
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
virtual stream_outcome move_through_joint_positions_streamed(const std::function< boost::optional< std::vector< trajectory_point > >()> &batch_source, const std::function< bool(trajectory_update)> &update_handler, const ProtoStruct &extra)=0
Execute a stream of trajectory points in order.
boost::variant< double, std::vector< double > > MoveLimit
A movement limit: either a single scalar applied uniformly, or per-joint values.
Definition arm.hpp:61
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:110
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling arm.
Definition arm.hpp:269
inline ::viam::sdk::KinematicsData get_kinematics()
Get the kinematics data associated with the arm.
Definition arm.hpp:253
void set_manual_mode(bool manual_mode)
Enter or exit manual mode, with no time limit.
Definition arm.hpp:291
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:123
virtual::viam::sdk::KinematicsData get_kinematics(const ProtoStruct &extra)=0
Get the kinematics data associated with the arm.
std::map< std::string, mesh > get_3d_models()
Returns 3DModels associated with the calling arm.
Definition arm.hpp:264
properties get_properties()
Returns the properties of the arm which comprises the booleans indicating which optional features the...
Definition arm.hpp:279
virtual void set_manual_mode(bool manual_mode, std::chrono::seconds enabled_for, const ProtoStruct &extra)=0
Enter or exit manual mode.
virtual bool get_manual_mode(const ProtoStruct &extra)=0
Reports whether the arm is currently in manual mode.
pose get_end_position()
Get the current position of the end of the arm.
Definition arm.hpp:81
void move_to_position(const pose &pose)
Move the end of the arm to.
Definition arm.hpp:91
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.
virtual properties get_properties(const ProtoStruct &extra)=0
Returns the properties of the arm which comprises the booleans indicating which optional features the...
stream_outcome move_through_joint_positions_streamed(const std::function< boost::optional< std::vector< trajectory_point > >()> &batch_source, const std::function< bool(trajectory_update)> &update_handler)
Execute a stream of trajectory points in order.
Definition arm.hpp:183
API api() const override
Returns the API associated with a particular resource.
void set_manual_mode(bool manual_mode, std::chrono::seconds enabled_for)
Enter or exit manual mode.
Definition arm.hpp:299
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_joint_positions.
Definition arm.hpp:64
Optional features that the specific arm supports.
Definition arm.hpp:72
bool support_cartesian_commands
True if the arm supports direct cartesian commands (move_to_position is implemented)
Definition arm.hpp:76
bool support_manual_mode
True if the arm supports software-enabled manual mode.
Definition arm.hpp:74
Target kinematic constraints at a waypoint.
Definition arm.hpp:147
A single waypoint in a streamed joint-space trajectory.
Definition arm.hpp:139
std::chrono::microseconds time
Offset of this waypoint from the start of the trajectory.
Definition arm.hpp:158
std::vector< double > positions
Target position at this waypoint, one value per joint, in degrees.
Definition arm.hpp:161
boost::optional< kinematic_constraints > constraints
Optional velocity and acceleration constraints at this waypoint.
Definition arm.hpp:164
An update emitted while a streamed trajectory executes.
Definition arm.hpp:170
Kinematics data in Viam's Spatial Vector Algebra (SVA) format.
Definition kinematics.hpp:48
Kinematics data in URDF format with optional meshes by URDF filepath.
Definition kinematics.hpp:53
Kinematics data with unspecified format.
Definition kinematics.hpp:45
Definition pose.hpp:30