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;
37 position_type type;
38 };
39
42 struct properties {
43 bool ticks_count_supported;
44 bool angle_degrees_supported;
45 };
46
52 inline position get_position(position_type position_type = position_type::unspecified) {
53 return get_position({}, position_type);
54 }
55
62 virtual position get_position(const ProtoStruct& extra,
63 position_type position_type = position_type::unspecified) = 0;
64
66 inline void reset_position() {
67 return reset_position({});
68 }
69
72 virtual void reset_position(const ProtoStruct& extra) = 0;
73
76 return get_properties({});
77 }
78
81 virtual properties get_properties(const ProtoStruct& extra) = 0;
82
86 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
87
90 inline std::vector<GeometryConfig> get_geometries() {
91 return get_geometries({});
92 }
93
97 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
98
99 API api() const override;
100
101 protected:
102 explicit Encoder(std::string name);
103};
104
105template <>
107 static API api();
108};
109
110bool operator==(const Encoder::position& lhs, const Encoder::position& rhs);
111bool operator==(const Encoder::properties& lhs, const Encoder::properties& rhs);
112
113} // namespace sdk
114} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
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.
properties get_properties()
Returns a list of all the position_types that are supported by the encoder.
Definition encoder.hpp:75
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:52
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:66
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:90
virtual std::string name() const
Return the resource's name.
Definition resource_api.hpp:50
reported position.
Definition encoder.hpp:35
Encodes the supported modes of this encoder.
Definition encoder.hpp:42