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 <optional>
10#include <string>
11#include <variant>
12#include <vector>
13
15#include <viam/sdk/common/mesh.hpp>
16#include <viam/sdk/common/pose.hpp>
17#include <viam/sdk/common/proto_convert.hpp>
18#include <viam/sdk/resource/stoppable.hpp>
19#include <viam/sdk/spatialmath/geometry.hpp>
20
21namespace viam {
22namespace component {
23namespace arm {
24namespace v1 {
25
26class TrajectoryPoint;
27class MoveThroughJointPositionsStreamedResponse;
28class GetPropertiesResponse;
29
30} // namespace v1
31} // namespace arm
32} // namespace component
33} // namespace viam
34
35namespace viam {
36namespace sdk {
37
39
46class Arm : public Component, public Stoppable {
47 public:
50 [[deprecated("Use ::viam::sdk::KinematicsDataUnspecified instead")]] =
52 using KinematicsDataSVA [[deprecated("Use ::viam::sdk::KinematicsDataSVA instead")]] =
54 using KinematicsDataURDF [[deprecated("Use ::viam::sdk::KinematicsDataURDF instead")]] =
56#pragma GCC diagnostic push
57#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
58 using KinematicsData [[deprecated("Use ::viam::sdk::KinematicsData instead")]] =
59 ::viam::sdk::KinematicsData;
60#pragma GCC diagnostic pop
61
63 using MoveLimit = std::variant<double, std::vector<double>>;
64
66 struct MoveOptions {
67 std::optional<MoveLimit> max_vel_degs_per_sec;
68 std::optional<MoveLimit> max_acc_degs_per_sec2;
69 std::optional<double> max_tcp_speed;
70 };
71
74 struct properties {
76 bool support_manual_mode = false;
79 friend bool operator==(const properties&, const properties&) = default;
80 };
81
85 return get_end_position({});
86 }
87
91 virtual pose get_end_position(const ProtoStruct& extra) = 0;
92
94 inline void move_to_position(const pose& pose) {
96 }
97
101 virtual void move_to_position(const pose& pose, const ProtoStruct& extra) = 0;
102
104 inline std::vector<double> get_joint_positions() {
105 return get_joint_positions({});
106 }
107
110 virtual std::vector<double> get_joint_positions(const ProtoStruct& extra) = 0;
111
113 inline void move_to_joint_positions(const std::vector<double>& positions) {
114 return move_to_joint_positions(positions, {});
115 }
116
119 virtual void move_to_joint_positions(const std::vector<double>& positions,
120 const ProtoStruct& extra) = 0;
121
126 inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
127 const MoveOptions& options) {
128 return move_through_joint_positions(positions, options, {});
129 }
130
134 virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
135 const MoveOptions& options,
136 const ProtoStruct& extra) = 0;
137
151 std::vector<double> velocities_degs_per_sec;
152 std::optional<std::vector<double>> accelerations_degs_per_sec2;
153 };
154
161 std::chrono::microseconds time;
162
164 std::vector<double> positions;
165
167 std::optional<kinematic_constraints> constraints;
168 };
169
174
176 enum class stream_outcome : std::uint8_t {
177 k_completed = 0,
179 1,
180 };
181
187 const std::function<std::optional<std::vector<trajectory_point>>()>& batch_source,
188 const std::function<bool(trajectory_update)>& update_handler) {
189 return move_through_joint_positions_streamed(batch_source, update_handler, {});
190 }
191
233 const std::function<std::optional<std::vector<trajectory_point>>()>& batch_source,
234 const std::function<bool(trajectory_update)>& update_handler,
235 const ProtoStruct& extra) = 0;
236
238 virtual bool is_moving() = 0;
239
242 virtual ProtoStruct get_status() = 0;
243
247 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
248
254 const ProtoStruct& extra) = 0;
255
260 return get_kinematic_model(options, {});
261 }
262
263#pragma GCC diagnostic push
264#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
269 [[deprecated("use get_kinematic_model")]] virtual KinematicsData get_kinematics(
270 const ProtoStruct& extra);
271
274 [[deprecated("use get_kinematic_model")]] KinematicsData get_kinematics();
275#pragma GCC diagnostic pop
276
280 virtual std::map<std::string, mesh> get_3d_models(const ProtoStruct& extra) = 0;
281
284 inline std::map<std::string, mesh> get_3d_models() {
285 return get_3d_models({});
286 }
287
289 inline std::vector<GeometryConfig> get_geometries() {
290 return get_geometries({});
291 }
292
295 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
296
300 return get_properties({});
301 }
302
306 virtual properties get_properties(const ProtoStruct& extra) = 0;
307
311 inline void set_manual_mode(bool manual_mode) {
312 return set_manual_mode(manual_mode, std::chrono::seconds::zero(), {});
313 }
314
319 inline void set_manual_mode(bool manual_mode, std::chrono::seconds enabled_for) {
320 return set_manual_mode(manual_mode, enabled_for, {});
321 }
322
328 virtual void set_manual_mode(bool manual_mode,
329 std::chrono::seconds enabled_for,
330 const ProtoStruct& extra) = 0;
331
334 inline bool get_manual_mode() {
335 return get_manual_mode({});
336 }
337
341 virtual bool get_manual_mode(const ProtoStruct& extra) = 0;
342
343 API api() const override;
344
345 protected:
346 explicit Arm(std::string name);
347
348 explicit Arm(const ResourceConfig& cfg);
349};
350
351template <>
353 static API api();
354};
355
356namespace proto_convert_details {
357
358template <>
359struct to_proto_impl<Arm::trajectory_point> {
360 void operator()(const Arm::trajectory_point&, viam::component::arm::v1::TrajectoryPoint*) const;
361};
362
363template <>
364struct from_proto_impl<viam::component::arm::v1::TrajectoryPoint> {
365 Arm::trajectory_point operator()(const viam::component::arm::v1::TrajectoryPoint*) const;
366};
367
368template <>
369struct to_proto_impl<Arm::trajectory_update> {
370 void operator()(const Arm::trajectory_update&,
371 viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse*) const;
372};
373
374template <>
375struct from_proto_impl<viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse> {
376 Arm::trajectory_update operator()(
377 const viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse*) const;
378};
379
380template <>
381struct to_proto_impl<Arm::properties> {
382 void operator()(const Arm::properties&, viam::component::arm::v1::GetPropertiesResponse*) const;
383};
384
385template <>
386struct from_proto_impl<viam::component::arm::v1::GetPropertiesResponse> {
387 Arm::properties operator()(const viam::component::arm::v1::GetPropertiesResponse*) const;
388};
389
390} // namespace proto_convert_details
391
392} // namespace sdk
393} // namespace viam
Definition resource_api.hpp:21
An Arm represents a physical robot arm that exists in three-dimensional space.
Definition arm.hpp:46
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:334
KinematicsData get_kinematics()
Get the kinematics data associated with the arm as a raw file.
std::vector< double > get_joint_positions()
Lists the joint positions in degrees of every joint on a robot arm.
Definition arm.hpp:104
virtual ProtoStruct get_status()=0
Get the status of the arm.
stream_outcome move_through_joint_positions_streamed(const std::function< std::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:186
stream_outcome
How a streamed trajectory execution ended.
Definition arm.hpp:176
@ 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 KinematicModel get_kinematic_model(const kinematics_options &options, const ProtoStruct &extra)=0
Get the kinematic model of the arm.
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:113
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling arm.
Definition arm.hpp:289
void set_manual_mode(bool manual_mode)
Enter or exit manual mode, with no time limit.
Definition arm.hpp:311
virtual std::map< std::string, mesh > get_3d_models(const ProtoStruct &extra)=0
Returns 3DModels associated with the calling arm.
std::variant< double, std::vector< double > > MoveLimit
A movement limit: either a single scalar applied uniformly, or per-joint values.
Definition arm.hpp:63
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:126
virtual KinematicsData get_kinematics(const ProtoStruct &extra)
Get the kinematics data associated with the arm as a raw file.
std::map< std::string, mesh > get_3d_models()
Returns 3DModels associated with the calling arm.
Definition arm.hpp:284
KinematicModel get_kinematic_model(const kinematics_options &options={})
Get the kinematic model of the arm.
Definition arm.hpp:259
properties get_properties()
Returns the properties of the arm which comprises the booleans indicating which optional features the...
Definition arm.hpp:299
virtual stream_outcome move_through_joint_positions_streamed(const std::function< std::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.
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:84
void move_to_position(const pose &pose)
Move the end of the arm to.
Definition arm.hpp:94
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...
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:319
Definition component.hpp:10
Definition resource.hpp:42
virtual std::string name() const
Return the resource's name.
Definition stoppable.hpp:8
Kinematics data types shared by the components that serve GetKinematics.
Definition resource_api.hpp:46
Movement specifications for move_through_joint_positions.
Definition arm.hpp:66
Optional features that the specific arm supports.
Definition arm.hpp:74
bool support_cartesian_commands
True if the arm supports direct cartesian commands (move_to_position is implemented)
Definition arm.hpp:78
bool support_manual_mode
True if the arm supports software-enabled manual mode.
Definition arm.hpp:76
Target kinematic constraints at a waypoint.
Definition arm.hpp:150
A single waypoint in a streamed joint-space trajectory.
Definition arm.hpp:142
std::chrono::microseconds time
Offset of this waypoint from the start of the trajectory.
Definition arm.hpp:161
std::optional< kinematic_constraints > constraints
Optional velocity and acceleration constraints at this waypoint.
Definition arm.hpp:167
std::vector< double > positions
Target position at this waypoint, one value per joint, in degrees.
Definition arm.hpp:164
An update emitted while a streamed trajectory executes.
Definition arm.hpp:173
A component's kinematics as a tree of links and joints. Its proto JSON encoding is also the on-disk k...
Definition kinematics.hpp:154
Kinematics data in Viam's Spatial Vector Algebra (SVA) format.
Definition kinematics.hpp:195
Kinematics data in URDF format with optional meshes by URDF filepath.
Definition kinematics.hpp:200
Kinematics data with unspecified format.
Definition kinematics.hpp:192
Options for a GetKinematics request.
Definition kinematics.hpp:39
Definition pose.hpp:30