Viam C++ SDK current
Loading...
Searching...
No Matches
encoder_client.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <viam/api/component/encoder/v1/encoder.grpc.pb.h>
7
9#include <viam/sdk/config/resource.hpp>
10#include <viam/sdk/rpc/dial.hpp>
11
12namespace viam {
13namespace sdk {
14namespace impl {
15
19class EncoderClient : public Encoder {
20 public:
21 using interface_type = Encoder;
22 EncoderClient(std::string name, const ViamChannel& channel);
23
24 const ViamChannel& channel() const {
25 return *channel_;
26 }
27 position get_position(const ProtoStruct& extra, position_type position_type) override;
28 void reset_position(const ProtoStruct& extra) override;
29 properties get_properties(const ProtoStruct& extra) override;
30 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
31 ProtoStruct do_command(const ProtoStruct& command) override;
32
33 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
34 // like to live in a world where implementers of derived classes don't need to go out of
35 // their way to support two versions of a method (an `extra` version and a non-`extra`
36 // version), and users don't need to pass an unnecessary parameters to all method calls.
37 //
38 // To do this, we define in the parent resource class a non-virtual version of the methods
39 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
40 // param. In order to access these versions of the methods within the client code, however,
41 // we need to include these `using` lines.
46
47 private:
48 using StubType = viam::component::encoder::v1::EncoderService::StubInterface;
49 std::unique_ptr<StubType> stub_;
50 const ViamChannel* channel_;
51};
52
53} // namespace impl
54} // namespace sdk
55} // namespace viam
An encoder is a device that is hooked up to motors to report a position.
Definition encoder.hpp:21
properties get_properties()
Returns a list of all the position_types that are supported by the encoder.
Definition encoder.hpp:75
position get_position(position_type position_type=position_type::unspecified)
Returns position of the encoder which can either be ticks since last zeroing for an incremental encod...
Definition encoder.hpp:52
void reset_position()
Reset the value of the position.
Definition encoder.hpp:66
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling encoder.
Definition encoder.hpp:90
virtual std::string name() const
Return the resource's name.
Definition dial.hpp:25
gRPC client implementation of a Encoder component.
Definition encoder_client.hpp:19
ProtoStruct do_command(const ProtoStruct &command) override
Send/receive arbitrary commands to the resource.
std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra) override
Returns GeometryConfigs associated with the calling encoder.
properties get_properties(const ProtoStruct &extra) override
Returns a list of all the position_types that are supported by the encoder.
position get_position(const ProtoStruct &extra, position_type position_type) override
Returns position of the encoder which can either be ticks since last zeroing for an incremental encod...
void reset_position(const ProtoStruct &extra) override
Reset the value of the position.
Defines a Encoder component.
reported position.
Definition encoder.hpp:35
Encodes the supported modes of this encoder.
Definition encoder.hpp:42