This is an old revision of the document!
Bullet World
The BulletWorld is the environment in which all actions will be simulated. The BulletWorld class provides mainly methods controlling the simulation as well as getting objects that are present within the simulation. The BulletWorld uses the PyBullet library to realize the physics simulation and thus can be considered as a wrapper around the functionality of PyBullet.
Because PyBullet allows more than one physics client it is also possible with the BulletWorld. In other words, the user can have multiple instances of the BulletWorld,each with different scenarios.
A BulletWorld instance can be either of type direct or gui. With type direct there is no visible feedback of the actions in the simulation andthe simulation can only be affected by methods that change the status of an object.
In gui mode, however, there is a window in which the simulation is displayed and the objects can be dragged around with the mouse.
Because of technical restrictions it is only possible to have one graphical simulation, the rest will have to be executed in direct mode.
The following table lists all methods provided by the Bullet World class. There are methods to get objects from the BulletWorld either by their name, type or id, to set the gravity, and to simulate the BulletWorld for a given time. Furthermore, all event references are stored so that all events are unique for each instance of the BulletWorld. Currently, the only events available are for attachment, detachment, and manipulation.
Method | Parameter | Description |
---|---|---|
get_objects_by_name | string | Returns a list of all objects with the given name. |
get_object_by_id | int | Returns the object corresponding to the given ID. |
get_attachment_event | None | Returns the instance of the event which is called when two objects are attached. |
get_detachment_event | None | Returns the instance of the event which is called when two objects are detached. |
get_manipulation_event | None | Returns the instance of the event which is called when the environment was manipulated. |
set_realtime | Bool | Sets the realtime in the simulation to True or False. |
set_gravity | list[float] | Sets the gravity of the simulation to the given 3-dimensional vector. |
simualte | float | Runs the simualtion for a given amount of seconds. |
exit | None | Terminates the simulation. |
The simulation in PyBullet works in steps, where every step equals approximately 1/240 seconds. Some methods of PyBullet need a simulation step to work: For example, the collision detection may only function if the step_simulation method was executed at least once before.
The simulate method takes the amount of seconds that should be simulated as a float, so that it is also possible to simulate fractions of a second. Next, the method loops the exact number of steps to simulate the given time.
Simulations can be ended using the exit method. This sets the current_bullet_world to an active BulletWorld and collects the threads. It is mainly used for working with multiple Bullet Worlds because problems may arise if one of the instances is not correctly terminated. Otherwise, the threads would not be collected and continue to allocate RAM. When working with only one it is not necessary to use the exit method, though it is recommended to do so.
Current Bullet World
The current_bullet_world variable is the default world for all methods. It will always point to the last initialized BulletWorld. To ensure that the current_bullet_world always points on a valid BulletWorld every, instance saves the previous current_bullet_world and resets it once it is finished; making this effectively a single linked list.