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
28
29 friend bool operator==(const obstacle_detector& lhs, const obstacle_detector& rhs);
30 friend std::ostream& operator<<(std::ostream& os, const obstacle_detector& v);
31};
32
38 std::vector<obstacle_detector> obstacle_detectors;
39
41 boost::optional<double> position_polling_frequency_hz;
42
44 boost::optional<double> obstacle_polling_frequency_hz;
45
47 boost::optional<double> plan_deviation_m;
48
50 boost::optional<double> linear_m_per_sec;
51
53 boost::optional<double> angular_degs_per_sec;
54
55 friend bool operator==(const motion_configuration& lhs, const motion_configuration& rhs);
56 friend std::ostream& operator<<(std::ostream& os, const motion_configuration& v);
57};
58
68class Motion : public Service {
69 public:
73 enum class plan_state : uint8_t {
74 k_in_progress,
75 k_stopped,
76 k_succeeded,
77 k_failed,
78 };
79
83 struct plan_status {
86
88 time_pt timestamp;
89
92 boost::optional<std::string> reason;
93
94 friend bool operator==(const plan_status& lhs, const plan_status& rhs);
95 };
96
102 std::string plan_id;
103
106
108 std::string execution_id;
109
112
113 friend bool operator==(const plan_status_with_id& lhs, const plan_status_with_id& rhs);
114 };
115
119 using step = std::unordered_map<std::string, pose>;
120
124 struct plan {
126 std::string id;
127
130
133 std::string execution_id;
134
136 std::vector<step> steps;
137
138 friend bool operator==(const plan& lhs, const plan& rhs);
139 };
140
147 struct plan plan;
148
151
153 std::vector<plan_status> status_history;
154
155 friend bool operator==(const plan_with_status& lhs, const plan_with_status& rhs);
156 };
157
161 float line_tolerance_mm;
162 float orientation_tolerance_degs;
163 };
164
169 float orientation_tolerance_degs;
170 };
171
176 std::string frame1;
177 std::string frame2;
178 };
179 std::vector<allowed_frame_collisions> allows;
180 };
181
185 struct constraints {
186 std::vector<linear_constraint> linear_constraints;
187 std::vector<orientation_constraint> orientation_constraints;
188 std::vector<collision_specification> collision_specifications;
189 };
190
191 API api() const override;
192
200 inline bool move(const pose_in_frame& destination,
201 const Name& name,
202 const std::shared_ptr<WorldState>& world_state,
203 const std::shared_ptr<constraints>& constraints) {
204 return move(destination, name, world_state, constraints, {});
205 }
206
215 virtual bool move(const pose_in_frame& destination,
216 const Name& name,
217 const std::shared_ptr<WorldState>& world_state,
218 const std::shared_ptr<constraints>& constraints,
219 const ProtoStruct& extra) = 0;
220
227 inline std::string move_on_map(
228 const pose& destination,
229 const Name& component_name,
230 const Name& slam_name,
231 const std::shared_ptr<motion_configuration>& motion_configuration,
232 const std::vector<GeometryConfig>& obstacles) {
233 return move_on_map(
234 destination, component_name, slam_name, motion_configuration, obstacles, {});
235 }
236
244 virtual std::string move_on_map(
245 const pose& destination,
246 const Name& component_name,
247 const Name& slam_name,
248 const std::shared_ptr<motion_configuration>& motion_configuration,
249 const std::vector<GeometryConfig>& obstacles,
250 const ProtoStruct& extra) = 0;
251
262 inline std::string move_on_globe(
263 const geo_point& destination,
264 const boost::optional<double>& heading,
265 const Name& component_name,
266 const Name& movement_sensor_name,
267 const std::vector<geo_geometry>& obstacles,
268 const std::shared_ptr<motion_configuration>& motion_configuration,
269 const std::vector<geo_geometry>& bounding_regions) {
270 return move_on_globe(destination,
271 heading,
272 component_name,
273 movement_sensor_name,
274 obstacles,
276 bounding_regions,
277 {});
278 }
279
291 virtual std::string move_on_globe(
292 const geo_point& destination,
293 const boost::optional<double>& heading,
294 const Name& component_name,
295 const Name& movement_sensor_name,
296 const std::vector<geo_geometry>& obstacles,
297 const std::shared_ptr<motion_configuration>& motion_configuration,
298 const std::vector<geo_geometry>& bounding_regions,
299 const ProtoStruct& extra) = 0;
300
309 const Name& component_name,
310 const std::string& destination_frame,
311 const std::vector<WorldState::transform>& supplemental_transforms) {
312 return get_pose(component_name, destination_frame, supplemental_transforms, {});
313 }
314
324 const Name& component_name,
325 const std::string& destination_frame,
326 const std::vector<WorldState::transform>& supplemental_transforms,
327 const ProtoStruct& extra) = 0;
328
331 inline void stop_plan(const Name& component_name) {
332 return stop_plan(component_name, {});
333 }
334
338 virtual void stop_plan(const Name& component_name, const ProtoStruct& extra) = 0;
339
345 inline plan_with_status get_latest_plan(const Name& component_name) {
346 return get_latest_plan(component_name, {});
347 }
348
355 virtual plan_with_status get_latest_plan(const Name& component_name,
356 const ProtoStruct& extra) = 0;
357
364 inline std::pair<plan_with_status, std::vector<plan_with_status>>
366 return get_latest_plan_with_replan_history(component_name, {});
367 }
368
376 virtual std::pair<plan_with_status, std::vector<plan_with_status>>
377 get_latest_plan_with_replan_history(const Name& component_name, const ProtoStruct& extra) = 0;
378
385 inline plan_with_status get_plan(const Name& component_name, const std::string& execution_id) {
386 return get_plan(component_name, execution_id, {});
387 }
388
396 virtual plan_with_status get_plan(const Name& component_name,
397 const std::string& execution_id,
398 const ProtoStruct& extra) = 0;
399
407 inline std::pair<plan_with_status, std::vector<plan_with_status>> get_plan_with_replan_history(
408 const Name& component_name, const std::string& execution_id) {
409 return get_plan_with_replan_history(component_name, execution_id, {});
410 }
411
420 virtual std::pair<plan_with_status, std::vector<plan_with_status>> get_plan_with_replan_history(
421 const Name& component_name, const std::string& execution_id, const ProtoStruct& extra) = 0;
422
427 inline std::vector<plan_status_with_id> list_plan_statuses() {
428 return list_plan_statuses({});
429 }
430
436 virtual std::vector<plan_status_with_id> list_plan_statuses(const ProtoStruct& extra) = 0;
437
442 inline std::vector<plan_status_with_id> list_active_plan_statuses() {
443 return list_plan_statuses({});
444 }
445
451 virtual std::vector<plan_status_with_id> list_active_plan_statuses(
452 const ProtoStruct& extra) = 0;
453
457 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
458
459 protected:
460 explicit Motion(std::string name);
461};
462
463template <>
465 static API api();
466};
467
468} // namespace sdk
469} // namespace viam
Definition resource_api.hpp:21
The Motion service coordinates motion planning across all components of a given robot....
Definition motion.hpp:68
pose_in_frame get_pose(const Name &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:308
API api() const override
Returns the API associated with a particular resource.
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...
std::string move_on_map(const pose &destination, const Name &component_name, const Name &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:227
bool move(const pose_in_frame &destination, const Name &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:200
std::string move_on_globe(const geo_point &destination, const boost::optional< double > &heading, const Name &component_name, const Name &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:262
void stop_plan(const Name &component_name)
Stop a currently executing motion plan.
Definition motion.hpp:331
virtual std::pair< plan_with_status, std::vector< plan_with_status > > get_plan_with_replan_history(const Name &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...
plan_with_status get_plan(const Name &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:385
virtual plan_with_status get_plan(const Name &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 pose_in_frame get_pose(const Name &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.
plan_state
Describes the possible states a plan can be in.
Definition motion.hpp:73
std::pair< plan_with_status, std::vector< plan_with_status > > get_latest_plan_with_replan_history(Name component_name)
Returns the plan, state history, and replan history of the most recent execution to move a component....
Definition motion.hpp:365
virtual std::string move_on_map(const pose &destination, const Name &component_name, const Name &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.
std::pair< plan_with_status, std::vector< plan_with_status > > get_plan_with_replan_history(const Name &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:407
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::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:427
virtual void stop_plan(const Name &component_name, const ProtoStruct &extra)=0
Stop a currently executing motion plan.
plan_with_status get_latest_plan(const Name &component_name)
Returns the plan and state history of the most recent execution to move a component....
Definition motion.hpp:345
virtual std::pair< plan_with_status, std::vector< plan_with_status > > get_latest_plan_with_replan_history(const Name &component_name, const ProtoStruct &extra)=0
Returns the plan, state history, and replan history of the most recent execution to move a component....
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
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:119
virtual plan_with_status get_latest_plan(const Name &component_name, const ProtoStruct &extra)=0
Returns the plan and state history of the most recent execution to move a component....
virtual bool move(const pose_in_frame &destination, const Name &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.
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:442
virtual std::string move_on_globe(const geo_point &destination, const boost::optional< double > &heading, const Name &component_name, const Name &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.
A name for specific instances of resources.
Definition resource_api.hpp:61
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:174
Specifies all constraints to be passed to Viam's motion planning, along with any optional parameters.
Definition motion.hpp:185
Specifies that the component being moved should move linearly to its goal.
Definition motion.hpp:160
Specifies that the component being moved will not deviate its orientation beyond the specified thresh...
Definition motion.hpp:168
The motion plan status, plus plan ID, component name, and execution ID.
Definition motion.hpp:100
plan_status status
The plan status.
Definition motion.hpp:111
Name component_name
The component to be moved. Used for tracking and stopping.
Definition motion.hpp:105
std::string execution_id
The unique ID which identifies the plan execution.
Definition motion.hpp:108
std::string plan_id
The unique ID of the plan.
Definition motion.hpp:102
Describes the state of a given plan at a point in time.
Definition motion.hpp:83
plan_state state
The state of the plan execution.
Definition motion.hpp:85
time_pt timestamp
The time the executing plan transitioned to the state.
Definition motion.hpp:88
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:92
Describes a plan, its current status, and all status changes that have occurred previously on that pl...
Definition motion.hpp:145
plan_status status
The current status of the plan.
Definition motion.hpp:150
std::vector< plan_status > status_history
The prior status changes that have happened during plan execution.
Definition motion.hpp:153
Describes a motion plan.
Definition motion.hpp:124
Name component_name
The component requested to be moved. Used for tracking and stopping.
Definition motion.hpp:129
std::string id
The plan's unique ID.
Definition motion.hpp:126
std::string execution_id
The unique ID which identifies the execution. Multiple plans can share the same execution_id if they ...
Definition motion.hpp:133
std::vector< step > steps
An ordered list of plan steps.
Definition motion.hpp:136
Definition geometry.hpp:79
Defines configuration options for certain Motion APIs.
Definition motion.hpp:36
boost::optional< double > angular_degs_per_sec
Optional angular velocity to target when turning.
Definition motion.hpp:53
std::vector< obstacle_detector > obstacle_detectors
The obstacle detectors to be used for the API call.
Definition motion.hpp:38
boost::optional< double > linear_m_per_sec
Optional linear velocity to target when moving.
Definition motion.hpp:50
boost::optional< double > position_polling_frequency_hz
If not null, sets the frequency to poll for the position of the robot.
Definition motion.hpp:41
boost::optional< double > plan_deviation_m
Optional distance in meters a robot is allowed to deviate from the motion plan.
Definition motion.hpp:47
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:44
Definition motion.hpp:23
Name camera
The name of the camera component to be used for obstacle detection.
Definition motion.hpp:27
Name vision_service
The name of the vision service to be used for obstacle detection.
Definition motion.hpp:25
Definition pose.hpp:39
Definition pose.hpp:30