This page describes the procedure for creating components for operating the Raspberry Pi mouse on the simulator.
Please download the materials first.
Please unarchives ZIP file by tools such as Lhaplus.
The seminar may be held in an environment where you cannot connect to the Internet. In that case, it is stored in the distributed USB memory.
The simulator is developed using a physics engine called Open Dynamics Engine (ODE): http and a drawing library (drawstuff) that comes with ODE. It works if OpenGL works, so it should work in most environments.
You can simulate the following robot Raspberry Pi mouse.
Not only the dynamic calculation and contact response of the Raspberry Pi mouse on the simulator, but also the data of the distance sensor reproduces the values close to those of a real robot.
The Raspberry Pi mouse is an independent two-wheel drive mobile robot sold by RT corp..
RaspberryPi Mouse Specification | |
CPU | Raspberry Pi 2 Model B |
Motor | Stepping motor ST-42BYG020 x2 |
Motor Driver | SLA7070MRPT x2 |
Distance sensor | Red LED + Photo-transistor(ST-1K3) x4 |
Monitor red LEDs | x4 |
Buzzer | x1 |
Tact switch | x3 |
Battery | LiPo3-cells (11.1V) 1000mAh x1 |
An RT-Component to control the robot on the simulator by connecting with the RaspberryPiMouseSimulator Component.
An RT-Component which can operate the robot on the simulator with the GUI (slider) and automatically stops when the sensor value exceeds a certain level will be created.
The development process is as follows.
The following development environment is assumed.
The RobotController has an OutPort that outputs the target speed, an InPort that inputs the sensor value, and configuration parameters that set the target speed and the sensor value to stop.
Name of RT-Component | RobotController |
InPort | |
Name of InPort | in |
Type | TimedShortSeq |
Description | Sensor value |
OutPort | |
Name of OutPort | out |
Type | TimedVelocity2D |
Description | Target velocity |
Configuration | |
Name of configuration parameter | speed_x |
Type | double |
Default value | 0.0 |
Constraints | -1.5<x<1.5 |
Widget | slider |
Step | 0.01 |
Description | The speed of straight-ahead |
Configuration | |
Name of configuration parameter | speed_r |
Type | double |
Default value | 0.0 |
Constraints | -2.0<x<2.0 |
Widget | slider |
Step | 0.01 |
Description | The rotational speed |
Configuration | |
Name of configuration parameter | stop_d |
Type | int |
Default value | 30 |
Description | The sensor value to be stopped the robot |
We use the TimedVelocity2D type, which is a data type that stores the moving speed of a moving robot on a two-dimensional plane.
struct Velocity2D { /// Velocity along the x axis in metres per second. double vx; /// Velocity along the y axis in metres per second. double vy; /// Yaw velocity in radians per second. double va; }; struct TimedVelocity2D { Time tm; Velocity2D data; };
This data type can store the velocity vx along the X axis, the velocity vy along the Y axis, and the velocity va around the Z axis.
vx、vy、va represents the velocity in the robot center coordinate system.
For a robot with two wheels mounted on the left and right, such as a Raspberry Pi mouse, vy would be 0 assuming no skidding.
The robot is operated by specifying the straight-ahead speed vx and the rotation speed va.
The data of the distance sensor of the Raspberry Pi mouse is designed to output a larger value as the distance to the object gets closer.
Value from sensor | Actual distance[m] |
1394 | 0.01 |
792 | 0.02 |
525 | 0.03 |
373 | 0.04 |
299 | 0.05 |
260 | 0.06 |
222 | 0.07 |
181 | 0.08 |
135 | 0.09 |
100 | 0.10 |
81 | 0.15 |
36 | 0.20 |
17 | 0.25 |
16 | 0.30 |
The simulator reproduces this value and outputs it. The RobotController component implements a process that automatically stops when this value exceeds a certain level.
RTCBuilder is used to generate the template for the RobotController component.
In Eclipse, the folder where you do various tasks is called a "workspace", and as a general rule, all products are stored under this folder. You can create a workspace in any folder that you can access, but this tutorial assumes the following workspace.
First, start Eclipse. For Windows 10, you can start it by clicking Start menu> "OpenRTM-aist 1.2.1"> "OpenRTP", or search OpenRTP from the search window in the next of the Start Button.
You will first be asked for the location of the workspace, so specify the workspace above.
Then, the following Welcome page will be displayed.
The Welcome page is no longer needed, so click the x button in the upper left to close it.
Click the [Open Perspective] button in the upper right.
Select RTC Builder to start RTC Builder. The RTCBuilder icon for Hammer and RT appears in the menu bar.
You need to create a new project in RTCBuilder to create the RobotController component.
Click the Open New RTCBuilder Editor icon in the upper left.
Enter the project name (here, RobotController) to be created in the Project Name field and click the [Finish] button.
A project with the specified name will be generated and added to the Package Explorer.
The RTC profile XML (RTC.xml) with default values is automatically generated in the generated project.
When RTC.xml is generated, the RTCBuilder editor should open as the workspace associated with this project. If it doesn't start, double-click RTC.xml in Package Explorer.
First, select the Basics tab on the far left and enter the basic information. In addition to the RobotController component specifications (name) you decided earlier, enter the outline, version, etc. Items with red labels are required items. Others can be the default.
Then select the Activity tab and specify the action callback to use.
For RobotController component uses the onActivated(), onDeactivated(), onExecute() callbacks. As shown in the figure below, after clicking onAtcivated in (1), check [ON] with the radio button in (2). Just double-clicking the onActivated label toggles [ON] and [OFF]. Follow the same procedure for onDeactivated and onExecute.
In addition, select the DataPort tab and enter the DataPort information. Enter the following based on the specifications you decided above. The variable name and display position are optional and can be left as they are.
Then select the Configuration tab and enter the Configuration information based on the specifications you just decided. Constraints and widgets are used to change values in the GUI, such as sliders, spin buttons, and radio buttons, when displaying component configuration parameters in RTSystemEditor.
The straight speed speed_x and the rotation speed speed_r make it easier to operate with the slider.
Next, select the Language / Environment tab and select the programming language. Here, select C++ (language). In addition, defaults etc. are not set for the language and environment, and if you forget to specify it, an error will occur at the time of code generation, so be sure to specify the language.
Finally, click the Generate Code button on the Basic tab to generate a template for the component.
You can open the workspace in Explorer by right-clicking on the project and selecting View> System Explorer.
The code generated by RTCBuilder includes CMakeLists.txt to generate various files required for building by CMake. By using CMake, Visual Studio project files, solution files, Makefiles, etc. can be automatically generated from CMakeLists.txt.
Use CMake to configure the build environment. First, start CMake (cmake-gui). You can start it by clicking Start button> App View (lower right arrow)> CMake X.Y.X> CMake (cmake-gui), or search with cmake-gui from the search window next to the start buttont.
There are the following text boxes at the top of the screen, so specify the source code location (where CMakeList.txt is) and the build directory, respectively.
The source code location is where the RobotController component source was generated and where CMakeList.txt resides. The default is <workspace directory>/RobotController.
This directory is set by dragging and dropping from Explorer to cmake-gui without any manual input.
The build directory is the place to store project files, object files, and binaries for building. The location is arbitrary, but in this case it is recommended that you specify a subdirectory of RobotController with a descriptive name, such as <workspace directory>/RobotController/build.
Where is the soruce code | C:\workspace\RobotController |
Where to build the binaries | C:\workspace\RobotController\build |
Once specified, click the Configure button below. Then a dialog like the one below will be displayed, so specify the type of project you want to generate. This time, let's call it Visual Studio 16 2019. If you are using Visual Studio 2013 or Visual Studio 2015, please change it. Also set the platform to x64. If you have installed the 32-bit version, select Win32.
Click the [Finish] button in the dialog to start Configure. If there are no problems, Configuring done will be output in the log window at the bottom, so click the [Generate] button. If Generating done is displayed, the output of the project file, solution file, etc. is completed.
Note that CMake generates a cache file at the stage of Configure, so if you change the settings or change the environment due to trouble etc., delete the cache with [File]> [Delete Cache] and start over from Configure.
Then double-click RobotController.sln in the build directory you specified earlier to start Visual Studio.
NOTE: In the new version of cmake-gui, you can start it by clicking the button on cmake-gui.
In the RobotController component, the configuration parameters (speed_x, speed_y) are operated with sliders and the values are output from the outport (out) as the target speed. The value input from import (in) is stored in the variable, and if the value exceeds a certain value, it stops.
The following figure shows the processing contents of onActivated(), onExecute(), and onDeactivated().
Declare the variable sensor_data to temporarily store the sensor value.
private: int sensor_data[4]; // A variable that stores the sensor value
Implement onActivated(), onDeactivated(), onExecute() as shown below.
RTC::ReturnCode_t RobotController::onActivated(RTC::UniqueId ec_id) { // Initialize sensor vaiables for (int i = 0; i < 4; i++) { sensor_data[i] = 0; } return RTC::RTC_OK; }
RTC::ReturnCode_t RobotController::onDeactivated(RTC::UniqueId ec_id) { // Stopping the robot m_out.data.vx = 0; m_out.data.va = 0; m_outOut.write(); return RTC::RTC_OK; }
RTC::ReturnCode_t RobotController::onExecute(RTC::UniqueId ec_id) { // Check if data is arrving if (m_inIn.isNew()) { // Read input data from InPort m_inIn.read(); for (int i = 0; i < m_in.data.length(); i++) { // Storing input data if (i < 4) { sensor_data[i] = m_in.data[i]; } } } // Determine if robot is stopped only when moving forward if (m_speed_x > 0) { for (int i = 0; i < 4; i++) { // Determine if the sensor value is greater than certain value if (sensor_data[i] > m_stop_d) { //Stop if the sensor value is greater than the set value m_out.data.vx = 0; m_out.data.va = 0; m_outOut.write(); return RTC::RTC_OK; } } } // If there is no sensor with a value higher than the set value, // operate with the value of the configuration parameter. m_out.data.vx = m_speed_x; m_out.data.va = m_speed_r; m_outOut.write(); return RTC::RTC_OK; }
Select [Build] > [Build Solution] on the Visual Studio to build.
Connect the created RobotController to the simulator component and check the operation.
Start the name service to register the component reference.
Press the name service start button of RT System Editor to start it.
&color(red){NOTE: If omniNames does not start when you click Start Naming Service, make sure the full computer name is set to 14 characters or less.}
Please start the RobotController component. Run the RobotControllerComp.exe file in the RobotController\build\src\Debug (or Release) folder.
This component starts when you run EXE / RaspberryPiMouseSimulatorComp.exe in the folder where you extracted the file you downloaded earlier (RTM_Tutorial_2018.zip).
As shown in the figure below, connect the RobotController component and RaspberryPiMouseSimulator component by using RTSystemEditor.
Click the All Activate icon at the top of RTSystemEditor to activate all components. If activated successfully, the component will be displayed in yellow-green as shown below.
You can change the configuration from the [Edit] button in the configuration view as shown below.
If you have prepared an actual Raspberry Pi mouse on the seminar, you can check the operation on the actual robot, so if you have time to spare, please try it.
The procedure is as follows.
The Raspberry Pi mouse has two power switches, one is the Raspberry Pi power switch and the other is the motor power switch.
Turn on the power switch on the inside to start the Raspberry Pi.
When turning off the Raspberry Pi, do not turn it off directly from the power switch. Press the button in the middle of the three buttons for a few seconds to start shutting down. The Raspbian shutdown will be completed in about 10 seconds, so turn off the power switch after that.
Please refer to the following page for how to connect to the access point.
The SSID and password are printed on the sticker attached to the Rasoberry Pi mouse. First, click on the network icon at the bottom right.
To restart the Name Server on the RT System Editor, click the "Start Name Service" button again.
Then add 192.168.11.1 with the [Add Name Server] button in the RTSystemEditor.
Then you will see the following three RTCs.
RaspberryPiMouseRTC is an RT-Component for controlling Raspberry Mouse, which is being developed in the Robot System Design Laboratory of Meijo University.
Connect the RaspberryPiMouseRTC and RobotController components in the RTSystemEditor as follows.
Please turn on the power switch of the motor before operation. Be sure to turn off the power of the motor frequently.
Then activate the RTC and you will be able to operate the Raspberry Pi mouse.