Modulo 5.0.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
modulo_controllers::ControllerInterface Class Referenceabstract
Inheritance diagram for modulo_controllers::ControllerInterface:
modulo_controllers::BaseControllerInterface modulo_controllers::RobotControllerInterface

Public Member Functions

 ControllerInterface (bool claim_all_state_interfaces=false)
 Default constructor.
 
CallbackReturn on_init () override
 Declare parameters.
 
CallbackReturn on_configure (const rclcpp_lifecycle::State &previous_state) final
 Set class properties from parameters.
 
CallbackReturn on_activate (const rclcpp_lifecycle::State &previous_state) final
 Initialize internal data attributes from configured interfaces and wait for valid states from hardware.
 
CallbackReturn on_deactivate (const rclcpp_lifecycle::State &previous_state) final
 Deactivate the controller.
 
controller_interface::return_type update (const rclcpp::Time &time, const rclcpp::Duration &period) final
 Read the state interfaces, perform control evaluation and write the command interfaces.
 
controller_interface::InterfaceConfiguration state_interface_configuration () const final
 Configure the state interfaces.
 
controller_interface::InterfaceConfiguration command_interface_configuration () const final
 Configure the command interfaces.
 
- Public Member Functions inherited from modulo_controllers::BaseControllerInterface
 BaseControllerInterface ()
 Default constructor.
 
CallbackReturn on_init () override
 Declare parameters and register the on_set_parameters callback.
 
CallbackReturn on_configure (const rclcpp_lifecycle::State &previous_state) override
 Add signals.
 
template<>
void write_output (const std::string &name, const bool &data)
 
template<>
void write_output (const std::string &name, const double &data)
 
template<>
void write_output (const std::string &name, const std::vector< double > &data)
 
template<>
void write_output (const std::string &name, const int &data)
 
template<>
void write_output (const std::string &name, const std::string &data)
 

Protected Member Functions

virtual CallbackReturn add_interfaces ()
 Add interfaces like parameters, signals, services, and predicates to the controller.
 
virtual CallbackReturn on_configure ()
 Configure the controller.
 
virtual CallbackReturn on_activate ()
 Activate the controller.
 
virtual CallbackReturn on_deactivate ()
 Deactivate the controller.
 
virtual controller_interface::return_type read_state_interfaces ()
 Read the state interfaces.
 
virtual controller_interface::return_type write_command_interfaces (const rclcpp::Duration &period)
 Write the command interfaces.
 
virtual controller_interface::return_type evaluate (const rclcpp::Time &time, const std::chrono::nanoseconds &period)=0
 The control logic callback.
 
void add_state_interface (const std::string &name, const std::string &interface)
 Add a state interface to the controller by name.
 
void add_command_interface (const std::string &name, const std::string &interface)
 Add a command interface to the controller by name.
 
std::unordered_map< std::string, doubleget_state_interfaces (const std::string &name) const
 Get a map containing the state interfaces by name of the parent tag.
 
double get_state_interface (const std::string &name, const std::string &interface) const
 Get the value of a state interface by name.
 
double get_command_interface (const std::string &name, const std::string &interface) const
 Get the value of a command interface by name.
 
void set_command_interface (const std::string &name, const std::string &interface, double value)
 Set the value of a command interface by name.
 
- Protected Member Functions inherited from modulo_controllers::BaseControllerInterface
void add_parameter (const std::shared_ptr< state_representation::ParameterInterface > &parameter, const std::string &description, bool read_only=false)
 Add a parameter.
 
template<typename T >
void add_parameter (const std::string &name, const T &value, const std::string &description, bool read_only=false)
 Add a parameter.
 
virtual bool on_validate_parameter_callback (const std::shared_ptr< state_representation::ParameterInterface > &parameter)
 Parameter validation function to be redefined by derived controller classes.
 
std::shared_ptr< state_representation::ParameterInterface > get_parameter (const std::string &name) const
 Get a parameter by name.
 
template<typename T >
get_parameter_value (const std::string &name) const
 Get a parameter value by name.
 
template<typename T >
void set_parameter_value (const std::string &name, const T &value)
 Set the value of a parameter.
 
void add_predicate (const std::string &predicate_name, bool predicate_value)
 Add a predicate to the map of predicates.
 
void add_predicate (const std::string &predicate_name, const std::function< bool(void)> &predicate_function)
 Add a predicate to the map of predicates based on a function to periodically call.
 
bool get_predicate (const std::string &predicate_name) const
 Get the logical value of a predicate.
 
void set_predicate (const std::string &predicate_name, bool predicate_value)
 Set the value of the predicate given as parameter, if the predicate is not found does not do anything.
 
void set_predicate (const std::string &predicate_name, const std::function< bool(void)> &predicate_function)
 Set the value of the predicate given as parameter, if the predicate is not found does not do anything.
 
void add_trigger (const std::string &trigger_name)
 Add a trigger to the controller.
 
void trigger (const std::string &trigger_name)
 Latch the trigger with the provided name.
 
template<typename T >
void add_input (const std::string &name, const std::string &topic_name="")
 Add an input to the controller.
 
template<typename T >
void add_output (const std::string &name, const std::string &topic_name="")
 Add an output to the controller.
 
void set_input_validity_period (double input_validity_period)
 Set the input validity period of input signals.
 
template<typename T >
std::optional< Tread_input (const std::string &name)
 Read the most recent message of an input.
 
template<typename T >
void write_output (const std::string &name, const T &data)
 Write an object to an output.
 
void add_service (const std::string &service_name, const std::function< ControllerServiceResponse(void)> &callback)
 Add a service to trigger a callback function with no input arguments.
 
void add_service (const std::string &service_name, const std::function< ControllerServiceResponse(const std::string &string)> &callback)
 Add a service to trigger a callback function with a string payload.
 
rclcpp::QoS get_qos () const
 Getter of the Quality of Service attribute.
 
void set_qos (const rclcpp::QoS &qos)
 Set the Quality of Service for ROS publishers and subscribers.
 
bool is_active () const
 Check if the controller is currently in state active or not.
 
std::timed_mutex & get_command_mutex ()
 Get the reference to the command mutex.
 
template<>
void add_input (const std::string &name, const std::string &topic_name)
 
template<>
void add_input (const std::string &name, const std::string &topic_name)
 
template<>
void add_input (const std::string &name, const std::string &topic_name)
 
template<>
void add_output (const std::string &name, const std::string &topic_name)
 
template<>
void add_output (const std::string &name, const std::string &topic_name)
 
template<>
void add_output (const std::string &name, const std::string &topic_name)
 
template<>
std::optional< boolread_input (const std::string &name)
 
template<>
std::optional< doubleread_input (const std::string &name)
 
template<>
std::optional< intread_input (const std::string &name)
 

Protected Attributes

std::string hardware_name_
 The hardware name provided by a parameter.
 

Detailed Description

Definition at line 10 of file ControllerInterface.hpp.

Constructor & Destructor Documentation

◆ ControllerInterface()

modulo_controllers::ControllerInterface::ControllerInterface ( bool  claim_all_state_interfaces = false)

Default constructor.

Parameters
claim_all_state_interfacesFlag to indicate if all state interfaces should be claimed

Definition at line 9 of file ControllerInterface.cpp.

Member Function Documentation

◆ add_command_interface()

void modulo_controllers::ControllerInterface::add_command_interface ( const std::string &  name,
const std::string &  interface 
)
protected

Add a command interface to the controller by name.

Parameters
nameThe name of the parent tag, e.g. the name of the joint, sensor or gpio
interfaceThe desired command interface

Definition at line 84 of file ControllerInterface.cpp.

◆ add_interfaces()

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::add_interfaces ( )
protectedvirtual

Add interfaces like parameters, signals, services, and predicates to the controller.

This function is called during the on_init callback of the base class to perform post-construction steps.

Returns
SUCCESS or ERROR

Reimplemented in modulo_controllers::RobotControllerInterface.

Definition at line 39 of file ControllerInterface.cpp.

◆ add_state_interface()

void modulo_controllers::ControllerInterface::add_state_interface ( const std::string &  name,
const std::string &  interface 
)
protected

Add a state interface to the controller by name.

Parameters
nameThe name of the parent tag, e.g. the name of the joint, sensor or gpio
interfaceThe desired state interface

Definition at line 80 of file ControllerInterface.cpp.

◆ command_interface_configuration()

controller_interface::InterfaceConfiguration modulo_controllers::ControllerInterface::command_interface_configuration ( ) const
final

Configure the command interfaces.

Returns
The command interface configuration

Definition at line 106 of file ControllerInterface.cpp.

◆ evaluate()

virtual controller_interface::return_type modulo_controllers::ControllerInterface::evaluate ( const rclcpp::Time &  time,
const std::chrono::nanoseconds &  period 
)
protectedpure virtual

The control logic callback.

This method should be overridden by derived classes. It is called in the update() method between reading the state interfaces and writing the command interfaces.

Parameters
timeThe controller clock time
periodTime elapsed since the last control evaluation
Returns
OK or ERROR

◆ get_command_interface()

double modulo_controllers::ControllerInterface::get_command_interface ( const std::string &  name,
const std::string &  interface 
) const
protected

Get the value of a command interface by name.

Parameters
nameThe name of the parent tag, e.g. the name of the joint, sensor or gpio
interfaceThe desired command interface
Exceptions
out_of_rangeif the desired command interface is not available
Returns
The value of the command interface

Definition at line 278 of file ControllerInterface.cpp.

◆ get_state_interface()

double modulo_controllers::ControllerInterface::get_state_interface ( const std::string &  name,
const std::string &  interface 
) const
protected

Get the value of a state interface by name.

Parameters
nameThe name of the parent tag, e.g. the name of the joint, sensor or gpio
interfaceThe desired state interface
Exceptions
out_of_rangeif the desired state interface is not available
Returns
The value of the state interface

Definition at line 274 of file ControllerInterface.cpp.

◆ get_state_interfaces()

std::unordered_map< std::string, double > modulo_controllers::ControllerInterface::get_state_interfaces ( const std::string &  name) const
protected

Get a map containing the state interfaces by name of the parent tag.

Parameters
nameThe name of the parent tag, e.g. the name of the joint, sensor or gpio
Exceptions
out_of_rangeif the desired state interface is not available
Returns
The map containing the values of the state interfaces

Definition at line 270 of file ControllerInterface.cpp.

◆ on_activate() [1/2]

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_activate ( )
protectedvirtual

Activate the controller.

This method should be overridden by derived classes.

Returns
SUCCESS or ERROR

Reimplemented in modulo_controllers::RobotControllerInterface.

Definition at line 194 of file ControllerInterface.cpp.

◆ on_activate() [2/2]

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_activate ( const rclcpp_lifecycle::State &  previous_state)
final

Initialize internal data attributes from configured interfaces and wait for valid states from hardware.

This functions calls the internal on_activate() method

Parameters
previous_stateThe previous lifecycle state
Returns
SUCCESS or ERROR

Definition at line 141 of file ControllerInterface.cpp.

◆ on_configure() [1/2]

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_configure ( )
protectedvirtual

Configure the controller.

This method should be overridden by derived classes.

Returns
SUCCESS or ERROR

Reimplemented in modulo_controllers::RobotControllerInterface.

Definition at line 76 of file ControllerInterface.cpp.

◆ on_configure() [2/2]

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_configure ( const rclcpp_lifecycle::State &  previous_state)
final

Set class properties from parameters.

This functions calls the internal on_configure() method

Parameters
previous_stateThe previous lifecycle state
Returns
SUCCESS or ERROR

Definition at line 44 of file ControllerInterface.cpp.

◆ on_deactivate() [1/2]

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_deactivate ( )
protectedvirtual

Deactivate the controller.

This method should be overridden by derived classes.

Returns
SUCCESS or ERROR

Definition at line 208 of file ControllerInterface.cpp.

◆ on_deactivate() [2/2]

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_deactivate ( const rclcpp_lifecycle::State &  previous_state)
final

Deactivate the controller.

Parameters
previous_stateThe previous lifecycle state
Returns
SUCCESS or ERROR

Definition at line 199 of file ControllerInterface.cpp.

◆ on_init()

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn modulo_controllers::ControllerInterface::on_init ( )
override

Declare parameters.

Returns
CallbackReturn status

Definition at line 12 of file ControllerInterface.cpp.

◆ read_state_interfaces()

controller_interface::return_type modulo_controllers::ControllerInterface::read_state_interfaces ( )
protectedvirtual

Read the state interfaces.

Returns
OK or ERROR

Definition at line 253 of file ControllerInterface.cpp.

◆ set_command_interface()

void modulo_controllers::ControllerInterface::set_command_interface ( const std::string &  name,
const std::string &  interface,
double  value 
)
protected

Set the value of a command interface by name.

Parameters
nameThe name of the parent tag, e.g. the name of the sensor or gpio
interfaceThe name of the command interface
valueThe new value of the interface

Definition at line 282 of file ControllerInterface.cpp.

◆ state_interface_configuration()

controller_interface::InterfaceConfiguration modulo_controllers::ControllerInterface::state_interface_configuration ( ) const
final

Configure the state interfaces.

Returns
The state interface configuration

Definition at line 123 of file ControllerInterface.cpp.

◆ update()

controller_interface::return_type modulo_controllers::ControllerInterface::update ( const rclcpp::Time &  time,
const rclcpp::Duration &  period 
)
final

Read the state interfaces, perform control evaluation and write the command interfaces.

Parameters
timeThe controller clock time
periodTime elapsed since the last control evaluation
Returns
OK or ERROR

Definition at line 213 of file ControllerInterface.cpp.

◆ write_command_interfaces()

controller_interface::return_type modulo_controllers::ControllerInterface::write_command_interfaces ( const rclcpp::Duration &  period)
protectedvirtual

Write the command interfaces.

Parameters
periodTime elapsed since the last control evaluation
Returns
OK or ERROR

Definition at line 262 of file ControllerInterface.cpp.

Member Data Documentation

◆ hardware_name_

std::string modulo_controllers::ControllerInterface::hardware_name_
protected

The hardware name provided by a parameter.

Definition at line 169 of file ControllerInterface.hpp.


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