Viam C++ SDK current
Loading...
Searching...
No Matches
base_client.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <grpcpp/channel.h>
7
8#include <viam/api/component/base/v1/base.grpc.pb.h>
9
10#include <viam/sdk/common/linear_algebra.hpp>
11#include <viam/sdk/common/proto_value.hpp>
14#include <viam/sdk/config/resource.hpp>
16
17namespace viam {
18namespace sdk {
19namespace impl {
20
24class BaseClient : public Base {
25 public:
26 using interface_type = Base;
27 BaseClient(std::string name, std::shared_ptr<grpc::Channel> channel);
28 void move_straight(int64_t distance_mm, double mm_per_sec, const ProtoStruct& extra) override;
29 void spin(double angle_deg, double degs_per_sec, const ProtoStruct& extra) override;
30 void set_power(const Vector3& linear,
31 const Vector3& angular,
32 const ProtoStruct& extra) override;
33 void set_velocity(const Vector3& linear,
34 const Vector3& angular,
35 const ProtoStruct& extra) override;
36 void stop(const ProtoStruct& extra) override;
37 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
38 properties get_properties(const ProtoStruct& extra) override;
39 bool is_moving() override;
40 ProtoStruct do_command(const ProtoStruct& command) override;
41
42 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
43 // like to live in a world where implementers of derived classes don't need to go out of
44 // their way to support two versions of a method (an `extra` version and a non-`extra`
45 // version), and users don't need to pass an unnecessary parameters to all method calls.
46 //
47 // To do this, we define in the parent resource class a non-virtual version of the methods
48 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
49 // param. In order to access these versions of the methods within the client code, however,
50 // we need to include these `using` lines.
54 using Base::set_power;
56 using Base::spin;
57 using Base::stop;
58
59 private:
60 using StubType = viam::component::base::v1::BaseService::StubInterface;
61 std::unique_ptr<StubType> stub_;
62 std::shared_ptr<grpc::Channel> channel_;
63};
64
65} // namespace impl
66} // namespace sdk
67} // namespace viam
Defines a Base component.
Implements a gRPC server for the Base component.
A Base is the platform that the other parts of a mobile robot attach to.
Definition base.hpp:25
void set_power(const Vector3 &linear, const Vector3 &angular)
Sets the linear and angular power of a base -1 -> 1 in terms of power for each direction.
Definition base.hpp:73
properties get_properties()
Returns physical properties of the base (width, turning radius, wheel circumference)
Definition base.hpp:105
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling base.
Definition base.hpp:120
void move_straight(int64_t distance_mm, double mm_per_sec)
Move a robot's base in a straight line by a given distance. This method blocks until completed or can...
Definition base.hpp:41
void spin(double angle_deg, double degs_per_sec)
Spins a robot's base by an given angle, expressed in degrees. This method blocks until completed or c...
Definition base.hpp:58
void set_velocity(const Vector3 &linear, const Vector3 &angular)
Set the linear and angular velocity of a base.
Definition base.hpp:89
virtual std::string name() const
Return the resource's name.
void stop()
Stops a resource from running.
Definition stoppable.hpp:16
Definition linear_algebra.hpp:15
gRPC client implementation of a Base component.
Definition base_client.hpp:24
void stop(const ProtoStruct &extra) override
Stops a resource from running.
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.
properties get_properties(const ProtoStruct &extra) override
Returns physical properties of the base (width, turning radius, wheel circumference)
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.
ProtoStruct do_command(const ProtoStruct &command) override
Send/receive arbitrary commands to the resource.
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...
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...
void set_velocity(const Vector3 &linear, const Vector3 &angular, const ProtoStruct &extra) override
Set the linear and angular velocity of a base.
gRPC client implementation for a robot.
Information about the physical base.
Definition base.hpp:29