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. Connect to the robot

Web interface

You can start MARRtino components from web interface (see Network Configuration for more details):

Shell interface

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

Note: since version 4.1, ROS nodes are distribted within docker components, so you need to access the docker components to issue ROS commands

Example:

docker exec -it base tmux
<enter ROS commands in the opened shell>

2. Bringup robot nodes

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

Devices

Functionalities

MARRtino Robot

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

Web interface  Robot start

Command line (v3.x)

cd src/marrtino_apps/robot

roslaunch robot.launch

Command line (v4.x)

echo '@robot' | netcat -w 1 localhost 9236

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 (v3.x)

$ cd src/marrtino_apps/stage

$ roslaunch simrobot.launch

Command line (v4.x)

echo '<map name>[;robot_type[;<num_robots>]]' | netcat -w 1 localhost 9235

Example:

echo 'montreal;marrtino' | netcat -w 1 localhost 9235

Other devices/functionalities

To use some commands, you need to start ROS nodes to enable required devices or functionalities.

More details on how to start nodes needed for using and programming the robot are available in the MARRtino Development Guide.

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

More details in the MARRtino Development Guide

3.1 Web programming interface

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

MARRtino robot

http://10.3.1.1/program/index.html

Virtual machine

http://localhost/program/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, ref='REL'|'ABS', frame='odom'|'map')

setSpeed(lx,az,time,stopend=False)
setSpeed4W(fl,fr,bl,br,tm,stopend=False)

stop()

enableObstacleAvoidance(False|True) 

goto(gx,gy,gth)  # map pose (move_base)
gotoLabel(label) # semantic map(map_server,move_base)

gotoTarget(gx,gy, frame='odom'|'map')  # no path planning

p = getRobotPose()


# range distance

d = obstacleDistance(deg=0)


# audio

sound(name)

say(text, language='en')

s = asr()

# modim

show_image(value, which='default')

show_text(value, which='default')


# vision

img = getImage()

img = getWebImage(objcat=None)

n = faceDetection(img)

label,conf = mobilenetObjrec(img)

b = tagTrigger()  # boolean

id = tagID()      # id

d = tagDistance() # [m]

a = tagAngle()    # [deg]


# utils

wait(sec)           # wait [sec]

b = marrtinoOK()    # robot is ready and running

d = distance(p1,p2) # distance between points/poses

display(x)          # print in display area





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 *


<your program>



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

https://github.com/robocupathomeedu/rc-home-edu-learn-matlab