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 AttributeMap& extra) override;
26 void go_for(double rpm, double revolutions, const AttributeMap& extra) override;
27 void go_to(double rpm, double position_revolutions, const AttributeMap& extra) override;
28 void set_rpm(double rpm, const AttributeMap& extra) override;
29 void reset_zero_position(double offset, const AttributeMap& extra) override;
30 position get_position(const AttributeMap& extra) override;
31 properties get_properties(const AttributeMap& extra) override;
32 void stop(const AttributeMap& extra) override;
33 power_status get_power_status(const AttributeMap& extra) override;
34 std::vector<GeometryConfig> get_geometries(const AttributeMap& extra) override;
35 bool is_moving() override;
36 AttributeMap do_command(const AttributeMap& 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:24
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:107
position get_position()
Reports the position of the robot's motor relative to its zero position.
Definition motor.hpp:147
void set_power(double power_pct)
Sets the percentage of the motor's total power that should be employed.
Definition motor.hpp:69
void set_rpm(double rpm)
Move the motor indefinitely at a specified speed which is expressed in RPM.
Definition motor.hpp:122
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling motor.
Definition motor.hpp:186
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:87
properties get_properties()
Returns the properties of the motor which comprises the booleans indicating which optional features t...
Definition motor.hpp:158
power_status get_power_status()
Definition motor.hpp:168
void reset_zero_position(double offset)
Sets the current position of the motor as the new zero position.
Definition motor.hpp:135
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.
position get_position(const AttributeMap &extra) override
Reports the position of the robot's motor relative to its zero position.
void stop(const AttributeMap &extra) override
Stops a resource from running.
void go_for(double rpm, double revolutions, const AttributeMap &extra) override
Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number o...
void go_to(double rpm, double position_revolutions, const AttributeMap &extra) override
Move the motor to a specific position that is relative to its home position at a specified speed whic...
properties get_properties(const AttributeMap &extra) override
Returns the properties of the motor which comprises the booleans indicating.
void set_power(double power_pct, const AttributeMap &extra) override
Sets the percentage of the motor's total power that should be employed.
AttributeMap do_command(const AttributeMap &command) override
Send/receive arbitrary commands to the resource.
void reset_zero_position(double offset, const AttributeMap &extra) override
Sets the current position of the motor as the new zero position.
void set_rpm(double rpm, const AttributeMap &extra) override
Move the motor indefinitely at a specified speed which is expressed in RPM.
std::vector< GeometryConfig > get_geometries(const AttributeMap &extra) override
Returns GeometryConfigs associated with the calling motor.
power_status get_power_status(const AttributeMap &extra) override
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:32
Features that the specific motor supports.
Definition motor.hpp:43