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/sdk/common/proto_value.hpp>
7#include <viam/sdk/common/utils.hpp>
8#include <viam/sdk/config/resource.hpp>
9#include <viam/sdk/resource/stoppable.hpp>
10
11namespace viam {
12namespace sdk {
13
15
21class Servo : public Component, public Stoppable {
22 public:
25 typedef uint32_t position;
26
27 API api() const override;
28
31 inline void move(uint32_t angle_deg) {
32 return move(angle_deg, {});
33 }
34
38 virtual void move(uint32_t angle_deg, const ProtoStruct& extra) = 0;
39
43 return get_position({});
44 }
45
49 virtual position get_position(const ProtoStruct& extra) = 0;
50
52 virtual bool is_moving() = 0;
53
57 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
58
61 inline std::vector<GeometryConfig> get_geometries() {
62 return get_geometries({});
63 }
64
68 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
69
70 protected:
71 explicit Servo(std::string name) : Component(std::move(name)){};
72};
73
74template <>
76 static API api();
77};
78
79} // namespace sdk
80} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Definition component.hpp:10
virtual std::string name() const
Return the resource's name.
Definition servo.hpp:21
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
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:61
void move(uint32_t angle_deg)
Move the servo to the provided angle.
Definition servo.hpp:31
virtual position get_position(const ProtoStruct &extra)=0
Reports the position of the robot's servo relative to its zero position.
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:42
virtual void move(uint32_t angle_deg, const ProtoStruct &extra)=0
Move the servo to the provided angle.
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling servo.
Definition stoppable.hpp:8
Current position of the motor relative to its home.
Definition resource_api.hpp:50