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/api/component/base/v1/base.pb.h>
9
10#include <viam/sdk/common/linear_algebra.hpp>
11#include <viam/sdk/common/proto_type.hpp>
12#include <viam/sdk/common/utils.hpp>
13#include <viam/sdk/config/resource.hpp>
14#include <viam/sdk/resource/stoppable.hpp>
15
16namespace viam {
17namespace sdk {
18
20
27class Base : public Component, public Stoppable {
28 public:
31 struct properties {
32 double width_meters;
33 double turning_radius_meters;
34 double wheel_circumference_meters;
35
36 static properties from_proto(const component::base::v1::GetPropertiesResponse& proto);
37 };
38 friend std::ostream& operator<<(std::ostream& os, const properties& v);
39 friend bool operator==(const properties& lhs, const properties& rhs);
40
47 }
48
55 double mm_per_sec,
56 const AttributeMap& extra) = 0;
57
62 inline void spin(double angle_deg, double degs_per_sec) {
63 return spin(angle_deg, degs_per_sec, {});
64 }
65
71 virtual void spin(double angle_deg, double degs_per_sec, const AttributeMap& extra) = 0;
72
77 inline void set_power(const Vector3& linear, const Vector3& angular) {
78 return set_power(linear, angular, {});
79 }
80
86 virtual void set_power(const Vector3& linear,
87 const Vector3& angular,
88 const AttributeMap& extra) = 0;
89
93 inline void set_velocity(const Vector3& linear, const Vector3& angular) {
94 return set_velocity(linear, angular, {});
95 }
96
101 virtual void set_velocity(const Vector3& linear,
102 const Vector3& angular,
103 const AttributeMap& extra) = 0;
104
106 virtual bool is_moving() = 0;
107
110 return get_properties({});
111 }
112
115 virtual properties get_properties(const AttributeMap& extra) = 0;
116
120 virtual AttributeMap do_command(const AttributeMap& command) = 0;
121
124 inline std::vector<GeometryConfig> get_geometries() {
125 return get_geometries({});
126 }
127
131 virtual std::vector<GeometryConfig> get_geometries(const AttributeMap& extra) = 0;
132
133 API api() const override;
134
135 protected:
136 explicit Base(std::string name);
137};
138
139template <>
141 static API api();
142};
143
144} // namespace sdk
145} // 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:27
virtual void set_velocity(const Vector3 &linear, const Vector3 &angular, const AttributeMap &extra)=0
Set the linear and angular velocity of a base.
virtual bool is_moving()=0
Reports if the base is in motion.
virtual void set_power(const Vector3 &linear, const Vector3 &angular, const AttributeMap &extra)=0
Sets the linear and angular power of a base -1 -> 1 in terms of power for each direction.
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:77
virtual void move_straight(int64_t distance_mm, double mm_per_sec, const AttributeMap &extra)=0
Move a robot's base in a straight line by a given distance. This method blocks until completed or can...
virtual std::vector< GeometryConfig > get_geometries(const AttributeMap &extra)=0
Returns GeometryConfigs associated with the calling base.
virtual properties get_properties(const AttributeMap &extra)=0
Returns physical properties of the base (width, turning radius, wheel circumference)
properties get_properties()
Returns physical properties of the base (width, turning radius, wheel circumference)
Definition base.hpp:109
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling base.
Definition base.hpp:124
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:45
virtual AttributeMap do_command(const AttributeMap &command)=0
Send/receive arbitrary commands to the resource.
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:62
void set_velocity(const Vector3 &linear, const Vector3 &angular)
Set the linear and angular velocity of a base.
Definition base.hpp:93
virtual void spin(double angle_deg, double degs_per_sec, const AttributeMap &extra)=0
Spins a robot's base by an given angle, expressed in degrees. This method blocks until completed or c...
API api() const override
Returns the API associated with a particular resource.
Definition client_helper.hpp:16
Definition component.hpp:14
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:31