controlling choreonoid with leap motion
#contents
In this case study, a Leap Motion sensor is used to control a GRobo robot running in the Choreonoid simulator.
First, you will verify operation using the provided components (demo system and sample components). Then, you will create your own component to control the robot in the simulator.
Resources and Prerequisites
Download and extract the following archive:
robomec2015_openrtm_tutorial_part3.zip(No corresponding page available.) Updated: 2015/05/20
The main contents of the archive are:
- Demo/: Components and Choreonoid for the demo system
- rtc_handle.bat: Batch file for launching the demo system
- src/: Source code of the provided components
- LeapMotion_RobotControl_Sample: Source code of the sample component
- LeapMotionGRoboControlSampleComp.exe: Binary of the sample component (x64, Visual Studio 2013)
- online_tutorial/: This web page
[Required] Download and install the Leap Motion driver by clicking “Windows Download” from the following page:
https://www.leapmotion.com/setup/windows
Verifying the Demo System
In this section, you will start the demo system and verify its operation.
Follow the steps below:
- Start the Name Server using “Start Naming Service” from the Start Menu (refer to the OpenRTM documentation(No corresponding page available.)).
- Launch RTSystemEditorRCP or OpenRTP 1.1.1 from the Start Menu.
- Run Demo/rtc_handle.bat to start the demo launcher.
- In RtcHandle, click the following buttons to launch the components:
- CNoid_G
- RobotDemo
- LeapRTC
- LeapMotion
- Click “getRtcList”.
- Click “Load” and select “LeapDemo.data”.
- Click “ConnectAll” to connect all components automatically.
- Click “ActivateAll” to activate all components and start the system.
- While the LeapRTCComp window is selected, move your hands above the Leap Motion sensor. Data will appear in the LeapMotion window, and the robot in the simulator will move according to the generated commands.
Verifying the Sample Component
In this section, the sample component is used instead of the GRobotDemo component to control the robot in the simulator.
Before proceeding, start the demo system using the steps described above.
Compiling LeapMotionGRoboControlSampleComp
- Start CMake.
- Specify src/LeapMotion_RobotControl_Sample as the source directory.
- Specify the build directory inside the source directory as the build directory.
- Click Configure.
- Select an appropriate Generator.
- The example shown uses Visual Studio 2013 x64.
- Select the Generator corresponding to your installed OpenRTM version.
- Click Generate to create the project.
- Open LeapMotionGRoboControlSample.sln in Visual Studio and build ALL_BUILD.
- Confirm that the component binary has been generated.
Running LeapMotionGRoboControlSampleComp
- Execute LeapMotionGRoboControlSampleComp.exe.
- In RTSystemEditor, delete the connections of the GRobotDemo component.
- Connect LeapMotionGRoboControlSampleComp as follows and activate it:
- Connect
LeapMotion.eSEAT0.hands_outtoLeapMotionGRoboControlSample0.hand_positions - Connect
LeapMotionGRoboControlSample0.hand_positionstoRobotMotion0.targetAngle
- Connect
- While the LeapRTCComp window is selected, move your hands above the Leap Motion sensor. The robot’s hands in the simulator will follow your hand movements.
Creating Your Own Component
This section explains how to create a robot control component.
First, generate a source-code skeleton using RTCBuilder. Then, edit the source code freely to implement your own algorithm for controlling the robot using Leap Motion data.
Creating the RTC
- Start RTCBuilder.
- Create a new RTCBuilder project (choose any project name and component name).
- Select the following activities:
- onActivated
- onDeactivated
- onExecute
- Create the following data ports:
| Type | Port Name | Data Type |
|---|---|---|
| InPort | hand_positions | RTC::TimedFloatSeq |
| OutPort | command | RTC::TimedString |
| OutPort | target_angles | RTC::TimedShortSeq |
- Skip the Service Port tab (none required).
- Skip the Configuration tab (none required).
- Set the programming language to C++.
- Generate the component source skeleton.
Editing the Source Code
After generation, edit and compile the component using CMake and Visual Studio.
Add the following private variables to the class definition in the header file:
bool m_rightUp;
bool m_leftUp;
Add the following function near line 12 of the .cpp file:
double minmax(double a, double max, double min)
{
if (a > max)
{
return max;
}
else if (min > a)
{
return min;
}
return a;
}
Add the following lines to the constructor:
m_rightUp = false;
m_leftUp = false;
Replace the contents of onExecute() with the provided source code.
(The original code block should be kept exactly as provided.)
Compile the component using the same procedure as for the sample component.
The compiled component can be used in the same way as LeapMotionGRoboControlSample0.
After confirming that it behaves the same as the sample component, modify the source code while referring to the following input/output data formats.
Input Data Format
The data received through eSEAT0.hands_out and supplied to the component’s hand_positions input port has the following format:
[right hand x, right hand y, right hand z,
left hand x, left hand y, left hand z]
Command Output Port
The command output port controls the robot’s posture by outputting one of the following commands:
- b_step
- balance
- bothdown
- bothup
- bow
- bye
- f01
- f1
- f_step
- go_ahead
- go_back
- gymnastics
- init
- kick
- l1
- left_step
- leftdown1
- leftdown2
- leftup1
- leftup2
- look_left
- look_right
- motion
- muri
- r1
- rest
- right_step
- rightdown1
- rightdown2
- rightup1
- rightup2
- turn_l
- turn_r
Target Angle Output Port
The target_angles output port specifies joint positions using the format:
[joint number, position, joint number, position, ...]
For example:
[14, <position>, 15, <position>, 16, <position>,
17, <position>, 18, <position>, 19, <position>]
Using Components on Another Computer
Components running on another computer can also be used.
This section explains how to connect components across a network.
Before proceeding, be sure to disable Windows Firewall.
Verifying Name Server Connectivity
First, verify that the computers can communicate and that the remote Name Server is visible.
- Determine the IP address of the remote computer.
- In RTSystemEditor, click Add Name Server and enter the remote computer’s IP address.
- If successful, the remote Name Server will appear in the Name Server list.
Verifying Component Connectivity
After confirming Name Server visibility:
- On the local computer, start ConsoleInComp.exe.
- On the remote computer, start ConsoleOutComp.exe.
-
In RTSystemEditor, place:
- ConsoleIn0 (local Name Server)
- ConsoleOut0 (remote Name Server)
- Connect their ports.
- If successful, numbers entered in ConsoleInComp.exe will be displayed by ConsoleOutComp.exe.
If remote components cannot be controlled:
- Open
rtc.conf. - Add the following line:
corba.endpoint: <IP address>
- Use the local computer’s IP address on the local machine and the remote computer’s IP address on the remote machine.
- Restart all components.
Using a Remote Leap Motion Component
Once connectivity has been verified, the remote LeapRTC0 component can be used from the local RTSystemEditor.
Place the remote LeapRTC0 component in the System Diagram and connect its ports. It will behave as if the Leap Motion sensor were directly connected to the local computer.
If RTSystemEditor still cannot control the component, follow the rtc.conf procedure described above.
For this tutorial package, the relevant rtc.conf files are located in:
robomec2015_openrtm_tutorial_part3/Demo/LeapMotionrobomec2015_openrtm_tutorial_part3/Demo/eSEAT