robobosimpy - mintforpeople/robobo-programming GitHub Wiki

Robobosim.py library

Robobosim.py is the library used to directly interact with the functions exclusive to the simulator for the Robobo educational robot (http://www.theroboboproject.com) in the Python language.

The robobosim.py library is designed to make it easier to work with the simulator, allowing, for example, to change the robot position directly, without moving the wheels (as if we were doing it by hand). It is important to keep in mind that no function in this library can be used in the real robot.

In this section, you can find basic documentation to install and start using this library.

Installation

The library runs with Python 3, so it must be installed before using the library.

Once you have installed Python 3, you can install the library with pip:

pip install robobosim

Library methods description

connect()

Establishes the connection to the simulator.

disconnect()

Stops the connection with the simulator.

wait(seconds)

Pauses the execution for the amount of time specified

Parameters:

  • seconds (float): Time to wait in seconds (>0). Decimals like 0.2 are allowed

getRobots()

Returns the list of available robots in the scene

getRobotLocation(robot_id)

Returns the location, in global coordinates, of the specified robot.

Parameters:

  • robot_id (int): The ID of the robot. This parameter is incremental and starts at 0.

setRobotLocation(robot_id, position=None, rotation=None)

Sets the location of the specified robot.

Parameters:

  • robot_id (int): The ID of the robot. This parameter is incremental and starts at 0.
  • position (dict): Optional. Dictionary with the coordinates (x, y, z) of the target position. If not specified, the current position is kept.
  • rotation (dict): Optional. The ID of the robot. This parameter is incremental and starts at 0. If not specified, the current rotation is kept.

resetSimulation()

Resets the state of the current simulation running on RoboboSim.

getObjects()

Returns the list of available objects in the scene

getObjectLocation(object_id)

Parameters

  • object_id (string): The ID of the specified object

setObjectLocation(object_id, position, rotation)

Sets the location in world coordinates of the Object specified by the ID

Parameters

  • object_id (string): The ID of the specified object.
  • position (dict): Optional. Dict (x,y,z) of the target global position for the robot. If not specified robot will retain position.
  • rotation (dict): Optional. Dict (x,y,z) of the target global rotation of the robot. If not specified robot will retain rotation.

onNewLocation(callback)

Configures the callback that is called when location data is received.

Parameters

  • callback (fun): The callback function to be called.

onNewLocation(callback)

Configures the callback that is called when object location data is received.

Parameters

  • callback (fun): The callback function to be called.

AGVobo Load & Unload Methods

loadItem(robot_id)

If the AGV Robobo is placed on a proper load zone, it will load and carry the item provided by that zone on top of the robot

Parameters

  • robot_id (int): ID of the robot to load the item on

unloadItem(robot_id)

If the AGV Robobo is placed on a proper unload zone and is carrying a loaded item, it will drop the loaded item

Parameters

  • robot_id (int): ID of the robot to unload the item from

isRobotLoaded(robot_id)

Returns the boolean load status of the Robot specified by the index

Parameters

  • robot_id (int): ID of the robot to check the load status of

onNewLoaded(callback)

Configures the callback that is called when load status data is received.

Parameters

  • callback (fun): The callback function to be called

Sample code

To illustrate the use of these methods, the following example shows how to read and modify Robobo's position in the simulator:

# Import the library
from robobosim.RoboboSim import RoboboSim

# Connect to the RoboboSim
IP = "localhost"
sim = RoboboSim(IP)
sim.connect()

sim.wait(0.5)
# Get current location and print it
loc = sim.getRobotLocation(0)
print(loc["position"])
sim.wait(0.5)

# Move the Robot -20mm in the X axis
pos = loc['position']
pos["x"] -= 20
sim.setRobotLocation(0, loc['position'])
sim.wait(1)

# Reset the simulation
sim.resetSimulation()

sim.disconnect()

Sample object manipulation code

The following example shows how to read and modify a scene object's position:

# Import the library
from robobosim.RoboboSim import RoboboSim

# Connect to the RoboboSim
IP = "localhost"
sim = RoboboSim(IP)
sim.connect()

sim.wait(0.5)

# Get the interactable objects of the scene
# These come as a dict that can be indexed by the object's name
# For the sake of simplicity we'll just convert it to a list and grab the first one available
objects = sim.getObjects()
if objects is not None and len(objects) > 0:
    # Get the first object of the list, provided that there is at least one
    object_one = list(objects)[0]
    print(object_one)
    # Get the object's absolute position
    loc = sim.getObjectLocation(object_one)
    print(loc["position"])
    sim.wait(0.5)

    # Move the selected object +50 mm along the X axis
    pos = loc['position']
    pos["x"] += 50
    sim.setObjectLocation(object_one, loc['position'])
    sim.wait(0.5)

sim.disconnect()