Viam C++ SDK current
Loading...
Searching...
No Matches
servo.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <viam/api/component/servo/v1/servo.pb.h>
7
8#include <viam/sdk/common/proto_type.hpp>
9#include <viam/sdk/common/utils.hpp>
10#include <viam/sdk/config/resource.hpp>
11#include <viam/sdk/resource/stoppable.hpp>
12
13namespace viam {
14namespace sdk {
15
17
23class Servo : public Component, public Stoppable {
24 public:
27 typedef uint32_t position;
28
29 API api() const override;
30
32 static position from_proto(const viam::component::servo::v1::GetPositionResponse& proto);
33
36 inline void move(uint32_t angle_deg) {
37 return move(angle_deg, {});
38 }
39
43 virtual void move(uint32_t angle_deg, const AttributeMap& extra) = 0;
44
48 return get_position({});
49 }
50
54 virtual position get_position(const AttributeMap& extra) = 0;
55
57 virtual bool is_moving() = 0;
58
62 virtual AttributeMap do_command(const AttributeMap& command) = 0;
63
66 inline std::vector<GeometryConfig> get_geometries() {
67 return get_geometries({});
68 }
69
73 virtual std::vector<GeometryConfig> get_geometries(const AttributeMap& extra) = 0;
74
75 protected:
76 explicit Servo(std::string name) : Component(std::move(name)){};
77};
78
79template <>
81 static API api();
82};
83
84} // namespace sdk
85} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Definition component.hpp:14
virtual std::string name() const
Return the resource's name.
Definition servo.hpp:23
virtual position get_position(const AttributeMap &extra)=0
Reports the position of the robot's servo relative to its zero position.
virtual void move(uint32_t angle_deg, const AttributeMap &extra)=0
Move the servo to the provided angle.
API api() const override
Returns the API associated with a particular resource.
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling servo.
Definition servo.hpp:66
static position from_proto(const viam::component::servo::v1::GetPositionResponse &proto)
Creates a position struct from its proto representation.
void move(uint32_t angle_deg)
Move the servo to the provided angle.
Definition servo.hpp:36
virtual AttributeMap do_command(const AttributeMap &command)=0
Send/receive arbitrary commands to the resource.
virtual std::vector< GeometryConfig > get_geometries(const AttributeMap &extra)=0
Returns GeometryConfigs associated with the calling servo.
virtual bool is_moving()=0
Reports if a component is in motion.
position get_position()
Get the current angle (degrees) of the servo.
Definition servo.hpp:47
Definition stoppable.hpp:8
Current position of the motor relative to its home.
Definition resource_api.hpp:50