Modifying scenes from Blender

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.

Create the simulation scene

Load sample file

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.

Adding middleware communication

Configuring the middlewares

Binding the components in the scene with the middleware is done in a configuration file within the Blender file.

  1. On the Text Editor window, select the file component_config.py

  2. 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.

Running the simulation

Run the simulation

Press p to start the Game Engine

Connect with the client

You can connect directly to the simulated sensors/actuators using the telnet program. With the configuration provided before, MORSE will create two ports:

  • Port 60000 for the Motion_Controller
  • Port 60001 for the Pose sensor

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:

  1. On a separate terminal, navigate to the directory $MORSE_ROOT/share/morse/examples/clients/atrv/

  2. Execute the command:

    $ python socket_v_omega_client.py
  3. Press a to give speed commands to the robot

  4. Type linear (for instance 0.2 m/s) and angular speeds (for instance 0.1 rad/s), followed by enter after each

  5. The robot should start moving in MORSE

  6. Press b to print the readings of the Pose sensor exported by MORSE

  7. 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.