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 <grpcpp/channel.h>
7
8#include <viam/api/component/encoder/v1/encoder.grpc.pb.h>
9
11#include <viam/sdk/config/resource.hpp>
12
13namespace viam {
14namespace sdk {
15namespace impl {
16
20class EncoderClient : public Encoder {
21 public:
22 using interface_type = Encoder;
23 EncoderClient(std::string name, std::shared_ptr<grpc::Channel> channel);
24 position get_position(const ProtoStruct& extra, position_type position_type) override;
25 void reset_position(const ProtoStruct& extra) override;
26 properties get_properties(const ProtoStruct& extra) override;
27 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
28 ProtoStruct do_command(const ProtoStruct& command) override;
29
30 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
31 // like to live in a world where implementers of derived classes don't need to go out of
32 // their way to support two versions of a method (an `extra` version and a non-`extra`
33 // version), and users don't need to pass an unnecessary parameters to all method calls.
34 //
35 // To do this, we define in the parent resource class a non-virtual version of the methods
36 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
37 // param. In order to access these versions of the methods within the client code, however,
38 // we need to include these `using` lines.
43
44 private:
45 using StubType = viam::component::encoder::v1::EncoderService::StubInterface;
46 std::unique_ptr<StubType> stub_;
47 std::shared_ptr<grpc::Channel> channel_;
48};
49
50} // namespace impl
51} // namespace sdk
52} // 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.
gRPC client implementation of a Encoder component.
Definition encoder_client.hpp:20
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