Although now the main method to create scenario files in morse is using the Builder API, it remains possible and useful to be able to modify the settings and environment from the Blender interface.
This tutorial explains how to link components into an existing scene. All the methods here require the use of Blender’s user interface and short-cuts.
We will go through the steps required to manually build “from scratch” a new robot for simulation. Note that once created, you can save your simulation scenario as a regular Blender file to replay it directly any time later.
This tutorial assumes MORSE is properly installed. If not, follow the instructions here.
Open the MORSE simulator with the test file provided with the installation, by using this command:
$ morse $MORSE_ROOT/share/morse/examples/tutorials/tutorial-1.blend
This will load a scene with a robot in a room with some furniture.
The file:
$ morse $MORSE_ROOT/share/morse/examples/tutorials/tutorial-1-solved.blend
contains the final scene, as obtained at the end of the tutorial.
We’ll add a motion controller to the robot, so that it can receive commands from an external program. The robot will then move according to the instructions received. In this case we’ll add a controller that uses linear and angular speed (V, W).
Next we will add a pose sensor to the robot that will report the angles of the robot orientation with respect to the reference axes (yaw, pitch and roll)
Binding the components in the scene with the middleware is done in a configuration file within the Blender file.
On the Text Editor window, select the file component_config.py
Add the following items to the component_mw dictionary:
component_mw = {
"Pose": [["morse.middleware.socket_mw.MorseSocketClass", "post_message"]],
"Motion_Controller": [["morse.middleware.socket_mw.MorseSocketClass", "read_message"]],
}
This specifies that the output of the Pose sensor is to be serialized to a socket with the MorseSocketClass.post_message method and the Motion Controller reads its input from a socket with MorseSocketClass.read_message.
Press p to start the Game Engine
You can connect directly to the simulated sensors/actuators using the telnet program. With the configuration provided before, MORSE will create two ports:
By issuing this command from a terminal you will read a constant feed of the current position of the robot:
telnet localhost 60001
To give it movement instructions, you can do the following:
telnet localhost 60000
{"v": 2.0, "w": 1.0}
The second line must be given when inside the telnet environment, and will instruct the robot to move at 2.0 m/s and rotate with an angular speed of 1.0 rad/s.
Of course, telnet is not the only way to interact with the simulation. You can connect with the socket ports from another program.
As an example, we have provided a simple Python client program that you can use to test, and to guide you in creating your own programs. Just follow these instructions to try the client program:
On a separate terminal, navigate to the directory $MORSE_ROOT/share/morse/examples/clients/atrv/
Execute the command:
$ python socket_v_omega_client.py
Press a to give speed commands to the robot
Type linear (for instance 0.2 m/s) and angular speeds (for instance 0.1 rad/s), followed by enter after each
The robot should start moving in MORSE
Press b to print the readings of the Pose sensor exported by MORSE
Press q to exit the client
Finally exit the simulation, by pressing esc on the Blender window, then close Blender by pressing Ctrl-q, then enter.