Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
doc:pycram:bulletworld [2022/11/04 15:01] jdechdoc:pycram:bulletworld [2022/11/07 12:07] (current) jdech
Line 122: Line 122:
 Since some methods especially the geometric reasoning need to modify the position of objects it is necessary to have a second Bullet World, so the second Bullet World can be modified without changing the state of the main Bullet World. This is mainly required to have a consistent belief state. This is what shadow worlds provide.  Since some methods especially the geometric reasoning need to modify the position of objects it is necessary to have a second Bullet World, so the second Bullet World can be modified without changing the state of the main Bullet World. This is mainly required to have a consistent belief state. This is what shadow worlds provide. 
  
-A shadow world is a second Bullet World that mirrors the main Bullet World +A shadow world is a second Bullet World that mirrors the main Bullet World, so everything that happens in the main Bullet World will be reflected in the shadow world. This happens completely autonomous by the World_Sync class, this class runs in a separate thread and spawns, removes and changes the location of objects in the shadow world. 
  
 +===== World Sync ===== 
 +The World Sync synchronizes the shadow world with the main Bullet World, it basically provides the "shadow" functionality. This module runs in a seperate thread and checks every 0.1 seconds if there are objects that need to be added or removed from the shadow world. Checking if anything should be added or removed is done by two queues, anytime an object in the main Bullet World is added or removed there will be a new entry added to the queue with every necessary information. The World Sync then checks if there are any entries in the queue and processes them. 
 +
 +There is also an object mapping which maps the objects of the main Bullet World to the corresponding objects in the shadow world.
 +
 +
 +===== Using the shadow world ===== 
 +To use the shadow world you have to import Use_shadow_world from pycram.bullet_world and use it in a "with" environment, in this environment you can use the BulletWorld.current_bullet_world variable which points at the shadow world. 
 +
 +There are also two methods for retrieving the corresponding object of the other world, these are get_shadow_object and get_bullet_object_for_shadow.
 +
 +<code>
 +from pycram.bullet_world import BulletWorld, Object, Use_shadow_world 
 +
 +world = BulletWorld()
 +milk = Object("milk", "milk", "milk.stl")
 +shadow_milk = world.get_shadow_object(milk)
 +
 +with Use_shadow_world():
 +    shadow_milk.set_position([0,0, 1])
 +    BulletWorld.current_bullet_world.simulate(10)
 +</code>