Viam C++ SDK current
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
viam::sdk::impl::BoardClient Class Reference

gRPC client implementation of a Board component. More...

#include <board_client.hpp>

+ Inheritance diagram for viam::sdk::impl::BoardClient:

Public Types

using interface_type = Board
 
- Public Types inherited from viam::sdk::Board
enum class  power_mode : uint8_t { normal = 0 , offline_deep = 1 }
 Power mode of the board The effect of these power modes depends on your physical board.
 
using analog_value = int32_t
 Represents the raw value received by the registered analog to digital converter (ADC). The range and conversion mechanism to voltage will vary depending on the specific ADC registered to the pin.
 
using digital_value = int64_t
 Depending on the type of digital interrupt, this can have different meanings. If a basic (default) interrupt is configured, then this is the total interrupt count. If a servo interrupt is configured this tracks the pulse width value. Consult Viam's Board documentation for more details.
 

Public Member Functions

 BoardClient (std::string name, std::shared_ptr< grpc::Channel > channel)
 
ProtoStruct do_command (const ProtoStruct &command) override
 Send/receive arbitrary commands to the resource.
 
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.
 
bool get_gpio (const std::string &pin, const ProtoStruct &extra) override
 Gets the high/low state of the given pin on a 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_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.
 
uint64_t get_pwm_frequency (const std::string &pin, const ProtoStruct &extra) override
 Gets the PWM frequency 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 frequency.
 
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 docs for more information.
 
void write_analog (const std::string &pin, int value, const ProtoStruct &extra) override
 Writes the value to the analog writer of the board.
 
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. Consult Viam's Board docs for more information.
 
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.
 
std::vector< GeometryConfigget_geometries (const ProtoStruct &extra) override
 Returns GeometryConfigs associated with the calling board.
 
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.
 
std::vector< GeometryConfigget_geometries ()
 Returns GeometryConfigs associated with the calling board.
 
virtual std::vector< GeometryConfigget_geometries (const ProtoStruct &extra)=0
 Returns GeometryConfigs associated with the calling board.
 
bool get_gpio (const std::string &pin)
 Gets the high/low state of the given pin on a board.
 
virtual bool get_gpio (const std::string &pin, const ProtoStruct &extra)=0
 Gets the high/low state of the given pin on a board.
 
double get_pwm_duty_cycle (const std::string &pin)
 Gets the duty cycle of the given pin on a board.
 
virtual double get_pwm_duty_cycle (const std::string &pin, const ProtoStruct &extra)=0
 Gets the duty cycle of the given pin on a board.
 
uint64_t get_pwm_frequency (const std::string &pin)
 Gets the PWM frequency of the given pin on a board.
 
virtual uint64_t get_pwm_frequency (const std::string &pin, const ProtoStruct &extra)=0
 Gets the PWM frequency of the given pin on a board.
 
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 docs for more information.
 
virtual analog_response read_analog (const std::string &analog_reader_name, const ProtoStruct &extra)=0
 Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board docs for more information.
 
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. Consult Viam's Board docs for more information.
 
virtual digital_value read_digital_interrupt (const std::string &digital_interrupt_name, const ProtoStruct &extra)=0
 Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board docs for more information.
 
void set_gpio (const std::string &pin, bool high)
 Set the gpio high/low state of the given pin on a board.
 
virtual void set_gpio (const std::string &pin, bool high, const ProtoStruct &extra)=0
 Set the gpio high/low state of the given pin on a board.
 
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.
 
virtual void set_power_mode (power_mode power_mode, const ProtoStruct &extra, const boost::optional< std::chrono::microseconds > &duration={})=0
 Sets the power consumption mode of the board to the requested setting for the given duration.
 
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.
 
virtual void set_pwm_duty_cycle (const std::string &pin, double duty_cycle_pct, const ProtoStruct &extra)=0
 Sets the given pin of a board to the given duty cycle.
 
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 frequency.
 
virtual void set_pwm_frequency (const std::string &pin, uint64_t frequency_hz, const ProtoStruct &extra)=0
 Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency.
 
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.
 
virtual void stream_ticks (std::vector< std::string > const &digital_interrupt_names, std::function< bool(Tick &&tick)> const &tick_handler, const ProtoStruct &extra)=0
 Returns a stream of digital interrupt ticks.
 
void write_analog (const std::string &pin, int value)
 Writes the value to the analog writer of the board.
 
virtual void write_analog (const std::string &pin, int value, const ProtoStruct &extra)=0
 Writes the value to the analog writer of the board.
 
- Public Member Functions inherited from viam::sdk::Board
API api () const override
 Returns the API associated with a particular resource.
 
bool get_gpio (const std::string &pin)
 Gets the high/low state of the given pin on a board.
 
void set_gpio (const std::string &pin, bool high)
 Set the gpio high/low state of the given pin on a board.
 
double get_pwm_duty_cycle (const std::string &pin)
 Gets the duty cycle of the given pin on a board.
 
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.
 
uint64_t get_pwm_frequency (const std::string &pin)
 Gets the PWM frequency of the given pin on a board.
 
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 frequency.
 
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 docs for more information.
 
void write_analog (const std::string &pin, int value)
 Writes the value to the analog writer of the board.
 
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. Consult Viam's Board docs for more information.
 
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.
 
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.
 
std::vector< GeometryConfigget_geometries ()
 Returns GeometryConfigs associated with the calling board.
 
- Public Member Functions inherited from viam::sdk::Component
Name get_resource_name () const override
 Returns the Name for a particular resource.
 
- Public Member Functions inherited from viam::sdk::Resource
 Resource (std::string name)
 
virtual std::string name () const
 Return the resource's name.
 

Additional Inherited Members

- Protected Member Functions inherited from viam::sdk::Board
 Board (std::string name)
 
- Protected Member Functions inherited from viam::sdk::Component
 Component (std::string name)
 
- Protected Member Functions inherited from viam::sdk::Resource
Name get_resource_name (const std::string &type) const
 

Detailed Description

gRPC client implementation of a Board component.

Member Function Documentation

◆ do_command()

ProtoStruct viam::sdk::impl::BoardClient::do_command ( const ProtoStruct & command)
overridevirtual

Send/receive arbitrary commands to the resource.

Parameters
Commandthe command to execute.
Returns
The result of the executed command.

Implements viam::sdk::Board.

◆ get_geometries() [1/3]

std::vector< GeometryConfig > viam::sdk::Board::get_geometries ( )
inline

Returns GeometryConfigs associated with the calling board.

Returns
The requested GeometryConfigs associated with the component.

◆ get_geometries() [2/3]

std::vector< GeometryConfig > viam::sdk::impl::BoardClient::get_geometries ( const ProtoStruct & extra)
overridevirtual

Returns GeometryConfigs associated with the calling board.

Parameters
extraAny additional arguments to the method.
Returns
The requested GeometryConfigs associated with the component.

Implements viam::sdk::Board.

◆ get_geometries() [3/3]

virtual std::vector< GeometryConfig > viam::sdk::Board::get_geometries ( const ProtoStruct & extra)
virtual

Returns GeometryConfigs associated with the calling board.

Parameters
extraAny additional arguments to the method.
Returns
The requested GeometryConfigs associated with the component.

Implements viam::sdk::Board.

◆ get_gpio() [1/3]

bool viam::sdk::Board::get_gpio ( const std::string & pin)
inline

Gets the high/low state of the given pin on a board.

Parameters
pinboard pin name
Returns
high/low state of the given pin. High = on, low = off

◆ get_gpio() [2/3]

bool viam::sdk::impl::BoardClient::get_gpio ( const std::string & pin,
const ProtoStruct & extra )
overridevirtual

Gets the high/low state of the given pin on a board.

Parameters
pinboard pin name
extraAny additional arguments to the method
Returns
high/low state of the given pin. High = on, low = off

Implements viam::sdk::Board.

◆ get_gpio() [3/3]

virtual bool viam::sdk::Board::get_gpio ( const std::string & pin,
const ProtoStruct & extra )
virtual

Gets the high/low state of the given pin on a board.

Parameters
pinboard pin name
extraAny additional arguments to the method
Returns
high/low state of the given pin. High = on, low = off

Implements viam::sdk::Board.

◆ get_pwm_duty_cycle() [1/3]

double viam::sdk::Board::get_pwm_duty_cycle ( const std::string & pin)
inline

Gets the duty cycle of the given pin on a board.

Parameters
pinboard pin name
Returns
duty cycle percentage (0 to 1)

◆ get_pwm_duty_cycle() [2/3]

double viam::sdk::impl::BoardClient::get_pwm_duty_cycle ( const std::string & pin,
const ProtoStruct & extra )
overridevirtual

Gets the duty cycle of the given pin on a board.

Parameters
pinboard pin name
extraAny additional arguments to the method
Returns
duty cycle percentage (0 to 1)

Implements viam::sdk::Board.

◆ get_pwm_duty_cycle() [3/3]

virtual double viam::sdk::Board::get_pwm_duty_cycle ( const std::string & pin,
const ProtoStruct & extra )
virtual

Gets the duty cycle of the given pin on a board.

Parameters
pinboard pin name
extraAny additional arguments to the method
Returns
duty cycle percentage (0 to 1)

Implements viam::sdk::Board.

◆ get_pwm_frequency() [1/3]

uint64_t viam::sdk::Board::get_pwm_frequency ( const std::string & pin)
inline

Gets the PWM frequency of the given pin on a board.

Parameters
pinboard pin name

◆ get_pwm_frequency() [2/3]

uint64_t viam::sdk::impl::BoardClient::get_pwm_frequency ( const std::string & pin,
const ProtoStruct & extra )
overridevirtual

Gets the PWM frequency of the given pin on a board.

Parameters
pinboard pin name
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ get_pwm_frequency() [3/3]

virtual uint64_t viam::sdk::Board::get_pwm_frequency ( const std::string & pin,
const ProtoStruct & extra )
virtual

Gets the PWM frequency of the given pin on a board.

Parameters
pinboard pin name
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ read_analog() [1/3]

analog_response viam::sdk::Board::read_analog ( const std::string & analog_reader_name)
inline

Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board docs for more information.

Parameters
analog_reader_nameanalog reader to read from

◆ read_analog() [2/3]

analog_response viam::sdk::impl::BoardClient::read_analog ( const std::string & analog_reader_name,
const ProtoStruct & extra )
overridevirtual

Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board docs for more information.

Parameters
analog_reader_nameanalog reader to read from
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ read_analog() [3/3]

virtual analog_response viam::sdk::Board::read_analog ( const std::string & analog_reader_name,
const ProtoStruct & extra )
virtual

Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board docs for more information.

Parameters
analog_reader_nameanalog reader to read from
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ read_digital_interrupt() [1/3]

digital_value viam::sdk::Board::read_digital_interrupt ( const std::string & digital_interrupt_name)
inline

Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board docs for more information.

Parameters
digital_interrupt_namedigital interrupt to check

◆ read_digital_interrupt() [2/3]

digital_value viam::sdk::impl::BoardClient::read_digital_interrupt ( const std::string & digital_interrupt_name,
const ProtoStruct & extra )
overridevirtual

Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board docs for more information.

Parameters
digital_interrupt_namedigital interrupt to check
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ read_digital_interrupt() [3/3]

virtual digital_value viam::sdk::Board::read_digital_interrupt ( const std::string & digital_interrupt_name,
const ProtoStruct & extra )
virtual

Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board docs for more information.

Parameters
digital_interrupt_namedigital interrupt to check
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ set_gpio() [1/3]

void viam::sdk::Board::set_gpio ( const std::string & pin,
bool high )
inline

Set the gpio high/low state of the given pin on a board.

Parameters
hightrue if the pin should be set to high (on) or false if it should be low (off)

◆ set_gpio() [2/3]

void viam::sdk::impl::BoardClient::set_gpio ( const std::string & pin,
bool high,
const ProtoStruct & extra )
overridevirtual

Set the gpio high/low state of the given pin on a board.

Parameters
hightrue if the pin should be set to high (on) or false if it should be low (off)
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ set_gpio() [3/3]

virtual void viam::sdk::Board::set_gpio ( const std::string & pin,
bool high,
const ProtoStruct & extra )
virtual

Set the gpio high/low state of the given pin on a board.

Parameters
hightrue if the pin should be set to high (on) or false if it should be low (off)
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ set_power_mode() [1/3]

void viam::sdk::Board::set_power_mode ( power_mode power_mode,
const boost::optional< std::chrono::microseconds > & duration = {} )
inline

Sets the power consumption mode of the board to the requested setting for the given duration.

Parameters
power_modeRequested power mode
durationRequested duration to stay in power_mode (in microseconds)

◆ set_power_mode() [2/3]

void viam::sdk::impl::BoardClient::set_power_mode ( power_mode power_mode,
const ProtoStruct & extra,
const boost::optional< std::chrono::microseconds > & duration )
overridevirtual

Sets the power consumption mode of the board to the requested setting for the given duration.

Parameters
power_modeRequested power mode
extraAny additional arguments to the method
durationRequested duration to stay in power_mode (in microseconds)

Implements viam::sdk::Board.

◆ set_power_mode() [3/3]

virtual void viam::sdk::Board::set_power_mode ( power_mode power_mode,
const ProtoStruct & extra,
const boost::optional< std::chrono::microseconds > & duration = {} )
virtual

Sets the power consumption mode of the board to the requested setting for the given duration.

Parameters
power_modeRequested power mode
extraAny additional arguments to the method
durationRequested duration to stay in power_mode (in microseconds)

Implements viam::sdk::Board.

◆ set_pwm_duty_cycle() [1/3]

void viam::sdk::Board::set_pwm_duty_cycle ( const std::string & pin,
double duty_cycle_pct )
inline

Sets the given pin of a board to the given duty cycle.

Parameters
pinboard pin name
duty_cycle_pctduty cycle percentage 0 to 1

◆ set_pwm_duty_cycle() [2/3]

void viam::sdk::impl::BoardClient::set_pwm_duty_cycle ( const std::string & pin,
double duty_cycle_pct,
const ProtoStruct & extra )
overridevirtual

Sets the given pin of a board to the given duty cycle.

Parameters
pinboard pin name
duty_cycle_pctduty cycle percentage 0 to 1
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ set_pwm_duty_cycle() [3/3]

virtual void viam::sdk::Board::set_pwm_duty_cycle ( const std::string & pin,
double duty_cycle_pct,
const ProtoStruct & extra )
virtual

Sets the given pin of a board to the given duty cycle.

Parameters
pinboard pin name
duty_cycle_pctduty cycle percentage 0 to 1
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ set_pwm_frequency() [1/3]

void viam::sdk::Board::set_pwm_frequency ( const std::string & pin,
uint64_t frequency_hz )
inline

Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency.

Parameters
pinboard pin name
frequency_hzfrequency in hz (0 = use board default frequency)

◆ set_pwm_frequency() [2/3]

void viam::sdk::impl::BoardClient::set_pwm_frequency ( const std::string & pin,
uint64_t frequency_hz,
const ProtoStruct & extra )
overridevirtual

Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency.

Parameters
pinboard pin name
frequency_hzfrequency in hz (0 = use board default frequency)
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ set_pwm_frequency() [3/3]

virtual void viam::sdk::Board::set_pwm_frequency ( const std::string & pin,
uint64_t frequency_hz,
const ProtoStruct & extra )
virtual

Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency.

Parameters
pinboard pin name
frequency_hzfrequency in hz (0 = use board default frequency)
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ stream_ticks() [1/3]

void viam::sdk::Board::stream_ticks ( std::vector< std::string > const & digital_interrupt_names,
std::function< bool(Tick &&tick)> const & tick_handler )
inline

Returns a stream of digital interrupt ticks.

Parameters
digital_interrupt_namesdigital interrupts to stream
tick_handlercallback function to call when a tick occurs. This should return true to keep streaming ticks and false to indicate that the stream of ticks should terminate. The callback function should not be blocking.

◆ stream_ticks() [2/3]

void viam::sdk::impl::BoardClient::stream_ticks ( std::vector< std::string > const & digital_interrupt_names,
std::function< bool(Tick &&tick)> const & tick_handler,
const ProtoStruct & extra )
overridevirtual

Returns a stream of digital interrupt ticks.

Parameters
digital_interrupt_namesdigital interrupts to stream
tick_handlercallback function to call when a tick occurs.
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ stream_ticks() [3/3]

virtual void viam::sdk::Board::stream_ticks ( std::vector< std::string > const & digital_interrupt_names,
std::function< bool(Tick &&tick)> const & tick_handler,
const ProtoStruct & extra )
virtual

Returns a stream of digital interrupt ticks.

Parameters
digital_interrupt_namesdigital interrupts to stream
tick_handlercallback function to call when a tick occurs.
extraAny additional arguments to the method

Implements viam::sdk::Board.

◆ write_analog() [1/3]

void viam::sdk::Board::write_analog ( const std::string & pin,
int value )
inline

Writes the value to the analog writer of the board.

Parameters
pinthe pin to write to
valuethe value to set the pin to

◆ write_analog() [2/3]

void viam::sdk::impl::BoardClient::write_analog ( const std::string & pin,
int value,
const ProtoStruct & extra )
overridevirtual

Writes the value to the analog writer of the board.

Parameters
pinthe pin to write to
valuethe value to set the pin to
extraany additional arguments to the method

Implements viam::sdk::Board.

◆ write_analog() [3/3]

virtual void viam::sdk::Board::write_analog ( const std::string & pin,
int value,
const ProtoStruct & extra )
virtual

Writes the value to the analog writer of the board.

Parameters
pinthe pin to write to
valuethe value to set the pin to
extraany additional arguments to the method

Implements viam::sdk::Board.


The documentation for this class was generated from the following file: