Viam C++ SDK current
Loading...
Searching...
No Matches
motor_client.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <viam/api/component/motor/v1/motor.grpc.pb.h>
7
10#include <viam/sdk/config/resource.hpp>
11#include <viam/sdk/rpc/dial.hpp>
12
13namespace viam {
14namespace sdk {
15namespace impl {
16
20class MotorClient : public Motor {
21 public:
22 using interface_type = Motor;
23 MotorClient(std::string name, const ViamChannel& channel);
24
25 const ViamChannel& channel() const {
26 return *channel_;
27 }
28 void set_power(double power_pct, const ProtoStruct& extra) override;
29 void go_for(double rpm, double revolutions, const ProtoStruct& extra) override;
30 void go_to(double rpm, double position_revolutions, const ProtoStruct& extra) override;
31 void set_rpm(double rpm, const ProtoStruct& extra) override;
32 void reset_zero_position(double offset, const ProtoStruct& extra) override;
33 position get_position(const ProtoStruct& extra) override;
34 properties get_properties(const ProtoStruct& extra) override;
35 void stop(const ProtoStruct& extra) override;
36 power_status get_power_status(const ProtoStruct& extra) override;
37 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
38 bool is_moving() override;
39 ProtoStruct do_command(const ProtoStruct& command) override;
40
41 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
42 // like to live in a world where implementers of derived classes don't need to go out of
43 // their way to support two versions of a method (an `extra` version and a non-`extra`
44 // version), and users don't need to pass an unnecessary parameters to all method calls.
45 //
46 // To do this, we define in the parent resource class a non-virtual version of the methods
47 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
48 // param. In order to access these versions of the methods within the client code, however,
49 // we need to include these `using` lines.
54 using Motor::go_for;
55 using Motor::go_to;
57 using Motor::set_power;
58 using Motor::set_rpm;
59 using Motor::stop;
60
61 private:
62 using StubType = viam::component::motor::v1::MotorService::StubInterface;
63 std::unique_ptr<StubType> stub_;
64 const ViamChannel* channel_;
65};
66
67} // namespace impl
68} // namespace sdk
69} // namespace viam
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
void set_rpm(double rpm)
Move the motor indefinitely at a specified speed which is expressed in RPM.
Definition motor.hpp:102
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling motor.
Definition motor.hpp:166
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
void reset_zero_position(double offset)
Sets the current position of the motor as the new zero position.
Definition motor.hpp:115
virtual std::string name() const
Return the resource's name.
void stop()
Stops a resource from running.
Definition stoppable.hpp:16
Definition dial.hpp:25
gRPC client implementation of a Motor component.
Definition motor_client.hpp:20
bool is_moving() override
Reports if a component is in motion.
void set_rpm(double rpm, const ProtoStruct &extra) override
Move the motor indefinitely at a specified speed which is expressed in RPM.
void go_for(double rpm, double revolutions, const ProtoStruct &extra) override
Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number o...
void stop(const ProtoStruct &extra) override
Stops a resource from running.
position get_position(const ProtoStruct &extra) override
Reports the position of the robot's motor relative to its zero position.
void go_to(double rpm, double position_revolutions, const ProtoStruct &extra) override
Move the motor to a specific position that is relative to its home position at a specified speed whic...
std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra) override
Returns GeometryConfigs associated with the calling motor.
ProtoStruct do_command(const ProtoStruct &command) override
Send/receive arbitrary commands to the resource.
power_status get_power_status(const ProtoStruct &extra) override
void set_power(double power_pct, const ProtoStruct &extra) override
Sets the percentage of the motor's total power that should be employed.
properties get_properties(const ProtoStruct &extra) override
Returns the properties of the motor which comprises the booleans indicating.
void reset_zero_position(double offset, const ProtoStruct &extra) override
Sets the current position of the motor as the new zero position.
Defines a Motor component.
Implements a gRPC server for the Motor component.
Current position of the motor relative to its home.
Information about power-state of the motor.
Definition motor.hpp:30
Features that the specific motor supports.
Definition motor.hpp:41