PROGRAMMING

How to program your robot

This section contains information about how to program your MARRtino robot.

For programming the robot, you usually need to: 1) connect to the robot, 2) start basic nodes (modules), 3) write and run programs. These steps are described below.


1. Connection to the robot

Using ROS

Use the virtual machine to connect and program your robot. If you are familiar with ROS, you will find a typical ROS environment and you can use standard ROS tools. If you are using the Raspberry PI on the robot, just connect to it through

ssh ubuntu@10.3.1.1
password: marrtino

Using web interface

If you are not familiar with ROS, you can start ROS nodes from MARRtino web interface (see Network Configuration for more details):

  • connect to MARRtino<XXX> access point (default password: hellorobot!)
  • open a browser to access http://10.3.1.1/bringup
  • connect to the robot using the Connect button
  • manage nodes to run on the robot

When using MARRtino VM, you can connect to http://localhost/bringup to start some ROS nodes in simulation mode.

2. Bringup robot nodes

The following components can be activated (either with ROS commands or through the web interface)

Devices

  • Robot base / Simulator
  • Laser sensors
  • Cameras
  • Audio

Functionalities

  • Mapping
  • Navigation
  • Speech
  • Vision

MARRtino Robot

To run programs in your robot, you must first launch the orazio ROS node.

Web interface Robot start

Command line

$ cd src/marrtino_apps/robot
$ roslaunch robot.launch

Robot Simulator

To test your programs in a simulator, you can use the standard ROS 2D simulator Stage. Many tutorials are available about how to use it.

MARRtino ROS node is fully compatible with ROS stage. So code developed and running on Stage would run on MARRtino as well (just make sure the topics are correctly linked).

Stage folder in marrtino_apps shows an example of use of the simulator.

Web interface Simrobot start

Command line

$ cd src/marrtino_apps/stage
$ roslaunch simrobot.launch

Other devices/functionalities

For some commands, you need to start nodes managing devices on the robot or functionalities.

The slides RoboCup@Home Education MARRtino guide provide more details on how to start nodes needed for using and programming the robot.

3 Programming the robot

There are several options to program your robot

1. Use a web interface to program the robot with command tiles, Blockly and Python.

2. Write Python programs

3. Write MATLAB programs

3.1 Web interface

Connect to the programming web interface and choose a programming method.

MARRtino robot

http://10.3.1.1/blockly/index.html

Simulator

http://localhost/blockly/index.html

Commands

Program the robot as sequences of predefined commands

Blockly

Use Blockly

Python

Use web interface to write and run Python programs with high-level MARRtino commands.



MARRtino high-level programming commands

# motion
forward(m)
backward(m)
left(n)
right(n)
turn(deg)
set_speed(lx,az,time,stopend=False)
stop()
goto(gx,gy,gth)
goto_target(gx,gy)
p = get_robot_pose()

# range distance
d = obstacle_distance(deg=0)

# audio
sound(name)
say(text, language='en')
s = asr()
# modim
show_image(value, which='default')
show_text(value, which='default')

# vision
img = get_image()
img = get_web_image(objcat=None)
n = face_detection(img)
label,conf = mobilenet_objrec(img)

# utils
wait(sec)
b = marrtino_ok()
d = distance(p1,p2)

3.2 Programming with Python

Write and run Python programs

Move to marrtino_apps/program and follow instructions in

https://bitbucket.org/iocchi/marrtino_apps/src/master/program/

Note: skip the "Install" section.


Write a Python program

from robot_cmd import *
begin()
<your program>
end()


Run on local PC connected to the robot or simulator

$ python robot_program_1.py

Run in client/server mode

Server on the robot

$ ./robot_program_server.py 5000

Client (elsewhere)

Send program as a string with TCP (e.g., ./robot_program_client.py)


3.3 Programming with MATLAB

MATLAB can be also used as high-level language to program MARRtino.

Source code and examples available in this repository shows its use