Robowflex  v0.1
Making MoveIt Easy
robowflex.py
Go to the documentation of this file.
1 import importlib
2 import robowflex_visualization as rv
3 import math
4 
5 # reload modules, as Blender likes to keep things around.
6 importlib.reload(rv)
7 importlib.reload(rv.robot)
8 importlib.reload(rv.scene)
9 importlib.reload(rv.primitives)
10 importlib.reload(rv.utils)
11 
12 # Load a Fetch robot.
13 fetch = rv.robot.Robot("Fetch", "package://robowflex_resources/fetch/robots/fetch.urdf")
14 
15 # Open the Gripper
16 fetch.set_joint("l_gripper_finger_joint", 0.05)
17 fetch.set_joint("r_gripper_finger_joint", 0.05)
18 
19 # Keyframe the head at neutral
20 fetch.set_joint("head_pan_joint", 0)
21 fetch.set_joint("head_tilt_joint", 0)
22 fetch.add_keyframe("head_pan_joint", 0)
23 fetch.add_keyframe("head_tilt_joint", 0)
24 
25 # Keyframe the head looking over at the block
26 fetch.set_joint("head_pan_joint", math.radians(50))
27 fetch.set_joint("head_tilt_joint", math.radians(30))
28 fetch.add_keyframe("head_pan_joint", 60)
29 fetch.add_keyframe("head_tilt_joint", 60)
30 
31 # Load a planning scene.
32 scene = rv.scene.Scene("Scene",
33  "package://robowflex_library/yaml/test_fetch.yml")
34 
35 # Animate a simple motion plan.
36 frame = fetch.animate_path(
37  "package://robowflex_visualization/yaml/fetch_pick.yml",
38  15, # FPS
39  30, # Start Frame
40 )
41 
42 # Keyframe the gripper at opening
43 fetch.add_keyframe("l_gripper_finger_joint", frame)
44 fetch.add_keyframe("r_gripper_finger_joint", frame)
45 
46 # Keyframe head still looking over
47 fetch.add_keyframe("head_pan_joint", frame)
48 fetch.add_keyframe("head_tilt_joint", frame)
49 
50 # Attach the cube to the gripper
51 cube = scene.get_object("Cube3")
52 fetch.attach_object("wrist_roll_link", cube, frame)
53 
54 # Close the Gripper
55 fetch.set_joint("l_gripper_finger_joint", 0.04)
56 fetch.set_joint("r_gripper_finger_joint", 0.04)
57 fetch.add_keyframe("l_gripper_finger_joint", frame + 30)
58 fetch.add_keyframe("r_gripper_finger_joint", frame + 30)
59 
60 # Animate the plan in reverse
61 frame = fetch.animate_path(
62  "package://robowflex_visualization/yaml/fetch_pick.yml",
63  15, # FPS
64  frame + 30, # Start Frame
65  True, # Reverse the Motion
66 )
67 
68 # Keyframe head returning to neutral
69 fetch.set_joint("head_pan_joint", 0)
70 fetch.set_joint("head_tilt_joint", 0)
71 fetch.add_keyframe("head_pan_joint", frame)
72 fetch.add_keyframe("head_tilt_joint", frame)