Viam C++ SDK current
Loading...
Searching...
No Matches
motor.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <viam/sdk/common/proto_value.hpp>
9#include <viam/sdk/common/utils.hpp>
10#include <viam/sdk/config/resource.hpp>
11#include <viam/sdk/resource/stoppable.hpp>
12
13namespace viam {
14namespace sdk {
15
22class Motor : public Component, public Stoppable {
23 public:
26 typedef double position;
27
30 struct power_status {
32 bool is_on = false;
36 double power_pct = 0.0;
37 friend bool operator==(const power_status&, const power_status&) = default;
38 };
39
42 struct properties {
44 bool position_reporting = false;
45 friend bool operator==(const properties&, const properties&) = default;
46 };
47
51 inline void set_power(double power_pct) {
52 return set_power(power_pct, {});
53 }
54
59 virtual void set_power(double power_pct, const ProtoStruct& extra) = 0;
60
69 inline void go_for(double rpm, double revolutions) {
70 return go_for(rpm, revolutions, {});
71 }
72
82 virtual void go_for(double rpm, double revolutions, const ProtoStruct& extra) = 0;
83
89 inline void go_to(double rpm, double position_revolutions) {
90 return go_to(rpm, position_revolutions, {});
91 }
92
99 virtual void go_to(double rpm, double position_revolutions, const ProtoStruct& extra) = 0;
100
104 inline void set_rpm(double rpm) {
105 return set_rpm(rpm, {});
106 }
107
112 virtual void set_rpm(double rpm, const ProtoStruct& extra) = 0;
113
117 inline void reset_zero_position(double offset) {
118 return reset_zero_position(offset, {});
119 }
120
125 virtual void reset_zero_position(double offset, const ProtoStruct& extra) = 0;
126
130 return get_position({});
131 }
132
136 virtual position get_position(const ProtoStruct& extra) = 0;
137
141 return get_properties({});
142 }
143
147 virtual properties get_properties(const ProtoStruct& extra) = 0;
148
151 return get_power_status({});
152 }
153
156 virtual power_status get_power_status(const ProtoStruct& extra) = 0;
157
159 virtual bool is_moving() = 0;
160
163 virtual ProtoStruct get_status() = 0;
164
168 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
169
172 inline std::vector<GeometryConfig> get_geometries() {
173 return get_geometries({});
174 }
175
179 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
180
181 API api() const override;
182
183 protected:
184 explicit Motor(std::string name);
185
186 explicit Motor(const ResourceConfig& cfg);
187};
188
189template <>
191 static API api();
192};
193
194} // namespace sdk
195} // namespace viam
Definition resource_api.hpp:21
Definition component.hpp:10
A Motor represents physical hardware that controls the rotation of an axle.
Definition motor.hpp:22
void go_to(double rpm, double position_revolutions)
Move the motor to a specific position that is relative to its home position at a specified speed whic...
Definition motor.hpp:89
position get_position()
Reports the position of the robot's motor relative to its zero position.
Definition motor.hpp:129
void set_power(double power_pct)
Sets the percentage of the motor's total power that should be employed.
Definition motor.hpp:51
virtual void go_for(double rpm, double revolutions, const ProtoStruct &extra)=0
Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number o...
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling motor.
void set_rpm(double rpm)
Move the motor indefinitely at a specified speed which is expressed in RPM.
Definition motor.hpp:104
virtual void reset_zero_position(double offset, const ProtoStruct &extra)=0
Sets the current position of the motor as the new zero position.
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling motor.
Definition motor.hpp:172
virtual void set_rpm(double rpm, const ProtoStruct &extra)=0
Move the motor indefinitely at a specified speed which is expressed in RPM.
virtual properties get_properties(const ProtoStruct &extra)=0
Returns the properties of the motor which comprises the booleans indicating.
virtual position get_position(const ProtoStruct &extra)=0
Reports the position of the robot's motor relative to its zero position.
virtual ProtoStruct get_status()=0
Get the status of the motor.
void go_for(double rpm, double revolutions)
Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number o...
Definition motor.hpp:69
properties get_properties()
Returns the properties of the motor which comprises the booleans indicating which optional features t...
Definition motor.hpp:140
power_status get_power_status()
Definition motor.hpp:150
virtual void set_power(double power_pct, const ProtoStruct &extra)=0
Sets the percentage of the motor's total power that should be employed.
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
virtual void go_to(double rpm, double position_revolutions, const ProtoStruct &extra)=0
Move the motor to a specific position that is relative to its home position at a specified speed whic...
void reset_zero_position(double offset)
Sets the current position of the motor as the new zero position.
Definition motor.hpp:117
virtual power_status get_power_status(const ProtoStruct &extra)=0
virtual bool is_moving()=0
Reports if a component is in motion.
API api() const override
Returns the API associated with a particular resource.
Definition resource.hpp:42
virtual std::string name() const
Return the resource's name.
Definition stoppable.hpp:8
Current position of the motor relative to its home.
Definition resource_api.hpp:46
Information about power-state of the motor.
Definition motor.hpp:30
bool is_on
True if the motor is on.
Definition motor.hpp:32
double power_pct
Definition motor.hpp:36
Features that the specific motor supports.
Definition motor.hpp:42
bool position_reporting
True if the motor supports reporting its position.
Definition motor.hpp:44