concepts.simulator.pymunk.default_env.PymunkDefaultEnv#

class PymunkDefaultEnv[source]#

Bases: object

A basic 2D physics environment based on pymunk.

The main function to be implemented by subclasses is reset_scene.

Methods

add_additional_drawing_region_circle(center, ...)

add_additional_drawing_region_rect(top_left, ...)

can_control(body)

Check if the body can be controlled by the user.

get_jittered_velocity(velocity)

get_observation()

Get an observation dict of the current state of the environment.

humanplay_mainloop()

Run a mainloop so that the user can control the objects in the environment.

non_physical_execute_trajectory(body_name, ...)

Execute a trajectory without physical simulation.

render()

Render the environment.

render_and_display([render_mode, trajectory])

reset(**kwargs)

reset_scene(**kwargs)

reset_world()

set_additional_step_callable(fn)

set_current_selection(body)

start_recording()

step(steps[, render_mode, callback])

Step the simulation for a number of steps.

stop_recording()

Attributes

__init__(damping=0.0, gravity=(0., 0.), world_width=800, world_height=800, fps=60, action_velocity=100, velocity_jitter=0.0, direction_jitter=0.0, display=True, render_fps=None)[source]#
Parameters:
__new__(**kwargs)#
add_additional_drawing_region_circle(center, radius, color)[source]#
Parameters:
add_additional_drawing_region_rect(top_left, bottom_right, color)[source]#
Parameters:
can_control(body)[source]#

Check if the body can be controlled by the user. This function can be overridden by subclasses.

Return type:

bool

get_jittered_velocity(velocity)[source]#
Parameters:

velocity (Tuple[float, float])

Return type:

Tuple[float, float]

get_observation()[source]#

Get an observation dict of the current state of the environment.

humanplay_mainloop()[source]#

Run a mainloop so that the user can control the objects in the environment.

non_physical_execute_trajectory(body_name, trajectory)[source]#

Execute a trajectory without physical simulation. This is done by manually setting the positions of the bodies.

Parameters:
  • body_name (str) – the name of the body to be moved.

  • trajectory (List[Tuple[float, float]]) – a list of positions to be set to the body.

Return type:

None

render()[source]#

Render the environment. If recording is enabled, the rendered frames will be stored in the recorded_frames list. Use start_recording() and stop_recording() to control the recording process.

The rendering is done by calling the debug_draw method of the PymunkWorld object.

Return type:

None

render_and_display(render_mode='image', trajectory=None)[source]#
Parameters:
  • render_mode (str | None)

  • trajectory (List[Any] | None)

Return type:

None

reset(**kwargs)[source]#
reset_scene(**kwargs)[source]#
reset_world()[source]#
Return type:

PymunkWorld

set_additional_step_callable(fn)[source]#
Parameters:

fn (Callable[[PymunkDefaultEnv], None])

set_current_selection(body)[source]#
Parameters:

body (Body)

start_recording()[source]#
step(steps, render_mode='image', callback=None)[source]#

Step the simulation for a number of steps.

Parameters:
  • steps (int) – the number of steps to be executed.

  • render_mode (str | None) – the mode of rendering. Can be one of [‘image’, ‘human’, ‘pose’, ‘state’]. Set to None to disable any rendering.

  • callback (Callable[[], bool] | None) – a callback function that returns False to stop the simulation.

Return type:

List[Any]

stop_recording()[source]#
RENDER_MODES = ['image', 'human', 'pose', 'state']#
SCREENSHOT_TITLE = 'screenshot'#
TITLE = 'Pymunk Default'#