Viam C++ SDK current
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
viam::sdk::Board Class Referenceabstract

Represents a physical board with gpio pins, digital interrupts, and analog voltage reading. More...

#include "components/board.hpp"

+ Inheritance diagram for viam::sdk::Board:

Classes

struct  analog_response
 Represents the response received when reading 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, though the min and max voltages and step_size can often help with this conversion. Consult your ADC's documentation and Viam's Board documentation for more details. More...
 
struct  status
 This contains all of the values for all of the registered analog readers and digital interrupts that have been registered on the board. More...
 
struct  Tick
 

Public Types

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

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.
 
virtual bool get_gpio (const std::string &pin, const AttributeMap &extra)=0
 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.
 
virtual void set_gpio (const std::string &pin, bool high, const AttributeMap &extra)=0
 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.
 
virtual double get_pwm_duty_cycle (const std::string &pin, const AttributeMap &extra)=0
 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.
 
virtual void set_pwm_duty_cycle (const std::string &pin, double duty_cycle_pct, const AttributeMap &extra)=0
 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.
 
virtual uint64_t get_pwm_frequency (const std::string &pin, const AttributeMap &extra)=0
 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.
 
virtual void set_pwm_frequency (const std::string &pin, uint64_t frequency_hz, const AttributeMap &extra)=0
 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.
 
virtual analog_response read_analog (const std::string &analog_reader_name, const AttributeMap &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.
 
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 AttributeMap &extra)=0
 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.
 
virtual digital_value read_digital_interrupt (const std::string &digital_interrupt_name, const AttributeMap &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 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 AttributeMap &extra)=0
 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.
 
virtual void set_power_mode (power_mode power_mode, const AttributeMap &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.
 
virtual AttributeMap do_command (const AttributeMap &command)=0
 Send/receive arbitrary commands to the resource.
 
std::vector< GeometryConfigget_geometries ()
 Returns GeometryConfigs associated with the calling board.
 
virtual std::vector< GeometryConfigget_geometries (const AttributeMap &extra)=0
 Returns GeometryConfigs associated with the calling board.
 
- Public Member Functions inherited from viam::sdk::Component
viam::common::v1::ResourceName get_resource_name (std::string name) const override
 Returns a ResourceName for a particular resource name.
 
- Public Member Functions inherited from viam::sdk::Resource
 Resource (std::string name)
 
virtual std::string name () const
 Return the resource's name.
 

Static Public Member Functions

static status from_proto (const viam::component::board::v1::Status &proto)
 Creates a status struct from its proto representation.
 
static power_mode from_proto (viam::component::board::v1::PowerMode proto)
 Creates a power_mode enum from its proto representation.
 
static viam::component::board::v1::Status to_proto (const status &status)
 Converts a status struct to its proto representation.
 
static viam::component::board::v1::PowerMode to_proto (power_mode power_mode)
 Converts a power_mode enum to its proto representation.
 

Protected Member Functions

 Board (std::string name)
 
- Protected Member Functions inherited from viam::sdk::Component
 Component (std::string name)
 

Detailed Description

Represents a physical board with gpio pins, digital interrupts, and analog voltage reading.

This acts as an abstract base class to be inherited from by any drivers representing specific board implementations. This class cannot be used on its own.

Member Function Documentation

◆ api()

API viam::sdk::Board::api ( ) const
overridevirtual

Returns the API associated with a particular resource.

Implements viam::sdk::Resource.

◆ do_command()

virtual AttributeMap viam::sdk::Board::do_command ( const AttributeMap & command)
pure virtual

Send/receive arbitrary commands to the resource.

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

Implemented in viam::sdk::impl::BoardClient.

◆ get_geometries() [1/2]

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/2]

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

Returns GeometryConfigs associated with the calling board.

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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ get_gpio() [1/2]

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/2]

virtual bool viam::sdk::Board::get_gpio ( const std::string & pin,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ get_pwm_duty_cycle() [1/2]

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/2]

virtual double viam::sdk::Board::get_pwm_duty_cycle ( const std::string & pin,
const AttributeMap & extra )
pure 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)

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ get_pwm_frequency() [1/2]

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/2]

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

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

Parameters
pinboard pin name
extraAny additional arguments to the method

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ read_analog() [1/2]

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/2]

virtual analog_response viam::sdk::Board::read_analog ( const std::string & analog_reader_name,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ read_digital_interrupt() [1/2]

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/2]

virtual digital_value viam::sdk::Board::read_digital_interrupt ( const std::string & digital_interrupt_name,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ set_gpio() [1/2]

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/2]

virtual void viam::sdk::Board::set_gpio ( const std::string & pin,
bool high,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ set_power_mode() [1/2]

virtual void viam::sdk::Board::set_power_mode ( power_mode power_mode,
const AttributeMap & extra,
const boost::optional< std::chrono::microseconds > & duration = {} )
pure 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)

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ set_power_mode() [2/2]

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_pwm_duty_cycle() [1/2]

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/2]

virtual void viam::sdk::Board::set_pwm_duty_cycle ( const std::string & pin,
double duty_cycle_pct,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ set_pwm_frequency() [1/2]

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/2]

virtual void viam::sdk::Board::set_pwm_frequency ( const std::string & pin,
uint64_t frequency_hz,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ stream_ticks() [1/2]

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/2]

virtual void viam::sdk::Board::stream_ticks ( std::vector< std::string > const & digital_interrupt_names,
std::function< bool(Tick &&tick)> const & tick_handler,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.

◆ write_analog() [1/2]

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/2]

virtual void viam::sdk::Board::write_analog ( const std::string & pin,
int value,
const AttributeMap & extra )
pure 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

Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.


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