This step involves importing the required modules and initializing key components for our tasks.
from pycram.designators.action_designator import Object, LocalTransformer, BulletWorld, Transform
Unknown attribute "type" in /robot[@name='pr2']/link[@name='base_laser_link'] Unknown attribute "type" in /robot[@name='pr2']/link[@name='wide_stereo_optical_frame'] Unknown attribute "type" in /robot[@name='pr2']/link[@name='narrow_stereo_optical_frame'] Unknown attribute "type" in /robot[@name='pr2']/link[@name='laser_tilt_link']
Every robot simulation requires a world where it can interact. This world serves as the playground where the robot performs tasks. Let's start by creating this world and setting the appropriate gravitational force to simulate Earth's gravity.
# Create an instance of the BulletWorld
world = BulletWorld()
# Set the gravitational force to simulate Earth's gravity
world.set_gravity([0, 0, -9.8])
Exception in thread Thread-10: Traceback (most recent call last): File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/oem/pycram_ws/src/pycram/src/pycram/bullet_world.py", line 536, in run basePosition=cameraTargetPosition) UnboundLocalError: local variable 'cameraTargetPosition' referenced before assignment
startThreads creating 1 threads. starting thread 0 started thread 0 argc=2 argv[0] = --unused argv[1] = --start_demo_name=Physics Server ExampleBrowserThreadFunc started X11 functions dynamically loaded using dlopen/dlsym OK! X11 functions dynamically loaded using dlopen/dlsym OK! Creating context Created GL 3.3 context Direct GLX rendering context obtained Making context current GL_VENDOR=NVIDIA Corporation GL_RENDERER=NVIDIA GeForce RTX 2060/PCIe/SSE2 GL_VERSION=3.3.0 NVIDIA 525.125.06 GL_SHADING_LANGUAGE_VERSION=3.30 NVIDIA via Cg compiler pthread_getconcurrency()=0 Version = 3.3.0 NVIDIA 525.125.06 Vendor = NVIDIA Corporation Renderer = NVIDIA GeForce RTX 2060/PCIe/SSE2 b3Printf: Selected demo: Physics Server startThreads creating 1 threads. starting thread 0 started thread 0 MotionThreadFunc thread started
Unknown tag "material" in /robot[@name='plane']/link[@name='planeLink']/collision[1] Unknown tag "contact" in /robot[@name='plane']/link[@name='planeLink'] Unknown tag "material" in /robot[@name='plane']/link[@name='planeLink']/collision[1] Unknown tag "contact" in /robot[@name='plane']/link[@name='planeLink']
For our robot to perform meaningful tasks, we need to populate its world with objects. In this section, we'll add a variety of objects, from a simple floor plane to kitchen setups and items like milk and bowls. These objects will be used in subsequent tasks.
plane = Object("floor", "environment", "plane.urdf", world=world)
from pycram.designators.object_designator import *
kitchen = Object("kitchen", "environment", "kitchen.urdf")
milk = Object("milk", "milk", "milk.stl", Pose([0.9, 1, 0.95]))
bowl = Object("bowl", "bowl", "bowl.stl", Pose([1.6, 1, 0.90]))
Unknown tag "material" in /robot[@name='plane']/link[@name='planeLink']/collision[1] Unknown tag "contact" in /robot[@name='plane']/link[@name='planeLink'] Scalar element defined multiple times: limit Unknown tag "material" in /robot[@name='plane']/link[@name='planeLink']/collision[1] Unknown tag "contact" in /robot[@name='plane']/link[@name='planeLink'] Scalar element defined multiple times: limit
Transformations with LocalTransformer Now that we have our world set up, let's perform some transformations. We'll use the LocalTransformer to transform poses relative to our objects.
l = LocalTransformer()
test_pose = Pose([1, 1, 1], [0, 0, 0, 1], "map")
p = Pose()
transformed_pose = l.transform_to_object_frame(p, milk)
print(transformed_pose)
new_pose = l.transform_pose(transformed_pose, "map")
print(new_pose)
header: seq: 0 stamp: secs: 1694191335 nsecs: 125374555 frame_id: "milk_3" pose: position: x: -0.9 y: -1.0 z: -0.95 orientation: x: 0.0 y: 0.0 z: 0.0 w: 1.0 header: seq: 0 stamp: secs: 1694191335 nsecs: 126070022 frame_id: "map" pose: position: x: 0.0 y: 0.0 z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 1.0
In the above code, we first transformed a pose to the object frame of the milk object, and then we transformed it back to the map frame. This demonstrates how we can easily manipulate poses relative to objects in our environment. You can also transform poses relative to other poses. by using the transform_pose method. Further u can set a Transform.
l.setTransform(Transform([1, 1, 1], [0, 0, 0, 1], "map", "test_frame"))
p = Pose()
transformed_pose = l.transform_pose(p, "test_frame")
You can also set a Pose to an object and update the transforms for that object.
milk.set_pose(Pose([1, 2, 1]))
l.update_transforms_for_object(milk)