Skip to content

Commit 3bd2735

Browse files
committed
Add examples for lecture 05
1 parent f5f3421 commit 3bd2735

15 files changed

+4020
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from compas.geometry import Frame
2+
from compas_fab.backends import RosClient
3+
from compas_fab.robots import Configuration
4+
5+
with RosClient('localhost') as client:
6+
robot = client.load_robot()
7+
group = robot.main_group_name
8+
9+
frames = []
10+
frames.append(Frame([0.3, 0.1, 0.5], [1, 0, 0], [0, 1, 0]))
11+
frames.append(Frame([0.5, 0.1, 0.6], [1, 0, 0], [0, 1, 0]))
12+
13+
start_configuration = Configuration.from_revolute_values([-0.042, 0.033, -2.174, 5.282, -1.528, 0.000])
14+
15+
trajectory = robot.plan_cartesian_motion(frames,
16+
start_configuration,
17+
group=group,
18+
options=dict(
19+
max_step=0.01,
20+
avoid_collisions=True,
21+
))
22+
23+
print("Computed cartesian path with %d configurations, " % len(trajectory.points))
24+
print("following %d%% of requested trajectory." % (trajectory.fraction * 100))
25+
print("Executing this path at full speed would take approx. %.3f seconds." % trajectory.time_from_start)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from compas.geometry import Frame
2+
from compas_fab.backends import RosClient
3+
from compas_fab.robots import Configuration
4+
from helpers import show_trajectory
5+
6+
with RosClient('localhost') as client:
7+
robot = client.load_robot()
8+
group = robot.main_group_name
9+
10+
frames = []
11+
frames.append(Frame([0.3, 0.1, 0.5], [1, 0, 0], [0, 1, 0]))
12+
frames.append(Frame([0.5, 0.1, 0.6], [1, 0, 0], [0, 1, 0]))
13+
14+
start_configuration = Configuration.from_revolute_values([-0.042, 0.033, -2.174, 5.282, -1.528, 0.000])
15+
16+
trajectory = robot.plan_cartesian_motion(frames,
17+
start_configuration,
18+
group=group,
19+
options=dict(
20+
max_step=0.01,
21+
avoid_collisions=True,
22+
))
23+
24+
print("Computed cartesian path with %d configurations, " % len(trajectory.points))
25+
print("following %d%% of requested trajectory." % (trajectory.fraction * 100))
26+
print("Executing this path at full speed would take approx. %.3f seconds." % trajectory.time_from_start)
27+
28+
show_trajectory(trajectory)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import math
2+
from compas.geometry import Frame
3+
from compas_fab.backends import RosClient
4+
from compas_fab.robots import Configuration
5+
6+
with RosClient('localhost') as client:
7+
robot = client.load_robot()
8+
group = robot.main_group_name
9+
10+
frame = Frame([0.4, 0.3, 0.4], [0, 1, 0], [0, 0, 1])
11+
tolerance_position = 0.001
12+
tolerance_axes = [math.radians(1)] * 3
13+
14+
start_configuration = Configuration.from_revolute_values([-0.042, 4.295, 0, -3.327, 4.755, 0.])
15+
16+
# create goal constraints from frame
17+
goal_constraints = robot.constraints_from_frame(frame,
18+
tolerance_position,
19+
tolerance_axes,
20+
group)
21+
22+
trajectory = robot.plan_motion(goal_constraints,
23+
start_configuration,
24+
group,
25+
options=dict(planner_id='RRT'))
26+
27+
print("Computed kinematic path with %d configurations." % len(trajectory.points))
28+
print("Executing this path at full speed would take approx. %.3f seconds." % trajectory.time_from_start)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import math
2+
from compas.geometry import Frame
3+
from compas_fab.backends import RosClient
4+
from compas_fab.robots import Configuration
5+
from helpers import show_trajectory
6+
7+
with RosClient('localhost') as client:
8+
robot = client.load_robot()
9+
group = robot.main_group_name
10+
11+
frame = Frame([0.4, 0.3, 0.4], [0, 1, 0], [0, 0, 1])
12+
tolerance_position = 0.001
13+
tolerance_axes = [math.radians(1)] * 3
14+
15+
start_configuration = Configuration.from_revolute_values([-0.042, 4.295, 0, -3.327, 4.755, 0.])
16+
17+
# create goal constraints from frame
18+
goal_constraints = robot.constraints_from_frame(frame,
19+
tolerance_position,
20+
tolerance_axes,
21+
group)
22+
23+
trajectory = robot.plan_motion(goal_constraints,
24+
start_configuration,
25+
group,
26+
options=dict(planner_id='RRT'))
27+
28+
print("Computed kinematic path with %d configurations." % len(trajectory.points))
29+
print("Executing this path at full speed would take approx. %.3f seconds." % trajectory.time_from_start)
30+
31+
show_trajectory(trajectory)

lecture_05/07_add_collision_mesh.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
3+
from compas.datastructures import Mesh
4+
5+
import compas_fab
6+
from compas_fab.backends import RosClient
7+
from compas_fab.robots import CollisionMesh
8+
from compas_fab.robots import PlanningScene
9+
10+
with RosClient('localhost') as client:
11+
robot = client.load_robot()
12+
13+
scene = PlanningScene(robot)
14+
mesh = Mesh.from_stl(compas_fab.get('planning_scene/floor.stl'))
15+
cm = CollisionMesh(mesh, 'floor')
16+
scene.add_collision_mesh(cm)
17+
18+
# sleep a bit before terminating the client
19+
#time.sleep(1)
20+
21+
#scene.remove_collision_mesh('floor')
22+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import time
2+
3+
from compas.datastructures import Mesh
4+
from compas.geometry import Box, Translation
5+
6+
from compas_fab.backends import RosClient
7+
from compas_fab.robots import CollisionMesh
8+
from compas_fab.robots import PlanningScene
9+
10+
with RosClient('localhost') as client:
11+
robot = client.load_robot()
12+
scene = PlanningScene(robot)
13+
14+
brick = Box.from_width_height_depth(0.016, 0.012, 0.031)
15+
brick.transform(Translation.from_vector([0, 0, brick.zsize / 2.]))
16+
17+
for i in range(5):
18+
mesh = Mesh.from_shape(brick)
19+
cm = CollisionMesh(mesh, 'brick_wall')
20+
cm.frame.point.y += 0.5
21+
cm.frame.point.z += brick.zsize * i
22+
23+
scene.append_collision_mesh(cm)
24+
25+
# sleep a bit before terminating the client
26+
time.sleep(1)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import time
2+
3+
from compas_fab.backends import RosClient
4+
from compas_fab.robots import PlanningScene
5+
6+
with RosClient('localhost') as client:
7+
robot = client.load_robot()
8+
scene = PlanningScene(robot)
9+
scene.remove_collision_mesh('brick_wall')
10+
scene.remove_collision_mesh('floor')
11+
12+
# sleep a bit before terminating the client
13+
time.sleep(1)

lecture_05/10_attach_tool.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import time
3+
4+
from compas_fab.backends import RosClient
5+
from compas_fab.robots import PlanningScene
6+
from compas_fab.robots import Tool
7+
8+
from compas.datastructures import Mesh
9+
from compas.geometry import Frame
10+
11+
HERE = os.path.dirname(__file__)
12+
13+
# create tool from mesh and frame
14+
mesh = Mesh.from_stl(os.path.join(HERE, 'vacuum_gripper.stl'))
15+
frame = Frame([0.07, 0, 0], [0, 0, 1], [0, 1, 0])
16+
tool = Tool(mesh, frame)
17+
tool.to_json(os.path.join(HERE, 'vacuum_gripper.json'))
18+
19+
20+
with RosClient('localhost') as client:
21+
robot = client.load_robot()
22+
scene = PlanningScene(robot)
23+
robot.attach_tool(tool)
24+
25+
# add attached tool to planning scene
26+
scene.add_attached_tool()
27+
28+
# now we can convert frames at robot's tool tip and flange
29+
frames_tcf = [Frame((-0.309, -0.046, -0.266), (0.276, 0.926, -0.256), (0.879, -0.136, 0.456))]
30+
frames_tcf0 = robot.from_tcf_to_t0cf(frames_tcf)
31+
32+
time.sleep(1)

lecture_05/11_detach_tool.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import time
3+
4+
from compas_fab.backends import RosClient
5+
from compas_fab.robots import PlanningScene
6+
from compas_fab.robots import Tool
7+
8+
HERE = os.path.dirname(__file__)
9+
tool = Tool.from_json(os.path.join(HERE, 'vacuum_gripper.json'))
10+
11+
with RosClient('localhost') as client:
12+
robot = client.load_robot()
13+
scene = PlanningScene(robot)
14+
15+
# Attach the tool
16+
robot.attach_tool(tool)
17+
scene.add_attached_tool()
18+
time.sleep(1)
19+
20+
# Remove the tool
21+
scene.remove_attached_tool()
22+
scene.remove_collision_mesh(tool.name)
23+
robot.detach_tool()
24+
time.sleep(1)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
from compas.geometry import Frame
3+
from compas_fab.backends import RosClient
4+
from compas_fab.robots import Configuration
5+
from compas_fab.robots import Tool
6+
7+
# create tool from json
8+
HERE = os.path.dirname(__file__)
9+
filepath = os.path.join(HERE, 'vacuum_gripper.json')
10+
tool = Tool.from_json(filepath)
11+
12+
element_height = 0.014
13+
approach_distance = 0.05
14+
15+
with RosClient('localhost') as client:
16+
robot = client.load_robot()
17+
18+
# 1. Set tool
19+
robot.attach_tool(tool)
20+
21+
# 2. Define start configuration
22+
start_configuration = Configuration.from_revolute_values([-5.961, 4.407, -2.265, 5.712, 1.571, -2.820])
23+
24+
# 3. Define frames
25+
picking_frame = Frame([-0.43, 0, element_height], [1, 0, 0], [0, 1, 0])
26+
approach_picking_frame = Frame([-0.43, 0, element_height + approach_distance], [1, 0, 0], [0, 1, 0])
27+
frames = [picking_frame, approach_picking_frame]
28+
29+
# 4. Convert frames to tool0_frames
30+
frames_tool0 = robot.from_tcf_to_t0cf(frames)
31+
32+
trajectory = robot.plan_cartesian_motion(frames_tool0,
33+
start_configuration,
34+
options=dict(max_step=0.01))
35+
36+
print("Computed cartesian path with %d configurations, " % len(trajectory.points))
37+
print("following %d%% of requested trajectory." % (trajectory.fraction * 100))
38+
print("Executing this path at full speed would take approx. %.3f seconds." % trajectory.time_from_start)

0 commit comments

Comments
 (0)