AUTh-ARL Core Stack  0.7
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arl::robot::Controller Class Referenceabstract

An abstract class which implements a robot controller. More...

#include <controller.h>

Inheritance diagram for arl::robot::Controller:
Collaboration diagram for arl::robot::Controller:

Public Types

enum  Timing { FIXED, DYNAMIC }
 

Public Member Functions

 Controller (std::shared_ptr< Robot > r, const std::string &name, Timing timing=FIXED)
 Constructor which initializes the robot controller. More...
 
 ~Controller ()
 
bool run ()
 The main function that runs the controller. More...
 
bool runRT ()
 Runs the controller with real time priority. More...
 
void setExternalStop (bool arg)
 Sets an external stop to the controller. Another external thread can use this function to stop the controller. More...
 
std::string getName ()
 Returns the name of the controller. More...
 
double getTime () const
 Returns the current time since the start of the controller in seconds. More...
 
virtual void enableLogging (const std::string &log_path="/home/user/autharl_logfiles/")
 Enables the logging by opening files for log benchmarking times and data. More...
 
virtual void reference (const arma::mat &ref)
 

Protected Member Functions

virtual void init ()
 Initializes the controller. More...
 
virtual bool stop ()
 Implements the stopping condition of your controller. More...
 
virtual bool success ()
 Implements the success condition of your controller. More...
 
virtual void measure ()
 Measures the desired data. More...
 
virtual void command ()
 Commands the robot. More...
 
virtual void update ()=0
 Performs the necessary calculations of the controller. More...
 
virtual void waitNextCycle ()
 Sets a new reference for the controller. More...
 

Protected Attributes

std::string name
 The name of the controller. More...
 
bool external_stop
 The external stopped setted by Controller::setExternalStop() More...
 
std::shared_ptr< Robotrobot
 The pointer to the robot to be controlled. More...
 
double t
 The current time t, with t = 0 when the controller is created. Alternatively the user can initialize time durint the init() function of its derived controller. More...
 
double dt
 The cycle time of the control loop, obtained by the robot. More...
 
bool stop_flag_
 
utils::Timer timer
 Used for measuring the current time of the controller. More...
 
utils::Timer benchmark_total_timer_
 
utils::Timer benchmark_timer_
 
io::Logger benchmark_logger_
 
io::Logger logger_
 
Timing timing_
 

Detailed Description

An abstract class which implements a robot controller.

This class defines an interface for implementing a robot controller. You can create your own robot controller by inherit this class and implement the different functionalities like:

  • How the controller is initializing. For example, the controller before it starts it may need to send the robot to an initial configuration
  • What measurements your controller needs. For example, reading the joint positions, or the joint torques of the robot.
  • The most important part: the calculations that your controller performs in order to produce commands from the measurements.
  • What commands your controller send to the robot. For example, sending calculates and sends task velocities or joint torques.
  • What is the stopping policy of your controller. For example, it stops when your robot stops moving or a high dangerous external force is detected.
  • When your controller is successful.

Member Enumeration Documentation

Enumerator
FIXED 
DYNAMIC 

Constructor & Destructor Documentation

arl::robot::Controller::Controller ( std::shared_ptr< Robot r,
const std::string &  name,
Timing  timing = FIXED 
)
explicit

Constructor which initializes the robot controller.

Parameters
rA pointer to the robot to be controlled.
nameThe name of your controller.
arl::robot::Controller::~Controller ( )

Member Function Documentation

void arl::robot::Controller::command ( )
protectedvirtual

Commands the robot.

Implemented according to your controller needs. Basically makes calls to functions of the Robot class, like sending new desired joint torques or joint positions. These desired signals can be stored in internal variables and should have been calculated based on the measurements of the Controller::measure() and the calculations of the Controller::update()

Reimplemented in arl::viz::RosStatePublisher, arl::controller::GravityCompensation, arl::controller::JointTrajectory, arl::controller::CartesianAdmittance, arl::controller::CartesianImpedance, arl::controller::Clik, and arl::bhand::controller::JointAdmittance.

void arl::robot::Controller::enableLogging ( const std::string &  log_path = "/home/user/autharl_logfiles/")
virtual

Enables the logging by opening files for log benchmarking times and data.

Parameters
log_pathThe path for the files to store.
Exceptions
Exceptionif the files cannot be opened (the directory is not exists)

Reimplemented in arl::controller::Clik.

Here is the call graph for this function:

std::string arl::robot::Controller::getName ( )

Returns the name of the controller.

Returns
The name of the controller
double arl::robot::Controller::getTime ( ) const

Returns the current time since the start of the controller in seconds.

Returns
The current time in seconds
void arl::robot::Controller::init ( )
protectedvirtual

Initializes the controller.

Implemented according to your controller needs. Common use cases involve sending a the robot in an initial configuration, setting the robot mode (to position or torque control) or setting the paramters and gains of your controller.

Reimplemented in arl::controller::GravityCompensation, arl::controller::JointTrajectory, arl::controller::CartesianAdmittance, arl::controller::CartesianImpedance, arl::controller::Clik, and arl::bhand::controller::JointAdmittance.

Here is the call graph for this function:

void arl::robot::Controller::measure ( )
protectedvirtual

Measures the desired data.

Implemented according to your controller needs. Basically makes calls to functions of the Robot class and store them to internal variables, like the joint positions of the robot, the task pose of a robotic arm etc.

Reimplemented in arl::viz::RosStatePublisher, arl::controller::CartesianAdmittance, arl::controller::CartesianImpedance, arl::controller::Clik, and arl::bhand::controller::JointAdmittance.

void arl::robot::Controller::reference ( const arma::mat &  ref)
virtual
bool arl::robot::Controller::run ( )

The main function that runs the controller.

This function is the main thread of the controller. What is basically do is that first initializes the controller by calling the Controller::init() and then runs the control loop which stops if the Controller::stop() returns true. In each loop the function measures by calling Controller::measure(), perform calculations by calling Controller::update(), commands the robot by calling Controller::command() and finally waits for the next cycle of the given robot by calling Robot::waitNextCycle(). After the loop ends it will return the result of the Controller::success().

Returns
True if the controller is successful. False otherwise.

Here is the call graph for this function:

bool arl::robot::Controller::runRT ( )

Runs the controller with real time priority.

It actually runs arl::robot::Controller::run() in a seperate thread with RT priority (99).

Returns
True if the controller is successful. False otherwise.

Here is the call graph for this function:

void arl::robot::Controller::setExternalStop ( bool  arg)

Sets an external stop to the controller. Another external thread can use this function to stop the controller.

Parameters
argSet True to stop the controller.
bool arl::robot::Controller::stop ( )
protectedvirtual

Implements the stopping condition of your controller.

Implemented according to your controller needs. Common use cases involve stopping conditions like your robot has zero velocity, the robot hardware signals an error or dangerous movements indicates the immediate stop.

Returns
True if the controller should stop. False otherwise.

Reimplemented in arl::viz::RosStatePublisher, arl::controller::GravityCompensation, arl::controller::JointTrajectory, arl::controller::CartesianAdmittance, arl::controller::CartesianImpedance, and arl::controller::Clik.

bool arl::robot::Controller::success ( )
protectedvirtual

Implements the success condition of your controller.

Implemented according to your controller needs. Did your controller deliver the task appropriantly?

Returns
True if the controller succeded. False otherwise.
virtual void arl::robot::Controller::update ( )
protectedpure virtual

Performs the necessary calculations of the controller.

Implemented according to your controller needs. The calculations can use the measurements from the Controller::measure() which is stored in internal variables and store the results for the Controller::command() to use.

Implemented in arl::viz::RosStatePublisher, arl::controller::GravityCompensation, arl::controller::JointTrajectory, arl::controller::CartesianAdmittance, arl::controller::CartesianImpedance, arl::controller::Clik, and arl::bhand::controller::JointAdmittance.

void arl::robot::Controller::waitNextCycle ( )
protectedvirtual

Sets a new reference for the controller.

Implemented according to your controller needs. The data has the form of an armadillo matrix which can contain any reference signal.

Parameters
refThe data reference in the form of a matrix

Reimplemented in arl::viz::RosStatePublisher.

Member Data Documentation

io::Logger arl::robot::Controller::benchmark_logger_
protected
utils::Timer arl::robot::Controller::benchmark_timer_
protected
utils::Timer arl::robot::Controller::benchmark_total_timer_
protected
double arl::robot::Controller::dt
protected

The cycle time of the control loop, obtained by the robot.

bool arl::robot::Controller::external_stop
protected

The external stopped setted by Controller::setExternalStop()

io::Logger arl::robot::Controller::logger_
protected
std::string arl::robot::Controller::name
protected

The name of the controller.

std::shared_ptr<Robot> arl::robot::Controller::robot
protected

The pointer to the robot to be controlled.

bool arl::robot::Controller::stop_flag_
protected
double arl::robot::Controller::t
protected

The current time t, with t = 0 when the controller is created. Alternatively the user can initialize time durint the init() function of its derived controller.

utils::Timer arl::robot::Controller::timer
protected

Used for measuring the current time of the controller.

Timing arl::robot::Controller::timing_
protected