Viam C++ SDK current
Loading...
Searching...
No Matches
board_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/board/v1/board.grpc.pb.h>
9
12#include <viam/sdk/config/resource.hpp>
14
15namespace viam {
16namespace sdk {
17namespace impl {
18
22class BoardClient : public Board {
23 public:
24 using interface_type = Board;
25 BoardClient(std::string name, std::shared_ptr<grpc::Channel> channel);
26 ProtoStruct do_command(const ProtoStruct& command) override;
27 void set_gpio(const std::string& pin, bool high, const ProtoStruct& extra) override;
28 bool get_gpio(const std::string& pin, const ProtoStruct& extra) override;
29 double get_pwm_duty_cycle(const std::string& pin, const ProtoStruct& extra) override;
30 void set_pwm_duty_cycle(const std::string& pin,
31 double duty_cycle_pct,
32 const ProtoStruct& extra) override;
33 uint64_t get_pwm_frequency(const std::string& pin, const ProtoStruct& extra) override;
34 void set_pwm_frequency(const std::string& pin,
35 uint64_t frequency_hz,
36 const ProtoStruct& extra) override;
37 analog_response read_analog(const std::string& analog_reader_name,
38 const ProtoStruct& extra) override;
39 void write_analog(const std::string& pin, int value, const ProtoStruct& extra) override;
40 digital_value read_digital_interrupt(const std::string& digital_interrupt_name,
41 const ProtoStruct& extra) override;
43 const ProtoStruct& extra,
44 const boost::optional<std::chrono::microseconds>& duration) override;
45 std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
46
47 void stream_ticks(std::vector<std::string> const& digital_interrupt_names,
48 std::function<bool(Tick&& tick)> const& tick_handler,
49 const ProtoStruct& extra) override;
50
51 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
52 // like to live in a world where implementers of derived classes don't need to go out of
53 // their way to support two versions of a method (an `extra` version and a non-`extra`
54 // version), and users don't need to pass an unnecessary parameters to all method calls.
55 //
56 // To do this, we define in the parent resource class a non-virtual version of the methods
57 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
58 // param. In order to access these versions of the methods within the client code, however,
59 // we need to include these `using` lines.
61 using Board::get_gpio;
66 using Board::set_gpio;
72
73 private:
74 using StubType = viam::component::board::v1::BoardService::StubInterface;
75 std::unique_ptr<StubType> stub_;
76 const std::shared_ptr<grpc::Channel> channel_;
77};
78
79} // namespace impl
80} // namespace sdk
81} // namespace viam
Defines a Board component.
Implements a gRPC server for the Board component.
Represents a physical board with gpio pins, digital interrupts, and analog voltage reading.
Definition board.hpp:24
power_mode
Power mode of the board The effect of these power modes depends on your physical board.
Definition board.hpp:73
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling board.
Definition board.hpp:242
void set_power_mode(power_mode power_mode, const boost::optional< std::chrono::microseconds > &duration={})
Sets the power consumption mode of the board to the requested setting for the given duration.
Definition board.hpp:220
analog_response read_analog(const std::string &analog_reader_name)
Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board d...
Definition board.hpp:160
void set_gpio(const std::string &pin, bool high)
Set the gpio high/low state of the given pin on a board.
Definition board.hpp:92
uint64_t get_pwm_frequency(const std::string &pin)
Gets the PWM frequency of the given pin on a board.
Definition board.hpp:131
int64_t digital_value
Depending on the type of digital interrupt, this can have different meanings. If a basic (default) in...
Definition board.hpp:47
digital_value read_digital_interrupt(const std::string &digital_interrupt_name)
Returns the current value of the interrupt which is based on the type of interrupt....
Definition board.hpp:187
void set_pwm_duty_cycle(const std::string &pin, double duty_cycle_pct)
Sets the given pin of a board to the given duty cycle.
Definition board.hpp:117
void write_analog(const std::string &pin, int value)
Writes the value to the analog writer of the board.
Definition board.hpp:174
void stream_ticks(std::vector< std::string > const &digital_interrupt_names, std::function< bool(Tick &&tick)> const &tick_handler)
Returns a stream of digital interrupt ticks.
Definition board.hpp:203
void set_pwm_frequency(const std::string &pin, uint64_t frequency_hz)
Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequenc...
Definition board.hpp:144
bool get_gpio(const std::string &pin)
Gets the high/low state of the given pin on a board.
Definition board.hpp:80
double get_pwm_duty_cycle(const std::string &pin)
Gets the duty cycle of the given pin on a board.
Definition board.hpp:104
virtual std::string name() const
Return the resource's name.
gRPC client implementation of a Board component.
Definition board_client.hpp:22
void set_pwm_duty_cycle(const std::string &pin, double duty_cycle_pct, const ProtoStruct &extra) override
Sets the given pin of a board to the given duty cycle.
ProtoStruct do_command(const ProtoStruct &command) override
Send/receive arbitrary commands to the resource.
void write_analog(const std::string &pin, int value, const ProtoStruct &extra) override
Writes the value to the analog writer of the board.
double get_pwm_duty_cycle(const std::string &pin, const ProtoStruct &extra) override
Gets the duty cycle of the given pin on a board.
void set_pwm_frequency(const std::string &pin, uint64_t frequency_hz, const ProtoStruct &extra) override
Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequenc...
digital_value read_digital_interrupt(const std::string &digital_interrupt_name, const ProtoStruct &extra) override
Returns the current value of the interrupt which is based on the type of interrupt....
std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra) override
Returns GeometryConfigs associated with the calling board.
void set_power_mode(power_mode power_mode, const ProtoStruct &extra, const boost::optional< std::chrono::microseconds > &duration) override
Sets the power consumption mode of the board to the requested setting for the given duration.
void stream_ticks(std::vector< std::string > const &digital_interrupt_names, std::function< bool(Tick &&tick)> const &tick_handler, const ProtoStruct &extra) override
Returns a stream of digital interrupt ticks.
bool get_gpio(const std::string &pin, const ProtoStruct &extra) override
Gets the high/low state of the given pin on a board.
void set_gpio(const std::string &pin, bool high, const ProtoStruct &extra) override
Set the gpio high/low state of the given pin on a board.
uint64_t get_pwm_frequency(const std::string &pin, const ProtoStruct &extra) override
Gets the PWM frequency of the given pin on a board.
analog_response read_analog(const std::string &analog_reader_name, const ProtoStruct &extra) override
Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board d...
gRPC client implementation for a robot.
A board's digital interrupt.
Definition board.hpp:59
Represents the response received when reading the registered analog to digital converter (ADC)....
Definition board.hpp:36