upkie 6.1.0
Open-source wheeled biped robots
Loading...
Searching...
No Matches
upkie::cpp::actuation::Interface Class Referenceabstract

Base class for actuation interfaces. More...

#include <Interface.h>

Public Member Functions

 Interface ()
 Initialize actuation interface for a given servo layout.
 
virtual ~Interface ()=default
 Virtual destructor so that derived destructors are called properly.
 
virtual void cycle (std::function< void(const moteus::Output &)> callback)=0
 Spin a new communication cycle. More...
 
virtual void reset (const Dictionary &config)=0
 Reset interface. More...
 
virtual void observe (Dictionary &observation) const =0
 Write servo and IMU observations to dictionary. More...
 
const ServoLayoutservo_layout () const noexcept
 Get servo layout.
 
const std::map< int, int > & servo_bus_map () const noexcept
 Map from servo ID to the CAN bus the servo is connected to.
 
const std::map< int, std::string > & servo_name_map () const noexcept
 Map from servo ID to joint name.
 
std::vector< moteus::ServoCommand > & commands ()
 Get servo commands.
 
const std::vector< moteus::ServoReply > & replies () const
 Get servo replies.
 
moteus::Data & data ()
 Get joint command-reply data. More...
 
void reset_action (Dictionary &action)
 Reset action dictionary to the default action. More...
 
virtual void process_action (const Dictionary &action)=0
 Process a new action dictionary. More...
 
void write_position_commands (const Dictionary &action)
 Write position commands from an action dictionary. More...
 
void write_stop_commands () noexcept
 Stop all servos. More...
 
void observe_imu (Dictionary &observation) const
 Observe IMU measurements. More...
 

Protected Attributes

moteus::Data data_
 Pointers to the memory shared with the CAN thread. More...
 
ImuData imu_data_
 IMU data.
 

Detailed Description

Base class for actuation interfaces.

Member Function Documentation

◆ cycle()

virtual void upkie::cpp::actuation::Interface::cycle ( std::function< void(const moteus::Output &)>  callback)
pure virtual

Spin a new communication cycle.

Parameters
callbackFunction to call when the cycle is over.

The callback will be invoked from an arbitrary thread when the communication cycle has completed. All memory pointed to by data must remain valid until the callback is invoked.

Implemented in upkie::cpp::actuation::BulletInterface, upkie::cpp::actuation::MockInterface, and upkie::cpp::actuation::Pi3HatInterface.

◆ data()

moteus::Data & upkie::cpp::actuation::Interface::data ( )
inline

Get joint command-reply data.

This field is meant to become internal when we refactor spine servo observations into actuation interfaces.

◆ observe()

virtual void upkie::cpp::actuation::Interface::observe ( Dictionary &  observation) const
pure virtual

Write servo and IMU observations to dictionary.

Parameters
[out]observationDictionary to write to.

Implemented in upkie::cpp::actuation::BulletInterface, upkie::cpp::actuation::MockInterface, and upkie::cpp::actuation::Pi3HatInterface.

◆ observe_imu()

void upkie::cpp::actuation::Interface::observe_imu ( Dictionary &  observation) const
inline

Observe IMU measurements.

Parameters
[out]observationDictionary to write observations to.

◆ process_action()

virtual void upkie::cpp::actuation::Interface::process_action ( const Dictionary &  action)
pure virtual

Process a new action dictionary.

Parameters
[in]actionAction to read commands from.

Implemented in upkie::cpp::actuation::BulletInterface, upkie::cpp::actuation::MockInterface, and upkie::cpp::actuation::Pi3HatInterface.

◆ reset()

virtual void upkie::cpp::actuation::Interface::reset ( const Dictionary &  config)
pure virtual

Reset interface.

Parameters
[in]configNew configuration dictionary.

Implemented in upkie::cpp::actuation::BulletInterface, upkie::cpp::actuation::MockInterface, and upkie::cpp::actuation::Pi3HatInterface.

◆ reset_action()

void upkie::cpp::actuation::Interface::reset_action ( Dictionary &  action)

Reset action dictionary to the default action.

Parameters
[out]actionAction dictionary.

◆ write_position_commands()

void upkie::cpp::actuation::Interface::write_position_commands ( const Dictionary &  action)

Write position commands from an action dictionary.

Parameters
[in]actionAction to read commands from.
Exceptions
PositionCommandErrorIf any position command is incorrect.

◆ write_stop_commands()

void upkie::cpp::actuation::Interface::write_stop_commands ( )
inlinenoexcept

Stop all servos.

This function does not and should not throw, as it will be called by default if any exception is caught from the spine control loop.

Member Data Documentation

◆ data_

moteus::Data upkie::cpp::actuation::Interface::data_
protected

Pointers to the memory shared with the CAN thread.

This memory consists of commands and replies. It is, by definition, not thread-safe.


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