Viam C++ SDK current
Loading...
Searching...
No Matches
motion.hpp
1
4#pragma once
5
6#include <string>
7
8#include <viam/sdk/common/pose.hpp>
9#include <viam/sdk/common/proto_value.hpp>
10#include <viam/sdk/common/utils.hpp>
11#include <viam/sdk/common/world_state.hpp>
12#include <viam/sdk/resource/resource_api.hpp>
13#include <viam/sdk/services/service.hpp>
14#include <viam/sdk/spatialmath/geometry.hpp>
15
16namespace viam {
17namespace sdk {
18
25 std::string vision_service;
26
28 std::string camera;
29
30 friend bool operator==(const obstacle_detector& lhs, const obstacle_detector& rhs);
31 friend std::ostream& operator<<(std::ostream& os, const obstacle_detector& v);
32};
33
39 std::vector<obstacle_detector> obstacle_detectors;
40
42 boost::optional<double> position_polling_frequency_hz;
43
45 boost::optional<double> obstacle_polling_frequency_hz;
46
48 boost::optional<double> plan_deviation_m;
49
51 boost::optional<double> linear_m_per_sec;
52
54 boost::optional<double> angular_degs_per_sec;
55
56 friend bool operator==(const motion_configuration& lhs, const motion_configuration& rhs);
57 friend std::ostream& operator<<(std::ostream& os, const motion_configuration& v);
58};
59
69class Motion : public Service {
70 public:
74 enum class plan_state : uint8_t {
75 k_in_progress,
76 k_stopped,
77 k_succeeded,
78 k_failed,
79 };
80
84 struct plan_status {
87
89 time_pt timestamp;
90
93 boost::optional<std::string> reason;
94
95 friend bool operator==(const plan_status& lhs, const plan_status& rhs);
96 };
97
103 std::string plan_id;
104
106 std::string component_name;
107
109 std::string execution_id;
110
113
114 friend bool operator==(const plan_status_with_id& lhs, const plan_status_with_id& rhs);
115 };
116
120 using step = std::unordered_map<std::string, pose>;
121
125 struct plan {
127 std::string id;
128
130 std::string component_name;
131
134 std::string execution_id;
135
137 std::vector<step> steps;
138
139 friend bool operator==(const plan& lhs, const plan& rhs);
140 };
141
148 struct plan plan;
149
152
154 std::vector<plan_status> status_history;
155
156 friend bool operator==(const plan_with_status& lhs, const plan_with_status& rhs);
157 };
158
162 float line_tolerance_mm;
163 float orientation_tolerance_degs;
164 };
165
170 float orientation_tolerance_degs;
171 };
172
177 std::string frame1;
178 std::string frame2;
179 };
180 std::vector<allowed_frame_collisions> allows;
181 };
182
186 struct constraints {
187 std::vector<linear_constraint> linear_constraints;
188 std::vector<orientation_constraint> orientation_constraints;
189 std::vector<collision_specification> collision_specifications;
190 };
191
192 API api() const override;
193
201 inline bool move(const pose_in_frame& destination,
202 const std::string& name,
203 const std::shared_ptr<WorldState>& world_state,
204 const std::shared_ptr<constraints>& constraints) {
205 return move(destination, name, world_state, constraints, {});
206 }
207
216 virtual bool move(const pose_in_frame& destination,
217 const std::string& name,
218 const std::shared_ptr<WorldState>& world_state,
219 const std::shared_ptr<constraints>& constraints,
220 const ProtoStruct& extra) = 0;
221
228 inline std::string move_on_map(
229 const pose& destination,
230 const std::string& component_name,
231 const std::string& slam_name,
232 const std::shared_ptr<motion_configuration>& motion_configuration,
233 const std::vector<GeometryConfig>& obstacles) {
234 return move_on_map(
235 destination, component_name, slam_name, motion_configuration, obstacles, {});
236 }
237
245 virtual std::string move_on_map(
246 const pose& destination,
247 const std::string& component_name,
248 const std::string& slam_name,
249 const std::shared_ptr<motion_configuration>& motion_configuration,
250 const std::vector<GeometryConfig>& obstacles,
251 const ProtoStruct& extra) = 0;
252
263 inline std::string move_on_globe(
264 const geo_point& destination,
265 const boost::optional<double>& heading,
266 const std::string& component_name,
267 const std::string& movement_sensor_name,
268 const std::vector<geo_geometry>& obstacles,
269 const std::shared_ptr<motion_configuration>& motion_configuration,
270 const std::vector<geo_geometry>& bounding_regions) {
271 return move_on_globe(destination,
272 heading,
273 component_name,
274 movement_sensor_name,
275 obstacles,
277 bounding_regions,
278 {});
279 }
280
292 virtual std::string move_on_globe(
293 const geo_point& destination,
294 const boost::optional<double>& heading,
295 const std::string& component_name,
296 const std::string& movement_sensor_name,
297 const std::vector<geo_geometry>& obstacles,
298 const std::shared_ptr<motion_configuration>& motion_configuration,
299 const std::vector<geo_geometry>& bounding_regions,
300 const ProtoStruct& extra) = 0;
301
310 const std::string& component_name,
311 const std::string& destination_frame,
312 const std::vector<WorldState::transform>& supplemental_transforms) {
313 return get_pose(component_name, destination_frame, supplemental_transforms, {});
314 }
315
325 const std::string& component_name,
326 const std::string& destination_frame,
327 const std::vector<WorldState::transform>& supplemental_transforms,
328 const ProtoStruct& extra) = 0;
329
332 inline void stop_plan(const std::string& component_name) {
333 return stop_plan(component_name, {});
334 }
335
339 virtual void stop_plan(const std::string& component_name, const ProtoStruct& extra) = 0;
340
346 inline plan_with_status get_latest_plan(const std::string& component_name) {
347 return get_latest_plan(component_name, {});
348 }
349
356 virtual plan_with_status get_latest_plan(const std::string& component_name,
357 const ProtoStruct& extra) = 0;
358
365 inline std::pair<plan_with_status, std::vector<plan_with_status>>
366 get_latest_plan_with_replan_history(const std::string& component_name) {
367 return get_latest_plan_with_replan_history(component_name, {});
368 }
369
377 virtual std::pair<plan_with_status, std::vector<plan_with_status>>
378 get_latest_plan_with_replan_history(const std::string& component_name,
379 const ProtoStruct& extra) = 0;
380
387 inline plan_with_status get_plan(const std::string& component_name,
388 const std::string& execution_id) {
389 return get_plan(component_name, execution_id, {});
390 }
391
399 virtual plan_with_status get_plan(const std::string& component_name,
400 const std::string& execution_id,
401 const ProtoStruct& extra) = 0;
402
410 inline std::pair<plan_with_status, std::vector<plan_with_status>> get_plan_with_replan_history(
411 const std::string& component_name, const std::string& execution_id) {
412 return get_plan_with_replan_history(component_name, execution_id, {});
413 }
414
423 virtual std::pair<plan_with_status, std::vector<plan_with_status>> get_plan_with_replan_history(
424 const std::string& component_name,
425 const std::string& execution_id,
426 const ProtoStruct& extra) = 0;
427
432 inline std::vector<plan_status_with_id> list_plan_statuses() {
433 return list_plan_statuses({});
434 }
435
441 virtual std::vector<plan_status_with_id> list_plan_statuses(const ProtoStruct& extra) = 0;
442
447 inline std::vector<plan_status_with_id> list_active_plan_statuses() {
448 return list_plan_statuses({});
449 }
450
456 virtual std::vector<plan_status_with_id> list_active_plan_statuses(
457 const ProtoStruct& extra) = 0;
458
462 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
463
464 protected:
465 explicit Motion(std::string name);
466};
467
468template <>
470 static API api();
471};
472
473} // namespace sdk
474} // namespace viam
Definition resource_api.hpp:21
The Motion service coordinates motion planning across all components of a given robot....
Definition motion.hpp:69
std::pair< plan_with_status, std::vector< plan_with_status > > get_latest_plan_with_replan_history(const std::string &component_name)
Returns the plan, state history, and replan history of the most recent execution to move a component....
Definition motion.hpp:366
virtual pose_in_frame get_pose(const std::string &component_name, const std::string &destination_frame, const std::vector< WorldState::transform > &supplemental_transforms, const ProtoStruct &extra)=0
Get the pose of any component on the robot.
pose_in_frame get_pose(const std::string &component_name, const std::string &destination_frame, const std::vector< WorldState::transform > &supplemental_transforms)
Get the pose of any component on the robot.
Definition motion.hpp:309
API api() const override
Returns the API associated with a particular resource.
void stop_plan(const std::string &component_name)
Stop a currently executing motion plan.
Definition motion.hpp:332
std::string move_on_globe(const geo_point &destination, const boost::optional< double > &heading, const std::string &component_name, const std::string &movement_sensor_name, const std::vector< geo_geometry > &obstacles, const std::shared_ptr< motion_configuration > &motion_configuration, const std::vector< geo_geometry > &bounding_regions)
Moves any component on the robot to a specific destination on a globe.
Definition motion.hpp:263
virtual std::vector< plan_status_with_id > list_plan_statuses(const ProtoStruct &extra)=0
Returns the status of plans created by MoveOnGlobe requests. Includes statuses of plans that are exec...
plan_state
Describes the possible states a plan can be in.
Definition motion.hpp:74
virtual std::pair< plan_with_status, std::vector< plan_with_status > > get_latest_plan_with_replan_history(const std::string &component_name, const ProtoStruct &extra)=0
Returns the plan, state history, and replan history of the most recent execution to move a component....
virtual plan_with_status get_latest_plan(const std::string &component_name, const ProtoStruct &extra)=0
Returns the plan and state history of the most recent execution to move a component....
virtual void stop_plan(const std::string &component_name, const ProtoStruct &extra)=0
Stop a currently executing motion plan.
virtual std::vector< plan_status_with_id > list_active_plan_statuses(const ProtoStruct &extra)=0
Returns the status of currently active plans created by MoveOnGlobe requests. Includes statuses of pl...
std::pair< plan_with_status, std::vector< plan_with_status > > get_plan_with_replan_history(const std::string &component_name, const std::string &execution_id)
Returns the plan, state history, and replan history of the requested plan. Returns a result if the la...
Definition motion.hpp:410
plan_with_status get_latest_plan(const std::string &component_name)
Returns the plan and state history of the most recent execution to move a component....
Definition motion.hpp:346
std::vector< plan_status_with_id > list_plan_statuses()
Returns the status of plans created by MoveOnGlobe requests. Includes statuses of plans that are exec...
Definition motion.hpp:432
bool move(const pose_in_frame &destination, const std::string &name, const std::shared_ptr< WorldState > &world_state, const std::shared_ptr< constraints > &constraints)
Moves any compononent on the robot to a specified destination.
Definition motion.hpp:201
virtual plan_with_status get_plan(const std::string &component_name, const std::string &execution_id, const ProtoStruct &extra)=0
Returns the plan and state history of the requested plan. Returns a result if the last execution is s...
virtual std::string move_on_map(const pose &destination, const std::string &component_name, const std::string &slam_name, const std::shared_ptr< motion_configuration > &motion_configuration, const std::vector< GeometryConfig > &obstacles, const ProtoStruct &extra)=0
Moves any component on the robot to a specific destination on a SLAM map.
virtual std::pair< plan_with_status, std::vector< plan_with_status > > get_plan_with_replan_history(const std::string &component_name, const std::string &execution_id, const ProtoStruct &extra)=0
Returns the plan, state history, and replan history of the requested plan. Returns a result if the la...
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
plan_with_status get_plan(const std::string &component_name, const std::string &execution_id)
Returns the plan and state history of the requested plan. Returns a result if the last execution is s...
Definition motion.hpp:387
std::unordered_map< std::string, pose > step
An individual "step", representing the state each component (keyed as a fully qualified component nam...
Definition motion.hpp:120
virtual bool move(const pose_in_frame &destination, const std::string &name, const std::shared_ptr< WorldState > &world_state, const std::shared_ptr< constraints > &constraints, const ProtoStruct &extra)=0
Moves any compononent on the robot to a specified destination.
virtual std::string move_on_globe(const geo_point &destination, const boost::optional< double > &heading, const std::string &component_name, const std::string &movement_sensor_name, const std::vector< geo_geometry > &obstacles, const std::shared_ptr< motion_configuration > &motion_configuration, const std::vector< geo_geometry > &bounding_regions, const ProtoStruct &extra)=0
Moves any component on the robot to a specific destination on a globe.
std::vector< plan_status_with_id > list_active_plan_statuses()
Returns the status of currently active plans created by MoveOnGlobe requests. Includes statuses of pl...
Definition motion.hpp:447
std::string move_on_map(const pose &destination, const std::string &component_name, const std::string &slam_name, const std::shared_ptr< motion_configuration > &motion_configuration, const std::vector< GeometryConfig > &obstacles)
Moves any component on the robot to a specific destination on a SLAM map.
Definition motion.hpp:228
virtual std::string name() const
Return the resource's name.
Definition service.hpp:10
Definition resource_api.hpp:46
used to selectively apply obstacle avoidance to specific parts of the robot.
Definition motion.hpp:175
Specifies all constraints to be passed to Viam's motion planning, along with any optional parameters.
Definition motion.hpp:186
Specifies that the component being moved should move linearly to its goal.
Definition motion.hpp:161
Specifies that the component being moved will not deviate its orientation beyond the specified thresh...
Definition motion.hpp:169
The motion plan status, plus plan ID, component name, and execution ID.
Definition motion.hpp:101
plan_status status
The plan status.
Definition motion.hpp:112
std::string execution_id
The unique ID which identifies the plan execution.
Definition motion.hpp:109
std::string component_name
The component to be moved. Used for tracking and stopping.
Definition motion.hpp:106
std::string plan_id
The unique ID of the plan.
Definition motion.hpp:103
Describes the state of a given plan at a point in time.
Definition motion.hpp:84
plan_state state
The state of the plan execution.
Definition motion.hpp:86
time_pt timestamp
The time the executing plan transitioned to the state.
Definition motion.hpp:89
boost::optional< std::string > reason
The reason for the state change. The error message if the plan failed, or the re-plan reason if re-pl...
Definition motion.hpp:93
Describes a plan, its current status, and all status changes that have occurred previously on that pl...
Definition motion.hpp:146
plan_status status
The current status of the plan.
Definition motion.hpp:151
std::vector< plan_status > status_history
The prior status changes that have happened during plan execution.
Definition motion.hpp:154
Describes a motion plan.
Definition motion.hpp:125
std::string id
The plan's unique ID.
Definition motion.hpp:127
std::string component_name
The component requested to be moved. Used for tracking and stopping.
Definition motion.hpp:130
std::string execution_id
The unique ID which identifies the execution. Multiple plans can share the same execution_id if they ...
Definition motion.hpp:134
std::vector< step > steps
An ordered list of plan steps.
Definition motion.hpp:137
Definition geometry.hpp:79
Defines configuration options for certain Motion APIs.
Definition motion.hpp:37
boost::optional< double > angular_degs_per_sec
Optional angular velocity to target when turning.
Definition motion.hpp:54
std::vector< obstacle_detector > obstacle_detectors
The obstacle detectors to be used for the API call.
Definition motion.hpp:39
boost::optional< double > linear_m_per_sec
Optional linear velocity to target when moving.
Definition motion.hpp:51
boost::optional< double > position_polling_frequency_hz
If not null, sets the frequency to poll for the position of the robot.
Definition motion.hpp:42
boost::optional< double > plan_deviation_m
Optional distance in meters a robot is allowed to deviate from the motion plan.
Definition motion.hpp:48
boost::optional< double > obstacle_polling_frequency_hz
If not null, sets the frequency to poll the vision service(s) for new obstacles.
Definition motion.hpp:45
Definition motion.hpp:23
std::string vision_service
The name of the vision service to be used for obstacle detection.
Definition motion.hpp:25
std::string camera
The name of the camera component to be used for obstacle detection.
Definition motion.hpp:28
Definition pose.hpp:39
Definition pose.hpp:30