• Diff for "pr2_mechanism/Tutorials/Communicating with a realtime joint controller"
Differences between revisions 9 and 10
Revision 9 as of 2009-08-14 20:53:51
Size: 1916
Editor: localhost
Comment: converted to 1.6 markup
Revision 10 as of 2009-09-15 23:33:21
Size: 2278
Editor: StuartGlaser
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
(Tutorial: Creating a Joint Controller)
Line 8: Line 9:
||<#FFFF00> <!> This wiki page is out of date ||

== Making realtime controllers ==
Line 13: Line 11:
=== Setup ===
All controllers inherit from Controller and should be written in the controller namespace. To inherit from Controller, you must include:
{{{
#include <mechanism_model/controller.h>
}}}
in your header file.
It requires that you include two functions:
{{{
void update(void)
{
  //I am called at realtime to update the controller
  //Have this function update your joint positions
  //Do your math and send your realtime_tools::RealtimePublisher messages here
  ...
}
<<TableOfContents(3)>>
Line 29: Line 13:
bool initXml(mechanism::RobotState *robot, TiXmlElement *config)
{
  //I am called at initialization
  //Have this function read the xml file that launched it
  //config is conveniently pointing at the xml element representing this controller
  //return true on a successful initialization
  ...
}
}}}
Controller has two other virtual functions that you can override as you see fit:
{{{
bool starting()
{
  //If the autostart parameter is true, I'm called once, once everything is setup
  //If this function returns true, the realtime calling of update begins
  ...
}
== Package-level Configuration ==
Line 47: Line 15:
bool stopping()
{
  //I am called when the controller is to be paused
  //I should undo anything done in starting()
  //Calling starting after calling stopping should resume controller functionality
  ...
}
}}}
In your .cpp file, outside of any function, you must register your controller as a controller using the following macro:
{{{
ROS_REGISTER_CONTROLLER(CONTROLLER_NAME_HERE)
}}}


== Creating the Controller Class ==

To make a realtime controller, create a class which inherits from the [[http://www.ros.org/doc/api/pr2_controller_interface/html/classcontroller_1_1Controller.html|controller::Controller]] class. Overload certain methods of this base class and Mechanism Control will call these methods when your controller changes state. You should certainly overload the `update` and `init` methods, and possibly the `starting` and `stopping` methods as well.

The `init` method is called from a non-realtime thread when your controller is loaded. In it, you should use the `RobotState` object to lookup the joints you will control and the !NodeHandle to read parameters and set up ROS communication.

The `starting` method is called from within realtime just before `update` is called for the first time. You should reset any state in the controller.

The `update` method is called once per realtime cycle. In `update` you should implement your controller's action, which may include reading joint states, writing joint efforts, and integrating in command information from external nodes.

/* TODO: register the controller with the classloader */

== Reading and Writing to Joints ==

Access to joints is provided through the [[http://www.ros.org/doc/api/pr2_mechanism_model/html/classpr2__mechanism_1_1RobotState.html|RobotState]] object, passed into the `init` method. You should lookup (by name) the joints you want in your `init` method using the `getJointState` method. You may then read from and write to the returned [[http://www.ros.org/doc/api/pr2_mechanism_model/html/classpr2__mechanism_1_1JointState.html|JointState]].

== External Communication ==

== Loading into the Mechanism Control Process ==

== Tools ==

=== Pids ===

=== KDL ===

=== Filters ===

(Tutorial: Creating a Joint Controller)

This tutorial gives an overview on making controllers for ros. It is assumed you have general knowledge of ros and its package system. If not, please review the Tutorials.

Package-level Configuration

Creating the Controller Class

To make a realtime controller, create a class which inherits from the controller::Controller class. Overload certain methods of this base class and Mechanism Control will call these methods when your controller changes state. You should certainly overload the update and init methods, and possibly the starting and stopping methods as well.

The init method is called from a non-realtime thread when your controller is loaded. In it, you should use the RobotState object to lookup the joints you will control and the NodeHandle to read parameters and set up ROS communication.

The starting method is called from within realtime just before update is called for the first time. You should reset any state in the controller.

The update method is called once per realtime cycle. In update you should implement your controller's action, which may include reading joint states, writing joint efforts, and integrating in command information from external nodes.

Reading and Writing to Joints

Access to joints is provided through the RobotState object, passed into the init method. You should lookup (by name) the joints you want in your init method using the getJointState method. You may then read from and write to the returned JointState.

External Communication

Loading into the Mechanism Control Process

Tools

Pids

KDL

Filters

Wiki: pr2_mechanism/Tutorials/Communicating with a realtime joint controller (last edited 2016-08-14 04:17:21 by Crescent)