Viam C++ SDK current
Loading...
Searching...
No Matches
encoder.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <viam/sdk/common/proto_value.hpp>
9#include <viam/sdk/common/utils.hpp>
10#include <viam/sdk/config/resource.hpp>
11
12namespace viam {
13namespace sdk {
14
21class Encoder : public Component {
22 public:
24 enum class position_type : uint8_t {
25 // Unspecified position type
26 unspecified = 0,
27 // Provided by incremental encoders
28 ticks_count = 1,
29 // Provided by absolute encoders
30 angle_degrees = 2
31 };
32
35 struct position {
36 float value = 0.0f;
37 position_type type = position_type::unspecified;
38 friend bool operator==(const position&, const position&) = default;
39 };
40
43 struct properties {
44 bool ticks_count_supported = false;
45 bool angle_degrees_supported = false;
46 friend bool operator==(const properties&, const properties&) = default;
47 };
48
54 inline position get_position(position_type position_type = position_type::unspecified) {
55 return get_position({}, position_type);
56 }
57
64 virtual position get_position(const ProtoStruct& extra,
65 position_type position_type = position_type::unspecified) = 0;
66
68 inline void reset_position() {
69 return reset_position({});
70 }
71
74 virtual void reset_position(const ProtoStruct& extra) = 0;
75
78 return get_properties({});
79 }
80
83 virtual properties get_properties(const ProtoStruct& extra) = 0;
84
88 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
89
92 virtual ProtoStruct get_status() = 0;
93
96 inline std::vector<GeometryConfig> get_geometries() {
97 return get_geometries({});
98 }
99
103 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
104
105 API api() const override;
106
107 protected:
108 explicit Encoder(std::string name);
109
110 explicit Encoder(const ResourceConfig& cfg);
111};
112
113template <>
115 static API api();
116};
117
118} // namespace sdk
119} // namespace viam
Definition resource_api.hpp:21
Definition component.hpp:10
An encoder is a device that is hooked up to motors to report a position.
Definition encoder.hpp:21
API api() const override
Returns the API associated with a particular resource.
virtual ProtoStruct get_status()=0
Get the status of the encoder.
properties get_properties()
Returns a list of all the position_types that are supported by the encoder.
Definition encoder.hpp:77
virtual void reset_position(const ProtoStruct &extra)=0
Reset the value of the position.
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling encoder.
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:54
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
virtual properties get_properties(const ProtoStruct &extra)=0
Returns a list of all the position_types that are supported by the encoder.
void reset_position()
Reset the value of the position.
Definition encoder.hpp:68
virtual position get_position(const ProtoStruct &extra, position_type position_type=position_type::unspecified)=0
Returns position of the encoder which can either be ticks since last zeroing for an incremental encod...
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling encoder.
Definition encoder.hpp:96
Definition resource.hpp:42
virtual std::string name() const
Return the resource's name.
Definition resource_api.hpp:46
reported position.
Definition encoder.hpp:35
Encodes the supported modes of this encoder.
Definition encoder.hpp:43