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;
36 double power_pct;
37 };
38
41 struct properties {
44 };
45
49 inline void set_power(double power_pct) {
50 return set_power(power_pct, {});
51 }
52
57 virtual void set_power(double power_pct, const ProtoStruct& extra) = 0;
58
67 inline void go_for(double rpm, double revolutions) {
68 return go_for(rpm, revolutions, {});
69 }
70
80 virtual void go_for(double rpm, double revolutions, const ProtoStruct& extra) = 0;
81
87 inline void go_to(double rpm, double position_revolutions) {
88 return go_to(rpm, position_revolutions, {});
89 }
90
97 virtual void go_to(double rpm, double position_revolutions, const ProtoStruct& extra) = 0;
98
102 inline void set_rpm(double rpm) {
103 return set_rpm(rpm, {});
104 }
105
110 virtual void set_rpm(double rpm, const ProtoStruct& extra) = 0;
111
115 inline void reset_zero_position(double offset) {
116 return reset_zero_position(offset, {});
117 }
118
123 virtual void reset_zero_position(double offset, const ProtoStruct& extra) = 0;
124
128 return get_position({});
129 }
130
134 virtual position get_position(const ProtoStruct& extra) = 0;
135
139 return get_properties({});
140 }
141
145 virtual properties get_properties(const ProtoStruct& extra) = 0;
146
149 return get_power_status({});
150 }
151
154 virtual power_status get_power_status(const ProtoStruct& extra) = 0;
155
157 virtual bool is_moving() = 0;
158
162 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
163
166 inline std::vector<GeometryConfig> get_geometries() {
167 return get_geometries({});
168 }
169
173 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
174
175 API api() const override;
176
177 protected:
178 explicit Motor(std::string name);
179};
180
181template <>
183 static API api();
184};
185
186bool operator==(const Motor::power_status& lhs, const Motor::power_status& rhs);
187bool operator==(const Motor::properties& lhs, const Motor::properties& rhs);
188
189} // namespace sdk
190} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
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:87
position get_position()
Reports the position of the robot's motor relative to its zero position.
Definition motor.hpp:127
void set_power(double power_pct)
Sets the percentage of the motor's total power that should be employed.
Definition motor.hpp:49
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:102
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:166
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.
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:67
properties get_properties()
Returns the properties of the motor which comprises the booleans indicating which optional features t...
Definition motor.hpp:138
power_status get_power_status()
Definition motor.hpp:148
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:115
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.
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:50
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:41
bool position_reporting
True if the motor supports reporting its position.
Definition motor.hpp:43