Viam C++ SDK current
Loading...
Searching...
No Matches
impl.hpp
1#pragma once
2
4#include <viam/sdk/components/component.hpp>
6#include <viam/sdk/config/resource.hpp>
7#include <viam/sdk/resource/reconfigurable.hpp>
8#include <viam/sdk/resource/resource.hpp>
9
10using namespace viam::sdk;
11
12// `MyBase` inherits from the `Base` class defined in the viam C++ SDK and
13// implements some of the relevant methods along with `reconfigure`. It also
14// specifies a static `validate` method that checks config validity.
15class MyBase : public Base, public Reconfigurable {
16 public:
17 MyBase(const Dependencies& deps, const ResourceConfig& cfg) : Base(cfg.name()) {
18 this->reconfigure(deps, cfg);
19 };
20 void reconfigure(const Dependencies& deps, const ResourceConfig& cfg) override;
21 static std::vector<std::string> validate(ResourceConfig cfg);
22
23 bool is_moving() override;
24 void stop(const ProtoStruct& extra) override;
25 void set_power(const Vector3& linear,
26 const Vector3& angular,
27 const ProtoStruct& extra) override;
28
29 ProtoStruct do_command(const ProtoStruct& command) override;
30 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
31 Base::properties get_properties(const ProtoStruct& extra) override;
32
33 void move_straight(int64_t distance_mm, double mm_per_sec, const ProtoStruct& extra) override {
34 throw std::runtime_error("move_straight unimplemented");
35 }
36 void spin(double angle_deg, double degs_per_sec, const ProtoStruct& extra) override {
37 throw std::runtime_error("spin unimplemented");
38 }
39 void set_velocity(const Vector3& linear,
40 const Vector3& angular,
41 const ProtoStruct& extra) override {
42 throw std::runtime_error("set_velocity unimplemented");
43 }
44
45 private:
46 std::shared_ptr<Motor> left_;
47 std::shared_ptr<Motor> right_;
48};
Defines a Base component.
Definition impl.hpp:15
void set_power(const Vector3 &linear, const Vector3 &angular, const ProtoStruct &extra) override
Sets the linear and angular power of a base -1 -> 1 in terms of power for each direction.
void reconfigure(const Dependencies &deps, const ResourceConfig &cfg) override
Reconfigures a resource.
void set_velocity(const Vector3 &linear, const Vector3 &angular, const ProtoStruct &extra) override
Set the linear and angular velocity of a base.
Definition impl.hpp:39
Base::properties get_properties(const ProtoStruct &extra) override
Returns physical properties of the base (width, turning radius, wheel circumference)
void spin(double angle_deg, double degs_per_sec, const ProtoStruct &extra) override
Spins a robot's base by an given angle, expressed in degrees. This method blocks until completed or c...
Definition impl.hpp:36
bool is_moving() override
Reports if the base is in motion.
std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra) override
Returns GeometryConfigs associated with the calling base.
void move_straight(int64_t distance_mm, double mm_per_sec, const ProtoStruct &extra) override
Move a robot's base in a straight line by a given distance. This method blocks until completed or can...
Definition impl.hpp:33
ProtoStruct do_command(const ProtoStruct &command) override
Send/receive arbitrary commands to the resource.
void stop(const ProtoStruct &extra) override
Stops a resource from running.
A Base is the platform that the other parts of a mobile robot attach to.
Definition base.hpp:25
Definition reconfigurable.hpp:9
Definition resource.hpp:23
Definition linear_algebra.hpp:15
Defines a Motor component.
Information about the physical base.
Definition base.hpp:29