creating rtcs for ev3 (python edition)
init #contents
Assembling the Mobile Robot
When you purchase the standard EV3 kit, it should include a manual describing how to build a mobile robot (Educator Vehicle).
If you do not have the manual, you can download it from the following URL. In this tutorial, we will use this mobile robot as an example to create a mobile robot RTC.
First, assemble the mobile robot (Educator Vehicle) according to the manual.
Connect the motors and sensors as follows:
| Right Motor | Port C |
| Left Motor | Port B |
| Motor (M) | Port A |
| Right Touch Sensor | Port 3 |
| Left Touch Sensor | Port 1 |
| Ultrasonic Sensor | Port 4 |
| Gyro Sensor | Port 2 |
Mobile Robot Kinematics
The component described above receives a two-dimensional velocity command as input. However, to actually control the motors, motor angular velocity commands must be calculated and sent to the motors.
For an introduction to mobile robot kinematics, the following page by Professor Kumagai of Tohoku Gakuin University is helpful:
Following the Common Interface Specification for Autonomous Mobile Functions,
- http://openrtm.org/openrtm/ja/project/Recommendation_CommonIF(No corresponding English project page available.)(No corresponding English project page available.)
we assume a right-handed coordinate system with the robot’s forward direction as the X-axis.
Velocity commands are represented as (v_x, v_y, v_a) according to this coordinate system. Since this is a differential-drive mobile robot, v_y is always 0, so only v_x and v_a need to be specified.
Let the angular velocities of the right and left wheels be
and
, respectively, and let the wheel radius be r. The linear velocities at the wheel-ground contact points, v_r and v_l, are:
Let ρ be the distance from the center of rotation to the center of the robot. Then:
On the other hand, if d is half the distance between the wheels (half the tread width), then:
From these equations, the angular velocities that should be applied to the left and right motors for a velocity command (v_x, v_y, v_a) are:
For the Educator Vehicle, the wheel diameter (2r) and tread width (2d) are:
| Wheel Diameter (2r) | 56 mm (0.056 m) |
| Wheel Radius (r) | 28 mm (0.028 m) |
| Tread Width (2d) | 118.5 mm (0.1185 m) |
| Half Tread Width (d) | 59.25 mm (0.05925 m) |
| Wheel Width | 28.5 mm (0.0285 m) |
Therefore:
Self-Localization (Odometry)
Next, let us consider how to estimate the robot’s position.
By integrating the robot’s linear and angular velocities, the position and orientation at any time can be obtained. Let the linear velocity be v_x and the angular velocity be v_a. Using a linear approximation, the relationship between the infinitesimal displacement (x, y, θ) and (v_x, v_a) is:
(A more accurate method would use arc approximation, but for simplicity we use linear approximation here.)
When implementing this on a computer with a sampling period Δt [s], the equations become:
Creating an RTC Skeleton
Designing the RTC
Now we design the RTC to be created.
The specifications of the RTC are shown below. Enter the required information in RTCBuilder and generate the skeleton code.
| Basic Tab | ||
| Profile Item | Name / Setting | |
| Module Name | EducatorVehicle | |
| Version | Any | |
| Vendor | Any | |
| Category | Mobilerobot | |
| Activity | ||
| Enabled Actions | onInitialize, onActivated, onDeactivated, onExecute | |
| Data Ports (InPort) | ||
| Port Name | Type | Description |
| velocity2D | RTC::TimedVelocity2D | Velocity command (v_x, v_y, v_θ) [m/s, m/s, rad/s] |
| angle | RTC::TimedDouble | |
| Data Ports (OutPort) | ||
| Port Name | Type | Description |
| odometry | RTC::TimedPose2D | Current position and orientation (x, y, θ) [m, m, rad] |
| ultrasonic | RTC::RangeData | Stores the ultrasonic sensor measurement as range sensor distance data in element 1 |
| gyro | RTC::TimedDouble | Outputs gyro sensor values as TimedDouble [rad] |
| color | RTC::TimedString | Outputs color sensor values as color names (none, black, white, blue, green, red, yellow, brown) |
| touch | RTC::TimedBooleanSeq | Outputs touch sensor values as Boolean[2] |
| Configuration | ||
| Parameter Name | Type | Description |
| wheelRadius | double | Wheel radius [m] |
| wheelDistance | double | Half the distance between the wheels [m] |














