Code Documentation

class pyrosim.Simulator(eval_steps=100, dt=0.01, play_blind=False, play_paused=False, update_network=1, draw_joints=False, use_textures=True, draw_shadows=True)[source]

Python Interface for ODE robotics simulator

eval_steps

int (optional) – Number of simulated steps (default 100)

dt

float (optional) – Length of simulated time in seconds of each step (default 0.01)

play_blind

bool (optional) – Run without graphics (default False)

play_paused

bool (optional) – Start simulation paused (default False)

draw_joints

bool ( optional ) – Starts simulation with joints drawn on screen. This can be toggled while the simulation is running by pressing ‘d’. (default False)

add_box_to_composite(composite_id, position=(0.0, 0.0, 0.0), orientation=(0.0, 0.0, 1.0), sides=(0.25, 0.25, 0.25), density=1.0, color=(1.0, 1.0, 1.0))

Adds box geometry to a composite body

Parameters:
  • composite_id (int) – The id tag of the target composite body
  • position (triple float (optional)) – The global position of the body. (default [0, 0, 0])
  • orientation (triple float (optional)) – The gloabl orientation of the body. (default [0, 0, 1])
  • sides (triple float (optional)) – The length, width, and height of the body. (default [.25, .25, .25])
  • density (float (optional)) – The density of the body
  • color (triple float (optional)) – Color of the body. (default is [1, 1, 1])
add_cylinder_to_composite(composite_id, position=(0.0, 0.0, 0.0), orientation=(0.0, 0.0, 1.0), length=0.5, radius=0.05, capped=True, density=1.0, color=(1.0, 1.0, 1.0))

Adds cylinder geometry to a composite body

Parameters:
  • composite_id (int) – The id tag of the target composite body
  • position (triple float (optional)) – The global position of the body. (default [0, 0, 0])
  • orientation (triple float (optional)) – The gloabl orientation of the body. (default [0, 0, 1])
  • length (float (optional)) – The length of the long axis of the cylinder. (default 0.5)
  • radius (float (optional)) – The radius of the cylinder. (default 0.05)
  • capped (boolean (optional)) – If true, the cylinder has rounded edges. If false, the cylinder has flat edges. (default True)
  • density (float (optional)) – The density of the body
  • color (triple float (optional)) – Color of the body. (default is [1, 1, 1])
add_impulse_to_body(body_id, force, time_step=0)

Adds an impulse force to a body at specified time step

Parameters:
  • body_id (int) – The id tag of the target body
  • force (triple float) – The force vector to apply
  • time_step (int (optional)) – The tme step to apply the specified force
add_light_to_body(body_id, intensity=1.0)

Makes the target body emit a light that can be sensed by light sensors

add_sphere_to_composite(composite_id, position=(0.0, 0.0, 0.0), orientation=(0.0, 0.0, 1.0), radius=0.25, density=1.0, color=(1.0, 1.0, 1.0))

Adds sphere geometry to a composite body

Parameters:
  • composite_id (int) – The id tag of the target composite body
  • position (triple float (optional)) – The global position of the body. (default [0, 0, 0])
  • orientation (triple float (optional)) – The gloabl orientation of the body. (default [0, 0, 1])
  • radius (float (optional)) – The radius of the sphere. (default 0.25)
  • density (float (optional)) – The density of the body
  • color (triple float (optional)) – Color of the body. (default is [1, 1, 1])
assign_collision(group1, group2)[source]

Specifies that members of group1 and group2 should collide in simulation

Parameters:
  • group1 (str) – String name of group 1
  • group2 (str) – String name of group 2
Returns:

True if successful

Return type:

bool

get_all_sensor_data()[source]

Outputs all sensor data created by the simulation

Returns:The sensor dictionary. The keys are is the id of the sensor and the value a list containing the sensory information at each time step.
Return type:dict
get_debug_output()[source]

Returns the debug output from the simulation

get_sensor_data(sensor_id=None)[source]

Returns the sensor data of the specified sensor at each time step

send_ball_and_socket_joint(body1, body2, anchor=(0, 0, 1))

Send a ball and socket joint to the simulator

Ball and sockets maintain the distance between the bodies and the joint

Parameters:
  • body1 (int) – The id tag of the first body. Specify -1 in order to set body1 to the ‘world’
  • body2 (int) – The id tag of the second body. Specify -1 in order to set body2 to the ‘world’
  • anchor (triple of floats (optional)) – The absolute starting position of the joint.
send_bias_neuron(value=1.0)

Send a bias neuron to the simulator

send_box(position=(0.0, 0.0, 0.0), orientation=(0.0, 0.0, 1.0), sides=(0.25, 0.25, 0.25), density=1.0, color=(1.0, 1.0, 1.0), space=None, collision_group=None)

Send a box geometry to the simulator

Parameters:
  • position (triple float (optional)) – The global position of the body. (default [0, 0, 0])
  • orientation (triple float (optional)) – The gloabl orientation of the body. (default [0, 0, 1])
  • sides (triple float (optional)) – The length, width, and height of the body. (default [.25, .25, .25])
  • density (float (optional)) – The density of the body
  • color (triple float (optional)) – Color of the body. (default is [1, 1, 1])
  • space (str (optional)) – The string name of the space in which to place the body. (default is to use the string set by set_current_space() function)
  • collision_group (str (optional)) – The string name of the collision group in which to place the body. Collision groups specify how bodies collide. (default is to use the string set by set_current_collision_group() function)
Returns:

The id tag of the box

Return type:

int

send_composite_body(space=None, collision_group=None)

Send a composite body base

Parameters:
  • space (str (optional)) – The string name of the space in which to place the body. (default is to use the string set by set_current_space() function)
  • collision_group (str (optional)) – The string name of the collision group in which to place the body. Collision groups specify how bodies collide. (default is to use the string set by set_current_collision_group() function)
Returns:

The id tag of the composite body

Return type:

int

send_cylinder(position=(0.0, 0.0, 0.0), orientation=(0.0, 0.0, 1.0), length=0.5, radius=0.05, capped=True, density=1.0, color=(1.0, 1.0, 1.0), space=None, collision_group=None)

Send a cylinder geometry to the simulator

Parameters:
  • position (triple float (optional)) – The global position of the body. (default [0, 0, 0])
  • orientation (triple float (optional)) – The gloabl orientation of the body. (default [0, 0, 1])
  • length (float (optional)) – The length of the long axis of the cylinder. (default 0.5)
  • radius (float (optional)) – The radius of the cylinder. (default 0.05)
  • capped (boolean (optional)) – If true, the cylinder has rounded edges. If false, the cylinder has flat edges. (default True)
  • density (float (optional)) – The density of the body
  • color (triple float (optional)) – Color of the body. (default is [1, 1, 1])
  • space (str (optional)) – The string name of the space in which to place the body. (default is to use the string set by set_current_space() function)
  • collision_group (str (optional)) – The string name of the collision group in which to place the body. Collision groups specify how bodies collide. (default is to use the string set by set_current_collision_group() function)
Returns:

The id tag of the cylinder

Return type:

int

send_height_map(height_matrix, position=(0, 0, 0), size=10.0, height_scale=1.0)

Send a height map to the simulator

Parameters:
  • height_matrix (2D numpy matrix) – A matrix filled in with the height (z) values. Each dimension must be at least size 2
  • position (triple float (optional)) – The center position of the height map. (default is [0, 0, 0])
  • size (float, tuple float (optional)) – The length of each side. When a singular value, height map is a square. (default is (10, 10))
  • height_scale (float (optional)) – Height multiplier. (default is 1.0)
send_hidden_neuron(alpha=1.0, tau=1.0, starting_value=0.0)

Send a hidden neuron to the simulator

send_hinge_joint(body1, body2, anchor, axis=(0, 0, 1), joint_range=None)

Send a hinge joint to the simulator to attach two bodies

A hinge joint allows bodies to rotate in relation to one another about the specified axis. By using -1 in place of a body id tag the joint will connect a point in space to the other body. Specifying joint_range places stopping limits on the joint.

Parameters:
  • body1 (int) – The id tag of the first body. Specify -1 in order to set body1 to the ‘world’
  • body2 (int) – The id tag of the second body. Specify -1 in order to set body2 to the ‘world’
  • anchor (triple float) – The location of the joint.
  • axis (triple float (optional)) – The axis the bodies rotate about. (default is about the z-axis [0, 0, 1])
  • joint_range (float or tuple (optional)) – The range of movement the joint can take in radians. The starting joint position is always at 0. By specifying a single value, a, the joint range becomes (-a, +a). You can also directly specify the low and high stops by directly specifying the tuple. (default is None meaning there are no stops)
Returns:

Id tag of the joint

Return type:

int

send_hinge_spring_joint(body1, body2, stiffness=1.0, axis1=(0, 1, 0), axis2=(0, 0, 1), damping=0.0)

Sends a linear spring with infinite rotational stiffness

send_is_seen_sensor(body_id, write_back=True)

Attach a sensor to a body which reports a 1 when ‘seen’ by a ray sensor and a 0 when not ‘seen’

Parameters:
  • body_id (int) – The id tag of the body to attach sensor to
  • write_back (bool) – If True, write back to python after simulation. (Default True)
Returns:

The id tag of the sensor

Return type:

int

send_light_sensor(body_id, write_back=True)

Send a light sensor embedded within a body

Parameters body_id : int

The id tag of the specified body
write_back : bool
If True, write back to python after simulation. (Default True)
Returns:The id tag of the sensor
Return type:int
send_linear_actuator(joint_id, max_force=-1, speed=1.0, control='positional')

Sends a linear actuator to acto on a slider joint

Parameters:
  • joint_id (int) – The id tag of the slider joint to motorize
  • max_force (float (optional)) – The maximum amount of force the joint can use to move. A negative value indicates infinite possible force. (default is infinite)
  • speed (float (optional)) – The speed multiplier used in actuation. (default is 1)
  • control (str (optional)) – There are two control schemes: ‘positional’ and ‘velocity’. positional indicates the value inputed dictates which position the motor should move to. velocity indicates the value inputed should specify the velocity of actuation.
Returns:

The id tag of the actuator

Return type:

int

send_linear_spring_joint(body1, body2, resting_length=1.0, stiffness=1.0, damping=0.0)

Sends a linear spring with infinite rotational stiffness

send_motor_neuron(motor_id, alpha=0.0, tau=1.0, starting_value=0.0)

Send a motor neuron to the simulator

The value of the motor neuron at each time step is passed to the specified motor in order to determine how it should actuate.

Parameters:
  • motor_id (float) – The id tag of the motor to send neuron value to
  • alpa (float (optional)) – A ‘learning rate’ parameter. (default is 0)
  • tau (float (optional)) – A ‘learning rate’ parameter. (default is 1.0)
  • starting_value (float (optional)) – The starting value the neuron takes. Could be usefully when motor does not start at 0. (default is 0)
Returns:

The id tag of the neuron

Return type:

int

send_point_mass_spring_joint(body1, body2, resting_length=1.0, stiffness=1.0, damping=0.0)

Sends a spring which simply maintains a certain length between two bodies

send_position_sensor(body_id, which_dimension='x', write_back=True)

Send position sensor which tracks the body specified in body_id

Parameters:
  • body_id (int) – The id tag of the specifed body
  • which_dimension (str or int (optional)) – Specifies which dimension to track: ‘x’, ‘y’, or ‘z’. You can also use 0, 1, or 2. (default is ‘x’)
  • write_back (bool) – If True, write back to python after simulation. (Default True)
Returns:

The id tag of the sensor

Return type:

int

send_position_x_sensor(body_id, write_back=True)

Send x position sensor which tracks the body specified in body_id

send_position_y_sensor(body_id, write_back=True)

Send y position sensor which tracks the body specified in body_id

send_position_z_sensor(body_id, write_back=True)

Send z position sensor which tracks the body specified in body_id

send_proprioceptive_sensor(joint_id, write_back=True)

Attach a proprioceptive sensor to the joint.

Proprioceptive sensors return the value of the joint at each time step. For example, a hinge joint will return the angle and a slider joint will return the position offset.

Note

Currently not implemented for universal or ball joints. Attached proprioceptive sensors will only return 0.

Parameters:
  • joint_id (int) – The id tag of the joint to attach the sensor to
  • write_back (bool) – If True, write back to python after simulation. (Default True)
Returns:

The id tag of the sensor

Return type:

int

send_quaternion_sensor(body_id, which_sense='a', write_back=True)

Attach a vestibular sensor returning the quaternion of the body.

Quaternions is 4 element vector which can represent the rotation of a body. It’s components are a, b, c, and d. You can also use w, x, y, and z. Read more here: https://en.wikipedia.org/wiki/Quaternion

send_ray(body_id, position, direction, max_length=10.0)

Send a ray entity and attach to a body

Parameters:
  • body_id (int) – The body entity id to attach to
  • position (triple float) – The starting position of the ray.
  • direction (triple float) – The starting orientation of the ray
  • max_length (float) – The total length the ray can sense
send_ray_blue_sensor(ray_id, write_back=True)

Send a blue color sensor attached to the ray at ray_id

send_ray_distance_sensor(ray_id, write_back=True)

Send a distance sensor attached to the ray at ray_id

send_ray_green_sensor(ray_id, write_back=True)

Send a green color sensor attached to the ray at ray_id

send_ray_red_sensor(ray_id, write_back=True)

Send a red color sensor attached to the ray at ray_id

send_ray_sensor(ray_id, which_sense='d', write_back=True)

Sends a ray sensor to the simulator.

Ray sensors connect to ray entities. They can return the distance to this object or the color of this object (r, g, b).

Parameters:
  • ray_id (int) – The id tag of the ray to attach to.
  • which_sense (str or int (optional)) – Specifies which sense of the ray to return. Use ‘d’ for distance, ‘r’ for red, ‘g’ for green, ‘b’ for blue.
  • write_back (bool) – If True, write back to python after simulation. (Default True)
Returns:

the id tag of the sensor.

Return type:

int

send_rotary_actuator(joint_id, max_force=-1, speed=1.0, control='positional')

Sends a rotary actuator to acto on a hinge joint

Parameters:
  • joint_id (int) – The id tag of the hinge joint to motorize
  • max_force (float (optional)) – The maximum amount of torque the joint can use to move. A negative value indicates infinite possible torque. (default is infinite)
  • speed (float (optional)) – The speed multiplier used in actuation. (default is 1)
  • control (str (optional)) – There are two control schemes: ‘positional’ and ‘velocity’. positional indicates the value inputed dictates which angle the motor should move to. velocity indicates the value inputed should specify the velocity of actuation.
Returns:

The id tag of the actuator

Return type:

int

send_sensor_neuron(sensor_id)

Send a sensor neuron to the simulator

Parameters:sensor_id (int) – The id tag of the sensor to pull values from at each time step.
Returns:The id tag of the neuron
Return type:int
send_slider_joint(body1, body2, axis=(0, 0, 1), joint_range=0.5)

Send a slider joint to the simulator

Slider joints allow two bodies to move linearly in relation to one another according to the specified axis.

Parameters:
  • body1 (int) – The id tag of the first body. Specify -1 in order to set body1 to the ‘world’
  • body2 (int) – The id tag of the second body. Specify -1 in order to set body2 to the ‘world’
  • axis (triple of floats (optional)) – The axis of the slider joint. (default is along the z-axis [0, 0, 1])
  • joint_range (float or tuple of floats (optional)) – The limits the slider can move. By specifying a single float, a, high and low limits are create (-a, a). (default is 0.5)
Returns:

Id tag of the joint

Return type:

int

send_sphere(position=(0.0, 0.0, 0.0), orientation=(0.0, 0.0, 1.0), radius=0.25, density=1.0, color=(1.0, 1.0, 1.0), space=None, collision_group=None)

Send a sphere geometry to the simulator

Parameters:
  • position (triple float (optional)) – The global position of the body. (default [0, 0, 0])
  • orientation (triple float (optional)) – The gloabl orientation of the body. (default [0, 0, 1])
  • radius (float (optional)) – The radius of the sphere. (default 0.25)
  • density (float (optional)) – The density of the body
  • color (triple float (optional)) – Color of the body. (default is [1, 1, 1])
  • space (str (optional)) – The string name of the space in which to place the body. (default is to use the string set by set_current_space() function)
  • collision_group (str (optional)) – The string name of the collision group in which to place the body. Collision groups specify how bodies collide. (default is to use the string set by set_current_collision_group() function)
Returns:

The id tag of the shpere

Return type:

int

send_synapse(source_neuron_id, target_neuron_id, weight)

Send a synapse to the simulator to connect neurons

Parameters:
  • source_neuron_id (int) – The id tag of the source neuron
  • target_neuron_id (int) – The id tag of the target neuron
  • weight (float) – The weight value of the synapse
Returns:

The id tag of the synapse

Return type:

int

send_thruster(body_id, force_range=(0.0, 10.0), direction=(0.0, 0.0, 1.0))

Sends a thruster to a body.

Thrusters act as forces pushing on the center of mass in the specified direction.

Parameters:
  • body_id (int) – The id tag of the body to connect to.
  • force_range (float tuple (optional)) – A tuple which specifies the low and high range of force used to apply to the attached body. (default is (0, 10))
  • direction (float triple (optional)) – The direction the force should be applied. For example, if you want the thruster to move the body upward you would set direction to be upward, i.e. direction = (0, 0, 1)
Returns:

The id tag of the thruster

Return type:

int

send_touch_sensor(body_id, write_back=True)

Attach a touch sensor to a body

Parameters:body_id (int) – The id tag of the body to attach the sensor to
Returns:
  • int – The id tag of the sensor
  • write_back (bool) – If True, write back to python after simulation. (Default True)
send_universal_joint(body1, body2, anchor, axis1=(0, 0, 1), axis2=(1, 0, 0))

Send a ball and socket joint to the simulator

Universal joints allow rotation about two axes.

Parameters:
  • body1 (int) – The id tag of the first body. Specify -1 in order to set body1 to the ‘world’
  • body2 (int) – The id tag of the second body. Specify -1 in order to set body2 to the ‘world’
  • anchor (triple of floats) – The absolute starting world position of the joint.
  • axis1 (triple of floats (optional)) – The first axis of rotation. (Default is (0, 0, 1))
  • axis2 (triple of floats (optional)) – The second axis of rotation. (Default is (1, 0, 0))
send_universal_spring_joint(body1, body2, resting_length=1.0, linear_stiffness=1.0, rotational_stiffness=10.0)

Sends a spring

send_user_neuron(input_values)

Send a user input neuron to the simulator.

A user input neuron takes pre-specified input supplied by the user before simulation. Similar to a bias neuron that changes every time step. This is useful to send Central Pattern Generators and other functions.

Parameters:input_values (list) – The values which the neuron will take every time step. If evaluation time is longer than the length of the list, the values will be repeated
Returns:The id tag of the neuron.
Return type:int
set_camera(xyz, hpr, tracking='none', body_to_track=0)[source]

Sets how the camera starts in simulation

Parameters:
  • xyz (triple float) – Indicates the statring position of the camera
  • hpr (triple float) – Heading, Pitch, and Roll of the camera.
  • tracking (string) – No tracking, pan tracking, or follow tracking
  • body_to_track (body id) – Body to have to camera follow
set_current_collision_group(group_name)[source]

Set the current group name for future bodies to use as default

set_current_space(space_name)[source]

Set the current space name for future bodies to use as default

set_gravity(x=0, y=0, z=-9.8)[source]

Set the gravity for simulation

set_network_update_interval(steps_between_evals)[source]

The number of evaluation steps between network updates.

Allows for larger time steps between computing an iteration of the network controller.

Note

May produce unexpected results, use with caution.

Parameters:int (steps_between_evals,) – a update_network value of 1 means the network is updated every simulation step, a value of 10 means the network updates every 10 eval steps.
start()[source]

Start the simulation

wait_to_finish()[source]

Communicate with pipe once simulation is complete

Note

for python 3.x it is necessary to use this command after sim.start() in order for the simulation to run properly.