roboball2d.physics package¶
Submodules¶
roboball2d.physics.b2_robot module¶
-
class
roboball2d.physics.b2_robot.
B2Robot
(robot, b2_world, ground)¶ Bases:
object
Specifies the interface required by
roboball2d.physics.B2World
to update the state of a robot. Seeroboball2d.physics.DefaultB2Robot
for an example of a class inherating from B2Robot.-
__init__
(robot, b2_world, ground)¶ Initialize self. See help(type(self)) for accurate signature.
-
apply_generalized_torques
(generalized_torques)¶ Apply generalized torques and return actually applied generalized torques.
-
get_state
()¶
-
set_state
(robot)¶
-
roboball2d.physics.b2_world module¶
-
class
roboball2d.physics.b2_world.
B2World
(robot_configs, ball_configs, visible_area_width, steps_per_sec=100.0, gravitational_acceleration=-8.0, vel_iters=10, pos_iters=8)¶ Bases:
object
Engine using b2box to update the dynamics of robot(s) and ball(s).
- robot_configs :
- instance (or list of instances)
of
roboball2d.robot.default_robot_config.DefaultRobotConfig
If a list of instances is passed, several simulated robots will be created. - ball_configs :
- instance (or list of instances)
of
roboball2d.ball.ball_config.BallConfig
if a list of instances is passed, several simulated balls will be created. - visible_width_area: float
- width of the world ground (width of possible contact between object and floor)
steps_per_second: float
at each call of
roboball2d.physics.b2_world.B2World.step()
, a time step of 1.0 / steps_per_second will be applied (except if an argument current_time is passed to step,- gravitational_acceleration: float
- gravity
- vel_iters : int
- ???
- pos_iters : int
- ???
-
__init__
(robot_configs, ball_configs, visible_area_width, steps_per_sec=100.0, gravitational_acceleration=-8.0, vel_iters=10, pos_iters=8)¶ - robot_configs :
- instance (or list of instances)
of
roboball2d.robot.default_robot_config.DefaultRobotConfig
If a list of instances is passed, several simulated robots will be created. - ball_configs :
- instance (or list of instances)
of
roboball2d.ball.ball_config.BallConfig
if a list of instances is passed, several simulated balls will be created. - visible_width_area: float
- width of the world ground (width of possible contact between object and floor)
steps_per_second: float
at each call of
roboball2d.physics.b2_world.B2World.step()
, a time step of 1.0 / steps_per_second will be applied (except if an argument current_time is passed to step,- gravitational_acceleration: float
- gravity
- vel_iters : int
- ???
- pos_iters : int
- ???
-
balls
¶
-
ground
¶
-
reset
(init_robot_state=None, ball_gun=None, reset_time=True)¶ Reset the simulation
- init_robot_state :
- if not None,
instance of
roboball2d.robot.default_robot_state.DefaultRobotState
, speciying the new state of the robot. A list of instance must be passed if several robots are managed. - ball_gun :
- Instance of an object having a shoot method specifying the new position,
velocity and spin of the ball (or list of instance if several balls
are managed. There must be as many ball_guns as managed balls. None can
be passed for balls which should not be reset. An error is thrown otherwise).
See for example
roboball2d.ball_gun.default_ball_gun.DefaultBallGun
- reset_time :
- if true, the internal time of the simulation is reset to 0
An instance of
roboball2d.physics.world_state.WorldState
which captures the state of all items managed by the simulation (after the step).
-
robots
¶
-
step
(all_torques, relative_torques=False, current_time=None, mirroring_robot_states={}, mirroring_ball_states={})¶ Performs a simulation step.
- all_torques :
- list of 3 torques (for a single robot) or list of list of 3 torques (for several robots) to apply to the joints
- relative torques : Bool
- if true, the torques specified do not use absolute value, but relative values between -1 and 1 (that will be mapped between (-max torque, +max torque)
- current_time : float
- if provided, the time step will not be based on the step per second
(
roboball2d.physics.b2_world.B2World
but based on the current_time argument passed during the previous call to step - mirroring_robot_states: dict
- dictionary {index:robot_state}, with robot state being an instance
of
roboball2d.robot.default_robot_state.DefaultRobotState
. This will force the robot of the specified index to take the specified state, overwriting all control and dynamics. - mirroring_ball_states: dict
- dictionary {index:item}, with item being an instance
of
roboball2d.Item
, encoding for the balls at the specified indexes the position, angle, linear_velocity and angular_velocity that should be used to overwrite the current state of the ball.
An instance of
roboball2d.physics.world_state.WorldState
which captures the state of all items managed by the simulation (after the step).
roboball2d.physics.default_b2_robot module¶
-
class
roboball2d.physics.default_b2_robot.
DefaultB2Robot
(robot_config, b2_world, ground)¶ Bases:
roboball2d.physics.b2_robot.B2Robot
(Advanced usage)
Instances of DefaultB2Robot will be created internally by
roboball2d.physics.b2_world.B2World
based on the attributes of the instane of roboball2d.robot.default_robot_config.DefaultRobotConfig passed to its constructor.Users code is not expected to create new instances of DefaultB2Robot.
Advanced users may create new robot configuration object and new B2Robot object (inheriting from
robotball2d.physics.b2_robot.B2Robot
) to fine tune how B2World manages the dynamics of robots.-
__init__
(robot_config, b2_world, ground)¶ Initialize self. See help(type(self)) for accurate signature.
-
apply_generalized_torques
(generalized_torques)¶ Apply generalized torques and return actually applied generalized torques.
-
get_state
(desired_torques, applied_step=None)¶
-
set_state
(robot_state)¶
-
roboball2d.physics.world_state module¶
-
class
roboball2d.physics.world_state.
WorldState
(robot_configs, ball_configs)¶ Bases:
object
An instance of WorldState captures the state of all object of a simulation. Returned for example by
roboball2d.physics.b2_world.B2World.reset()
androboball2d.physics.b2_world.B2World.step()
and- robot_configs:
- list of the configurations of the robots managed by the simulation see : py:class:roboball2d.robot.default_robot_configuration.DefaultRobotConfiguration
- robot_config:
- instance at index 0 of robot_configs
- ball_configs:
- list of the configurations of the balls managed by the simulation see : py:class:roboball2d.ball.ball_configuration.BallConfiguration
- t: float
- current simulation time (in seconds)
- applied_time_step: float
- duration of the time step applied (in seconds)
- robots:
- list of states of robots,
see
roboball2d.robot.default_robot_state.DefaultRobotState
- robot:
- instance at index 0 of robots
- balls :
- list of ball items, see
roboball2d.item.Item
- ball :
- instance at index 0 of balls
- balls_hits_floor:
- list of float or None values, one per managed ball. None at a given index means the ball at this index did not hit the floor during the last simulation step. A float gives the x position at which the ball touched the floor.
- ball_hits_floor:
- value at index 0 of balls_hits_floor.
- balls_hits_racket:
- list of index or None values, one per managed ball. None at a given index means the ball at this index did not hit any racket during the last simulation step. An integer gives the index of the robot which racket the ball touched.
- ball_hits_racket:
- value at index 0 of balls_hits_racket
-
__init__
(robot_configs, ball_configs)¶ Initialize self. See help(type(self)) for accurate signature.
-
applied_time_step
¶
-
ball
¶
-
ball_config
¶
-
ball_configs
¶
-
ball_hits_floor
¶
-
ball_hits_racket
¶
-
balls
¶
-
balls_hits_floor
¶
-
balls_hits_racket
¶
-
robot
¶
-
robot_config
¶
-
robot_configs
¶
-
robots
¶
-
t
¶