Overview

In this page, we demonstrate a sample robot model of a cart which is cooperated with RTC, that has a wheeled mechanism and can be operated interactively by using joystick. Both Controller and the joystick of this sample are made as OpenRTM components, and they are connected visually by using OpenRTM tools.

The model we concern in this article is the following cart model(Fig.1), that is one of the sample models available in OpenHRP.


Fig.1 Cart model

It has 3 wheels and can be steered by front wheel (the side having one wheel). The model consists of 4 rotational joints in total; one for steering and three for wheels(1 per each wheel).

The model file of this sample can be located at "etc/simple_vehicle.wrl" in OpenHRP3 source. Moreover the set of project files and sample programs described below are available at "sample/JoystickControl" in OpenHRP3 source directory.

Preparation

Since this sample requires OpenRTM based environment, the following packages/tools are need to be configured on your system.

  • OpenRTM-aist C++ edition
    • This should have been installed with OpenHRP3. Ver.0.4.2 or later in 0.4 series, is required.
  • OpenRTM-aist Python edition
    • Python environment is also required, since this sample uses RT components written in Python scripts.
      On Ubuntu-8.04 installation can be done by using deb package, but on Ubuntu-8.10 you would have to build the source and install.
      On Windows environments, please beware to select the proper (OpenRTM-aist Python) version compatible with Python-2.4 series, since OpenRTM-aist Python edition has compatibility issues with the Python that uses by OpenRTM-aist C++ edition.
  • RTSystemEditor.0.4.2, RTCBuilder.0.4.2
    • These are the basic OpenRTM tools, running as Eclipse plug-ins and mainly used to create/connect RT components. RTSystemEditor and RTCBuilder are correspond to RtcLink and RtcTemplate that we used before. You can setup these easily by using the Eclipse "All in one package", distributed by OpenRTM-aist.

Please refer OpenRTM-aist manuals, for the installation procedure of these software. You may note that source and pre-built packages are available to download. However you better select pre-built packages if you are not upto developing purpose.

Starting Nameserver

In CORBA and OpenRTM, the program called "Nameserver" is usually used to refer the objects generated at various places in system. For this, it is necessary to start the name server beforehand. Nameserver can be started by any of the following methods.

  1. Starting as OS daemon
    Nameserver can be set to start with OS start-up, by configuring a start-script. For example, if omniORB is installed in Ubuntu-Linux, the nameserver starts automatically with OS start-up.

  2. Starting using GrxUI
    When starting GrxUI (GUI of OpenHRP), it examines for the existence of the nameserver and if it is not started by that time, GrxUI takes actions to start the nameserver automatically. In this case, nameserver also stops with the termination of GrxUI.

  3. Starting manually
    OmniORB (the standard CORBA system used by OpenRTM-aist and OpenHRP) comes with nameserver start-up program called "omniNames"; starting this program manually, will start the nameserver. In this case, please start omniNames with appropriate options, as guided in OmniORB documentation.

When nameserver is started using GrxUI, GrxUI restart/termination effects on OpenRTM and its components' operation. Therefore it is better if you can keep the nameserver started beforehand. The start-up commands for Ubuntu and Windows are described below.

On Ubuntu

In Ubuntu, nameserver starts automatically if OmniORB is installed as a package; let's confirm this.

Run following command on Terminal.

$ ps ax | grep omniNames

In the output list, check whether "omniNames" is available as a process. If it is available, nameserver is running; and if not, start the nameserver manually as follows.

$ sudo /etc/init.d/omniorb4-nameserver start

Here we showed using Ubuntu deamon commands, but you can use omniNames commands too.

On Windows

When OpenRTM-aist is installed using its installer, a short-cut to start nameserver called "Start Naming Service" will be appeared under "Start menu""OpenRTM-aist""C++""examples". When starting nameserver using this short-cut, a console panel window will be displayed as shown below.


The console window appears at nameserver(omniNames) start-up

Note:
On OpenRTM-aist 0.4.2 installed Windows Vista environments, starting nameserver using the startmenu short-cut, cause the nameserver becomes undetectable upon RTCLink tool(describes later). To prevent this issue, find the batch file "rtm-naming.bat" targeted by "Start Naming Service" shortcut, and locate the following line;

set OMNIORB_USEHOSTNAME=localhost

comment out the line to disable the command as follows;

rem set OMNIORB_USEHOSTNAME=localhost

In this way, the problem will be resolved for the time being.

Launch of a joystick component

Please launch TkJoystickComp.py in sample/JoystickControl/JoysticRTC below the directory which you have extracted OpenHRP3. It will display the screen like the next figure.

Here, you can drag and move the center circle by your mouse. The location of this circle corresponds with a gradient of the joystick.

This program is made as a component of OpenRTM, it provides an OpenRTM port which outputs a gradient of the joystick. This port can be connected to an input for another RT component.

This time, we connect it to the controller of the robot, and make it possible to operate the robot by this joystick.

Launch of RTSystemEditor

Please start Eclipse in which RTSystemEditor has been installed.

Once Eclipse started, open RTSystemEditor perspective.

In "NameServiceView", press "Refresh Name Service" button, and you will see an item "JoyStick0|rtc", which corresponds with the joystick component you launched earlier on.


Fig.4: NameServiceView

When a localhost node is not displayed, Please push the "AddName Server" button on the right of a "Refresh Name Service" button, open a "Connect Name Server" dialog, and register localhost.


Fig.5: Dialog of connect Name Server

Click an item JoyStick0|rtc, properties of this component will be shown in the Property Window.


Fig6:Property Window

Next, click the item "Open New System Editor" from File menu or the tool button on Eclipse, and make SystemDiagram window visible.

From NameServiceView, drag the item Joystick0 to SystemDiagram. The component of Joystick will be displayed on SystemDiagram window.


Fig.7: A SystemDiagram view and the drug of a component

Generating the Skeleton using RTCBuilder

new project

Start RTC Builder.
In order to create a new project, please choose a file->new->project from menu.
Please choose a "RTC builder" from "others" in a new project wizard dialog. A project name is set to Sample in an example.


Fig.8: RTCBuilder new project

Module setup

Click a "Open New RtcBuilder Editor" button or file menu "Open New RtcBuilder Editor", and display the window of RTCBuilder. B

A setup of the controller is saved at sample/JoystickControl/JoystickController.xml. Click a "Profile Import" button and select JoystickController.xml in a file open dialog.

Open a basic profile input page. "Module name" is set to "JoystickController".


Fig.9: RTC Builder Basic page

Port setup

Open a data port page. Please see "RT-Component Data InPort Profile". A port called angle, velocity, and command is defined. Angle and velocity are the ports into which a robot's joint angle outputted from a simulator and joint angular velocity are inputted.

Command is the ports into which x,y position outputted from a joy stick component is inputted. The torque for controlling a robot is calculated from this input value.

A port called torque is defined as "RT-Component Data OutPort Profile". It is a port which outputs the joint torque value which controls a robot.


Fig.10: RTC Builder Data Port

Builder Language setup

Open a language and environment page. A programming language and compile environment are specified.


Fig.11: RTC Builder Language and environment

Generating the Skeleton

Return to a basic profile input page, and push code generation button to generate the skeleton of the component. The directory of a project name is generated in the work space directory of eclipse.

Coding of contoller component

By operations in the previous section, RTCBuilder generates a template code for a component, but of course, component developers have to write the part of its actual movement (which we call its core logic).

In RT-Component, several functions for actions of a component are defined on ahead. Its developers can override some of them in accordance with a kind of an action, and make a controller they need. In this example, we will implement those functions on "JoystickController.cpp" which were generated as a template.

You can read OpenRTM manual to see details about overridable functions defined in OpenRTM. This time, we will override "onInitialize" method which initialize during creation of components, and "onExecute" method which is called periodically for control and so on.

Override of onInitialize method

In "JoystickController.cpp", original onInitialize function is commented out. Enable the commented code and describe as below.

RTC::ReturnCode_t JoystickController::onInitialize()
{
  // initialize port
  m_torque.data.length(4);

  return RTC::RTC_OK;
}

Here, we set 4 to size of the double array which is used for torque output port in accordance with the number of joints in the robot. As for input ports, since their size are determined by outputs, we don't initialize them explicitly.

In addition, uncomment the corresponding function in the header file "JoystickController.h" as well as change to the cpp file.

Override of onExecute method

onExecute function which describe control code is a little complicated but we do implement as below. Uncomment the corresponding part of the header file for this function again.

RTC::ReturnCode_t JoystickController::onExecute(RTC::UniqueId ec_id)
{
  // data input from the robot
  m_angleIn.read();
  m_velocityIn.read();
  double steerAngle = m_angle.data[0];
  double steerVel = m_velocity.data[0];
  double tireVel = m_velocity.data[1];

  // data input from the joystick(user)
  m_commandIn.read();
  double steerCommandAngle = 3.14159 * -0.5 * m_command.data[0] / 180.0;
  double tireCommandVel = m_command.data[1] / 10;

  // steering torque calculation 
  double steerCommandTorque = 20.0 * (steerCommandAngle - steerAngle) - 2.0 * steerVel;

  // driven torque calculation
  double tireCommandTorque = 1.0 * (tireCommandVel - tireVel);

  // torque output to the robot
  m_torque.data[0] = steerCommandTorque;
  m_torque.data[1] = tireCommandTorque;
  m_torque.data[2] = tireCommandTorque; 
  m_torque.data[3] = tireCommandTorque; 
  m_torqueOut.write(); 

  return RTC::RTC_OK;
}

Here, the first element of the input from the joystick, which is x value, is set as a target angle of steering. And the second element of y value is set as a target value of the driven velocity. Based on these target values, torques of steering and driven tires are determined using an appropriate gains.

Those changes have been already applied to source files below sample/JoystickControl/ControllerRTC. Thus, you can get an execution file of the component which is implemented the way we have discussed by loading and compiling the project file JoystickController.sln which is a project file of these source files.

Creating rtc.conf

Describe the settings to run RT-Components in rtc.conf. We have produced the next file:

corba.nameservers: localhost
naming.formats: %n.rtc
exec_cxt.periodic.type: ExtTrigExecutionContext

Currently, for an OpenHRP controller, naming.formats and exec_cxt need to be set up as above. ExtTrigExecutionContext is an execution context for synchronization with simulation time, but it doesn't guarantee a perfect synchronization and sometimes has trouble with its operation. In versions 0.4.2 and later of OpenRTM-aist, such a problem will be fixed by a new execution context. Just for this example, there is no big problem which is caused by the context.

Creating bridge.conf

Next we create bridge.conf file which configures how to connect between a simulator and a controller component. In this sample, the file becomes as below:

[ComponentName]
JoystickController0.rtc

[ArrayMappingIn]
angle JOINT_VALUE
velocity JOINT_VELOCITY

[ArrayMappingOut]
torque JOINT_TORQUE

[PortNameMapping]
angle angle
velocity velocity
torque torque

Details about this setting are explained in Creating OpenHRP Controller Manual.

Load of OpenHRP simulation project

Once we finished a controller above, we will make a simulation project on GrxUI, which arranges models and associates controllers with models. Details how to create a simulation project are explained in the manual of GrxUI. Here, load the project which has been already configured.

Please load "SimulationProject.xml" below sample/JoysticControl from GrxUI. And on GrxUI, a wheeled type mechanism will appeared on its floor.

Here select Tools - Process Manager from GrxUI, and make sure items of JoystickController are checked, please. If compilation of components are successful previously, when the simulation project is loaded, process of components should start and enable thess items (see the next figure).


Fig.12: GrxUI which has loaded a simulation project

Connecting between a joystick and a controller using RTSystemEditor

Connect a controller component to a joystick component.

Let's return to RTSystemEditor again. Please drag JoystickController and VirtualRobot from NameServiceView to SystemDiagram as well as a TkJoyStick component.

Then connect ports. Drag your mouse from the part of "pos" port on the right upper of TkJoyStick0, to the part of "command" port on the left lower of JoystickController0. These ports are connected each other by a line.


Fig.13: connect ports

Similarly, please also connect the port of angle, velocity, and torque of "JoystickController0", and the port of the same name of "VirtualRobot0."

Moreover, select "Active" from the context menu which pops up when you right-click TkJoyStick0, and activate the joystick component.

The result we operate as above is the state indicated in the following figure.


Fig.14: RTSystemEditor

Start of simulation and operation of joystick

Now, let's start simulation. Click "Start Simulation" on GrxUI.

After this simulation starts, the wheel model may stay stopping. In this state, bring up the joystick window which you have opened on ahead, operate your joystick. The left and right of the joystick correspond with steering, and the top and bottom corresponds with driven power. We hope you can operate your model as if you drive your radio control car.