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 <grpcpp/channel.h>
7
8#include <viam/api/component/motor/v1/motor.grpc.pb.h>
9
12#include <viam/sdk/config/resource.hpp>
13
14namespace viam {
15namespace sdk {
16namespace impl {
17
21class MotorClient : public Motor {
22 public:
23 using interface_type = Motor;
24 MotorClient(std::string name, std::shared_ptr<grpc::Channel> channel);
25 void set_power(double power_pct, const ProtoStruct& extra) override;
26 void go_for(double rpm, double revolutions, const ProtoStruct& extra) override;
27 void go_to(double rpm, double position_revolutions, const ProtoStruct& extra) override;
28 void set_rpm(double rpm, const ProtoStruct& extra) override;
29 void reset_zero_position(double offset, const ProtoStruct& extra) override;
30 position get_position(const ProtoStruct& extra) override;
31 properties get_properties(const ProtoStruct& extra) override;
32 void stop(const ProtoStruct& extra) override;
33 power_status get_power_status(const ProtoStruct& extra) override;
34 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
35 bool is_moving() override;
36 ProtoStruct do_command(const ProtoStruct& command) override;
37
38 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
39 // like to live in a world where implementers of derived classes don't need to go out of
40 // their way to support two versions of a method (an `extra` version and a non-`extra`
41 // version), and users don't need to pass an unnecessary parameters to all method calls.
42 //
43 // To do this, we define in the parent resource class a non-virtual version of the methods
44 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
45 // param. In order to access these versions of the methods within the client code, however,
46 // we need to include these `using` lines.
51 using Motor::go_for;
52 using Motor::go_to;
54 using Motor::set_power;
55 using Motor::set_rpm;
56 using Motor::stop;
57
58 private:
59 using StubType = viam::component::motor::v1::MotorService::StubInterface;
60 std::unique_ptr<StubType> stub_;
61 std::shared_ptr<grpc::Channel> channel_;
62};
63
64} // namespace impl
65} // namespace sdk
66} // 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
gRPC client implementation of a Motor component.
Definition motor_client.hpp:21
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