Viam C++ SDK current
Loading...
Searching...
No Matches
navigation.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <viam/sdk/common/pose.hpp>
9#include <viam/sdk/common/utils.hpp>
10#include <viam/sdk/services/service.hpp>
11#include <viam/sdk/spatialmath/geometry.hpp>
12
13namespace viam {
14namespace sdk {
15
16class Navigation : public Service {
17 public:
21 enum class Mode : uint8_t {
22 k_unspecified,
23 k_manual,
24 k_waypoint,
25 k_explore,
26 };
27
31 enum class MapType : uint8_t {
32 k_unspecified,
33 k_none,
34 k_gps,
35 };
36
41 geo_point location;
42 double compass_heading;
43
44 bool operator==(const LocationResponse& rhs) const {
45 return compass_heading == rhs.compass_heading && location == rhs.location;
46 }
47 };
48
52 struct Properties {
53 MapType map_type;
54 };
55
59 struct Waypoint {
60 std::string id;
61 geo_point location;
62 };
63
67 struct Path {
68 std::string destination_waypoint_id;
69 std::vector<geo_point> geopoints;
70
71 bool operator==(const Path& rhs) const {
72 return destination_waypoint_id == rhs.destination_waypoint_id &&
73 geopoints == rhs.geopoints;
74 }
75 };
76
77 API api() const override;
78
82 virtual Mode get_mode(const ProtoStruct& extra) = 0;
83
87 virtual void set_mode(const Mode mode, const ProtoStruct& extra) = 0;
88
92 virtual LocationResponse get_location(const ProtoStruct& extra) = 0;
93
97 virtual std::vector<Waypoint> get_waypoints(const ProtoStruct& extra) = 0;
98
101 virtual void add_waypoint(const geo_point& location, const ProtoStruct& extra) = 0;
102
106 virtual void remove_waypoint(const std::string id, const ProtoStruct& extra) = 0;
107
111 virtual std::vector<geo_geometry> get_obstacles(const ProtoStruct& extra) = 0;
112
116 virtual std::vector<Path> get_paths(const ProtoStruct& extra) = 0;
117
121
125 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
126
127 // overloads without `extra` param:
128
129 inline Mode get_mode() {
130 return get_mode({});
131 }
132
133 inline void set_mode(const Mode mode) {
134 set_mode(mode, {});
135 }
136
137 inline LocationResponse get_location() {
138 return get_location({});
139 }
140
141 inline std::vector<Waypoint> get_waypoints() {
142 return get_waypoints({});
143 }
144
145 inline void add_waypoint(const geo_point& location) {
146 add_waypoint(location, {});
147 }
148
149 inline void remove_waypoint(const std::string id) {
150 remove_waypoint(id, {});
151 }
152
153 inline std::vector<geo_geometry> get_obstacles() {
154 return get_obstacles({});
155 }
156
157 inline std::vector<Path> get_paths() {
158 return get_paths({});
159 }
160
161 protected:
162 explicit Navigation(std::string name);
163};
164
165template <>
167 static API api();
168};
169
170} // namespace sdk
171} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Definition navigation.hpp:16
virtual void set_mode(const Mode mode, const ProtoStruct &extra)=0
Set the current mode.
virtual Properties get_properties()=0
Get this nav service's properties.
MapType
Is the map navigating in GPS or a custom map.
Definition navigation.hpp:31
API api() const override
Returns the API associated with a particular resource.
virtual void remove_waypoint(const std::string id, const ProtoStruct &extra)=0
Remove a waypoint by ID.
virtual std::vector< Path > get_paths(const ProtoStruct &extra)=0
Get the paths this nav service knows about.
virtual void add_waypoint(const geo_point &location, const ProtoStruct &extra)=0
Add a waypoint.
virtual std::vector< Waypoint > get_waypoints(const ProtoStruct &extra)=0
Get the waypoints this nav service knows about.
virtual Mode get_mode(const ProtoStruct &extra)=0
Get the current mode.
virtual LocationResponse get_location(const ProtoStruct &extra)=0
Get the current location.
virtual std::vector< geo_geometry > get_obstacles(const ProtoStruct &extra)=0
Get the obstacles this nav service knows about.
Mode
Enum affecting this nav service's goal.
Definition navigation.hpp:21
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Do an arbitrary command.
virtual std::string name() const
Return the resource's name.
Definition service.hpp:10
Definition resource_api.hpp:50
Location and direction.
Definition navigation.hpp:40
A user-provided destination and a set of geopoints to get there.
Definition navigation.hpp:67
A set of attributes for this nav service.
Definition navigation.hpp:52
A location with an id handle that can be used to uniquely identify and remove it.
Definition navigation.hpp:59
Definition geometry.hpp:80