Viam C++ SDK current
Loading...
Searching...
No Matches
base.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <viam/sdk/common/linear_algebra.hpp>
9#include <viam/sdk/common/proto_value.hpp>
10#include <viam/sdk/common/utils.hpp>
11#include <viam/sdk/config/resource.hpp>
12#include <viam/sdk/resource/stoppable.hpp>
13
14namespace viam {
15namespace sdk {
16
18
25class Base : public Component, public Stoppable {
26 public:
29 struct properties {
30 double width_meters;
31 double turning_radius_meters;
32 double wheel_circumference_meters;
33 };
34 friend std::ostream& operator<<(std::ostream& os, const properties& v);
35 friend bool operator==(const properties& lhs, const properties& rhs);
36
41 inline void move_straight(int64_t distance_mm, double mm_per_sec) {
42 return move_straight(distance_mm, mm_per_sec, {});
43 }
44
50 virtual void move_straight(int64_t distance_mm,
51 double mm_per_sec,
52 const ProtoStruct& extra) = 0;
53
58 inline void spin(double angle_deg, double degs_per_sec) {
59 return spin(angle_deg, degs_per_sec, {});
60 }
61
67 virtual void spin(double angle_deg, double degs_per_sec, const ProtoStruct& extra) = 0;
68
73 inline void set_power(const Vector3& linear, const Vector3& angular) {
74 return set_power(linear, angular, {});
75 }
76
82 virtual void set_power(const Vector3& linear,
83 const Vector3& angular,
84 const ProtoStruct& extra) = 0;
85
89 inline void set_velocity(const Vector3& linear, const Vector3& angular) {
90 return set_velocity(linear, angular, {});
91 }
92
97 virtual void set_velocity(const Vector3& linear,
98 const Vector3& angular,
99 const ProtoStruct& extra) = 0;
100
102 virtual bool is_moving() = 0;
103
106 return get_properties({});
107 }
108
111 virtual properties get_properties(const ProtoStruct& extra) = 0;
112
116 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
117
120 inline std::vector<GeometryConfig> get_geometries() {
121 return get_geometries({});
122 }
123
127 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
128
129 API api() const override;
130
131 protected:
132 explicit Base(std::string name);
133};
134
135template <>
137 static API api();
138};
139
140} // namespace sdk
141} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
A Base is the platform that the other parts of a mobile robot attach to.
Definition base.hpp:25
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
virtual bool is_moving()=0
Reports if the base is in motion.
virtual void spin(double angle_deg, double degs_per_sec, const ProtoStruct &extra)=0
Spins a robot's base by an given angle, expressed in degrees. This method blocks until completed or c...
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling base.
void set_power(const Vector3 &linear, const Vector3 &angular)
Sets the linear and angular power of a base -1 -> 1 in terms of power for each direction.
Definition base.hpp:73
virtual void move_straight(int64_t distance_mm, double mm_per_sec, const ProtoStruct &extra)=0
Move a robot's base in a straight line by a given distance. This method blocks until completed or can...
virtual void set_velocity(const Vector3 &linear, const Vector3 &angular, const ProtoStruct &extra)=0
Set the linear and angular velocity of a base.
properties get_properties()
Returns physical properties of the base (width, turning radius, wheel circumference)
Definition base.hpp:105
virtual properties get_properties(const ProtoStruct &extra)=0
Returns physical properties of the base (width, turning radius, wheel circumference)
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling base.
Definition base.hpp:120
void move_straight(int64_t distance_mm, double mm_per_sec)
Move a robot's base in a straight line by a given distance. This method blocks until completed or can...
Definition base.hpp:41
void spin(double angle_deg, double degs_per_sec)
Spins a robot's base by an given angle, expressed in degrees. This method blocks until completed or c...
Definition base.hpp:58
virtual void set_power(const Vector3 &linear, const Vector3 &angular, const ProtoStruct &extra)=0
Sets the linear and angular power of a base -1 -> 1 in terms of power for each direction.
void set_velocity(const Vector3 &linear, const Vector3 &angular)
Set the linear and angular velocity of a base.
Definition base.hpp:89
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 linear_algebra.hpp:15
Definition resource_api.hpp:50
Information about the physical base.
Definition base.hpp:29