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/resource.hpp>
8
9using namespace viam::sdk;
10
11// `MyBase` inherits from the `Base` class defined in the viam C++ SDK and
12// implements some of the relevant methods. It also specifies a static
13// `validate` method that checks config validity.
14class MyBase : public Base {
15 public:
16 MyBase(const Dependencies& deps, const ResourceConfig& cfg);
17 static std::vector<std::string> validate(ResourceConfig cfg);
18
19 bool is_moving() override;
20 void stop(const ProtoStruct& extra) override;
21 void set_power(const Vector3& linear,
22 const Vector3& angular,
23 const ProtoStruct& extra) override;
24
25 ProtoStruct do_command(const ProtoStruct& command) override;
26 ProtoStruct get_status() override {
27 return {};
28 }
29 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
30 Base::properties get_properties(const ProtoStruct& extra) override;
31
32 void move_straight(int64_t distance_mm, double mm_per_sec, const ProtoStruct& extra) override {
33 throw std::runtime_error("move_straight unimplemented");
34 }
35 void spin(double angle_deg, double degs_per_sec, const ProtoStruct& extra) override {
36 throw std::runtime_error("spin unimplemented");
37 }
38 void set_velocity(const Vector3& linear,
39 const Vector3& angular,
40 const ProtoStruct& extra) override {
41 throw std::runtime_error("set_velocity unimplemented");
42 }
43
44 private:
45 std::shared_ptr<Motor> left_;
46 std::shared_ptr<Motor> right_;
47};
Defines a Base component.
Definition impl.hpp:14
ProtoStruct get_status() override
Get the status of the base.
Definition impl.hpp:26
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 set_velocity(const Vector3 &linear, const Vector3 &angular, const ProtoStruct &extra) override
Set the linear and angular velocity of a base.
Definition impl.hpp:38
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:35
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:32
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 resource.hpp:43
Defines a Motor component.
Information about the physical base.
Definition base.hpp:29
Definition linear_algebra.hpp:25