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;
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 using KinematicsData [[deprecated("Use ::viam::sdk::KinematicsData instead")]] =
57 ::viam::sdk::KinematicsData;
58
60 using MoveLimit = boost::variant<double, std::vector<double>>;
61
63 struct MoveOptions {
64 boost::optional<MoveLimit> max_vel_degs_per_sec;
65 boost::optional<MoveLimit> max_acc_degs_per_sec2;
66 boost::optional<double> max_tcp_speed;
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
138 std::vector<double> velocities_degs_per_sec;
139 boost::optional<std::vector<double>> accelerations_degs_per_sec2;
140 };
141
148 std::chrono::microseconds time;
149
151 std::vector<double> positions;
152
154 boost::optional<kinematic_constraints> constraints;
155 };
156
161
163 enum class stream_outcome : std::uint8_t {
164 k_completed = 0,
166 1,
167 };
168
174 const std::function<boost::optional<std::vector<trajectory_point>>()>& batch_source,
175 const std::function<bool(trajectory_update)>& update_handler) {
176 return move_through_joint_positions_streamed(batch_source, update_handler, {});
177 }
178
220 const std::function<boost::optional<std::vector<trajectory_point>>()>& batch_source,
221 const std::function<bool(trajectory_update)>& update_handler,
222 const ProtoStruct& extra) = 0;
223
225 virtual bool is_moving() = 0;
226
229 virtual ProtoStruct get_status() = 0;
230
234 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
235
239 virtual ::viam::sdk::KinematicsData get_kinematics(const ProtoStruct& extra) = 0;
240
243 inline ::viam::sdk::KinematicsData get_kinematics() {
244 return get_kinematics({});
245 }
246
250 virtual std::map<std::string, mesh> get_3d_models(const ProtoStruct& extra) = 0;
251
254 inline std::map<std::string, mesh> get_3d_models() {
255 return get_3d_models({});
256 }
257
259 inline std::vector<GeometryConfig> get_geometries() {
260 return get_geometries({});
261 }
262
265 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
266
267 API api() const override;
268
269 protected:
270 explicit Arm(std::string name);
271};
272
273template <>
275 static API api();
276};
277
278namespace proto_convert_details {
279
280template <>
281struct to_proto_impl<Arm::trajectory_point> {
282 void operator()(const Arm::trajectory_point&, viam::component::arm::v1::TrajectoryPoint*) const;
283};
284
285template <>
286struct from_proto_impl<viam::component::arm::v1::TrajectoryPoint> {
287 Arm::trajectory_point operator()(const viam::component::arm::v1::TrajectoryPoint*) const;
288};
289
290template <>
291struct to_proto_impl<Arm::trajectory_update> {
292 void operator()(const Arm::trajectory_update&,
293 viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse*) const;
294};
295
296template <>
297struct from_proto_impl<viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse> {
298 Arm::trajectory_update operator()(
299 const viam::component::arm::v1::MoveThroughJointPositionsStreamedResponse*) const;
300};
301
302} // namespace proto_convert_details
303
304} // namespace sdk
305} // 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.
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 get_status()=0
Get the status of the arm.
stream_outcome
How a streamed trajectory execution ended.
Definition arm.hpp:163
@ 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:60
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
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling arm.
Definition arm.hpp:259
inline ::viam::sdk::KinematicsData get_kinematics()
Get the kinematics data associated with the arm.
Definition arm.hpp:243
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
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:254
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.
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:173
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_joint_positions.
Definition arm.hpp:63
Target kinematic constraints at a waypoint.
Definition arm.hpp:137
A single waypoint in a streamed joint-space trajectory.
Definition arm.hpp:129
std::chrono::microseconds time
Offset of this waypoint from the start of the trajectory.
Definition arm.hpp:148
std::vector< double > positions
Target position at this waypoint, one value per joint, in degrees.
Definition arm.hpp:151
boost::optional< kinematic_constraints > constraints
Optional velocity and acceleration constraints at this waypoint.
Definition arm.hpp:154
An update emitted while a streamed trajectory executes.
Definition arm.hpp:160
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