Controller

To hand over torque commands to worldHub_, you utilize a controller within the Raisin framework.

In the Raisin system, controllers are dynamically loaded as needed, which can be triggered through the ROS2 service raibo/load_controller. Once loaded, the advance() method of these controllers is called periodically according to a specified frequency set in the config/params.yaml file under the raisin_raibo2 package, with a default rate of 4000 Hz.

if control mode is

  1. PD_PLUS_FEEDFORWARD_TORQUE: robot’s pdtarget, pdgain should be updated.

  2. FORCE_AND_TORQUE: robot’s feedforward torque should be updated.

If a robot’s joint angle or velocity exceeds set limits, the safetyController halts the robot by issuing ZERO_TORQUE or ZERO_VELOCITY commands to ensure safety.

For implementing controllers in Raisin, it’s important to adhere to the naming convention specified. Each controller should be named following the pattern raisin_**_controller, where ** represents a descriptive part of the controller’s functionality.

For practical implementation examples, refer to the raisin_example_controller.zip.

API

class Controller

Controller class to control a robot.

To implement your own controller, inherit this class and implement virtual methods.

worldHub_ holds the robot’s estimated state and environment(including height), which are set by plugins.

Inside worldHub_, robotHub_ offers sensor data access (encoders, cameras, IMUs) and allows for issuing torque commands.

Note: worldSim_ is solely for simulations and must not be used with actual robots.

Estimated world(worldHub_) is visualized in serverHub_ (port 8080), and simulated world(worldSim_) is visualized in serverSim_ (port 7000).

Public Functions

inline explicit Controller(const std::string &name, raisim::World &worldHub, raisim::RaisimServer &serverHub, raisim::World &worldSim, raisim::RaisimServer &serverSim, GlobalResource &globalResource)
Parameters:
  • name – name of the controller

  • world – see worldHub_

  • server – see serverHub_

  • worldSim – see worldSim_

  • serverSim – see serverSim_

  • globalResource – global resources such as paramRoot, dataLogger

virtual bool create() = 0

create controller. this is called only once.

Returns:

true if successful

inline virtual bool init()

initialize controller. this is called only once.

Returns:

true if successful

inline virtual bool advance()

advance controller. This is called regularly by ControllerManager.

if control mode is

1) PD_PLUS_FEEDFORWARD_TORQUE: robot’s pdtarget, pdgain should be updated.

2) FORCE_AND_TORQUE robot’s feedforward torque should be updated.

Returns:

true if successful

inline virtual bool reset()

reset controller

Returns:

true if successful

inline virtual bool terminate()

terminate controller

Returns:

true if successful

inline virtual bool stop()

stop controller

Returns:

true if successful

inline void setPluginManager(plugin::PluginManager *pluginManager)

set pluginManager. This is used only in controllerManager.

Parameters:

pluginManager – pluginManager pointer

inline virtual bool isDone()

returns if the controller finished its work. Only episodic controllers can return true

Returns:

Protected Attributes

raisim::World &worldHub_

The worldHub_ object holds the robot’s estimated state and environment(including height), which are set by plugins.

1) get the estimated environment(addHeightMap…)

2) get the world time (getWolrdTime)

raisim::RaisimServer &serverHub_

This is for visualization of worldHub_ in port 8080. You can add visualObject through this serverHub_.

raisim::ArticulatedSystem *robotHub_

ArticulatedSystem variable that holds the information about the robot. This is member of worldHub_. Through this variable, you can

1) get the robot’s state(getGeneralizedCoordinate, getGeneralizedVelocity…)

2) control it(setPdTarget, setPdGain…)

raisim::ArticulatedSystem *robotSim_

ArticulatedSystem variable that holds the information about the robot in the simulation. This is member of worldSim_. Through this variable, you can

set the estimated robot’s state(setGeneralizedCoordinate, setGeneralizedVelocity…)

get the estimated robot’s state(getGeneralizedCoordinate, getGeneralizedVelocity…)

raisim::World &worldSim_

worldSim_ is solely for simulations and must not be used with actual robots. You can get ground truth information of simulation through worldSim_.

raisim::RaisimServer &serverSim_

This is for visualization of worldSim_, and simulated camera streaming in port 7000. If you want to use camera, make sure to turn on raisimUnreal on port 7000.

raisin::parameter::ParameterContainer &paramRoot_

Use this variable instead of calling parameter::ParameterContainer::getRoot(), which is not valid in dynamic library.

See also

test_raisin_parameter.cpp for example

raisin::DataLogger &dataLogger_

Use this variable instead of calling “raisin::DataLogger raisin::DataLogger::getInstance() = raisin::DataLogger()”, which is not valid in dynamic library.

See also

test_raisin_data_logger.cpp for example

raisin::plugin::PluginManager *pluginManager_

To access plugin from controller, use plugin::PluginManager::getPlugin(const std::string & plugin_name).

size_t logIdx_

Initialize this with DataLogger::initializeAnotherDataGroup.

class ControllerManager

Class to manage Controller.

Only one Controller is used at once.

When load is called, it

1) replaces already loaded controller with new controller

2) calls Controller::advance() of loaded controller regularly.

See Controller, for more details

Public Functions

bool load(const std::string &controller_path)

load controller

Parameters:

controller_path – path to the controller dynamic library

Returns:

true if successful

bool unload()

unload the currently loaded controller

Returns:

true if successful

bool halt()

call SafetyController::halt(). Turn in to halt mode.

Returns:

true if successful

bool controllerReset()

call Controller::reset() of the currently loaded controller.

Returns:

true if successful

bool advance()

call Controller::advance() of the currently loaded controller.

Returns:

true if successful

bool advanceSafetyControllerOnly()

call SafetyController::advance() only.

Returns:

true if successful

bool terminate()

call Controller::terminate() of the currently loaded controller.

Returns:

true if successful

bool isReady() const
Returns:

whether the currently loaded controller is ready

bool isDone() const
Returns:

whether the currently loaded (episodic) controller is done

const std::string &getCurrentControllerName()
Returns:

name of the currently loaded controller