Skip to content

Commit 6723fdc

Browse files
committed
Fix some issues with multiple groups in cartesian planner
1 parent e582aea commit 6723fdc

File tree

4 files changed

+74
-28
lines changed

4 files changed

+74
-28
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from compas.geometry import Frame
2+
from compas.robots import RobotModel
3+
4+
from compas_fab.backends import RosClient
5+
from compas_fab.backends import RosFileServerLoader
6+
from compas_fab.robots import Configuration
7+
from compas_fab.robots import Robot
8+
from compas_fab.robots import RobotSemantics
9+
10+
with RosClient() as client:
11+
loader = RosFileServerLoader(client)
12+
13+
urdf = loader.load_urdf()
14+
srdf = loader.load_srdf()
15+
16+
model = RobotModel.from_urdf_string(urdf)
17+
semantics = RobotSemantics.from_srdf_string(srdf, model)
18+
19+
robot = Robot(model, semantics=semantics, client=client)
20+
group = 'panda_arm'
21+
22+
frames = []
23+
frames.append(Frame((0.2925, 0.3949, 0.5066), (0, 1, 0), (0, 0, 1)))
24+
frames.append(Frame((0.5103, 0.2827, 0.4074), (0, 1, 0), (0, 0, 1)))
25+
26+
start_configuration = Configuration((0.667, -0.298, 0.336, -2.333, -1.787, 2.123, 0.571), (0, 0, 0, 0, 0, 0, 0))
27+
28+
trajectory = robot.plan_cartesian_motion(frames,
29+
start_configuration,
30+
max_step=0.01,
31+
avoid_collisions=True,
32+
group=group)
33+
34+
print("Computed cartesian path with %d configurations, " % len(trajectory.points))
35+
print("following %d%% of requested trajectory." % (trajectory.fraction * 100))
36+
print("Executing this path at full speed would take approx. %.3f seconds." % trajectory.time_from_start)

src/compas_fab/backends/ros/client.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,16 @@ def forward_kinematics(self, joint_positions, base_link, group, joint_names, ee_
140140

141141
return await_callback(self.forward_kinematics_async, **kwargs)
142142

143-
def plan_cartesian_motion(self, frames, base_link,
144-
ee_link, group, joint_names, joint_types,
145-
start_configuration, max_step, jump_threshold,
143+
def plan_cartesian_motion(self,
144+
robot, frames, start_configuration,
145+
group, max_step, jump_threshold,
146146
avoid_collisions, path_constraints,
147147
attached_collision_meshes):
148148
kwargs = {}
149+
kwargs['robot'] = robot
149150
kwargs['frames'] = frames
150-
kwargs['base_link'] = base_link
151-
kwargs['ee_link'] = ee_link
152-
kwargs['group'] = group
153-
kwargs['joint_names'] = joint_names
154-
kwargs['joint_types'] = joint_types
155151
kwargs['start_configuration'] = start_configuration
152+
kwargs['group'] = group
156153
kwargs['max_step'] = max_step
157154
kwargs['jump_threshold'] = jump_threshold
158155
kwargs['avoid_collisions'] = avoid_collisions

src/compas_fab/backends/ros/planner_backend_moveit.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,23 @@ def convert_to_frame(response):
161161
self.GET_POSITION_FK(self, (header, fk_link_names,
162162
robot_state), convert_to_frame, errback)
163163

164-
def plan_cartesian_motion_async(self, callback, errback, frames, base_link,
165-
ee_link, group, joint_names, joint_types,
166-
start_configuration, max_step, jump_threshold,
164+
def plan_cartesian_motion_async(self, callback, errback,
165+
robot, frames, start_configuration,
166+
group, max_step, jump_threshold,
167167
avoid_collisions, path_constraints,
168168
attached_collision_meshes):
169169
"""Asynchronous handler of MoveIt cartesian motion planner service."""
170+
base_link = robot.get_base_link_name(group)
171+
ee_link = robot.get_end_effector_link_name(group)
172+
173+
joint_names = robot.get_configurable_joint_names(group)
170174
header = Header(frame_id=base_link)
171175
waypoints = [Pose.from_frame(frame) for frame in frames]
172-
joint_state = JointState(
173-
header=header, name=joint_names, position=start_configuration.values)
174-
start_state = RobotState(
175-
joint_state, MultiDOFJointState(header=header))
176+
joint_state = JointState(header=header,
177+
name=joint_names,
178+
position=start_configuration.values)
179+
start_state = RobotState(joint_state, MultiDOFJointState(header=header))
180+
176181
if attached_collision_meshes:
177182
for acm in attached_collision_meshes:
178183
aco = AttachedCollisionObject.from_attached_collision_mesh(acm)
@@ -189,15 +194,24 @@ def plan_cartesian_motion_async(self, callback, errback, frames, base_link,
189194
path_constraints=path_constraints)
190195

191196
def convert_to_trajectory(response):
197+
try:
192198
trajectory = JointTrajectory()
193199
trajectory.source_message = response
194200
trajectory.fraction = response.fraction
195201
trajectory.joint_names = response.solution.joint_trajectory.joint_names
202+
203+
joint_types = robot.get_joint_types_by_names(trajectory.joint_names)
196204
trajectory.points = convert_trajectory_points(response.solution.joint_trajectory.points, joint_types)
197-
trajectory.start_configuration = Configuration(response.start_state.joint_state.position, start_configuration.types)
205+
206+
start_state_types = robot.get_joint_types_by_names(response.start_state.joint_state.name)
207+
trajectory.start_configuration = Configuration(
208+
response.start_state.joint_state.position, start_state_types)
198209

199210
callback(trajectory)
200211

212+
except Exception as e:
213+
errback(e)
214+
201215
self.GET_CARTESIAN_PATH(self, request, convert_to_trajectory, errback)
202216

203217
def plan_motion_async(self, callback, errback, goal_constraints, base_link,

src/compas_fab/robots/robot.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,14 +1097,9 @@ def plan_cartesian_motion(self, frames_WCF, start_configuration=None,
10971097
frame_RCF = self.to_local_coords(frame_WCF, group)
10981098
frame_RCF.point /= self.scale_factor
10991099
frames_RCF.append(frame_RCF)
1100-
base_link = self.get_base_link_name(group)
11011100

1102-
joint_names = self.get_configurable_joint_names()
1103-
joint_types = self.get_configurable_joint_types(group)
11041101
start_configuration = start_configuration.copy() if start_configuration else self.init_configuration()
11051102
start_configuration.scale(1. / self.scale_factor)
1106-
1107-
ee_link = self.get_end_effector_link_name(group)
11081103
max_step_scaled = max_step / self.scale_factor
11091104

11101105
T = self.transformation_WCF_RCF(group)
@@ -1123,13 +1118,17 @@ def plan_cartesian_motion(self, frames_WCF, start_configuration=None,
11231118
else:
11241119
path_constraints_RCF_scaled = None
11251120

1126-
trajectory = self.client.plan_cartesian_motion(frames_RCF, base_link,
1127-
ee_link, group, joint_names,
1128-
joint_types, start_configuration,
1129-
max_step_scaled, jump_threshold,
1130-
avoid_collisions,
1131-
path_constraints_RCF_scaled,
1132-
attached_collision_meshes)
1121+
trajectory = self.client.plan_cartesian_motion(
1122+
robot=self,
1123+
frames=frames_RCF,
1124+
start_configuration=start_configuration,
1125+
group=group,
1126+
max_step=max_step_scaled,
1127+
jump_threshold=jump_threshold,
1128+
avoid_collisions=avoid_collisions,
1129+
path_constraints=path_constraints_RCF_scaled,
1130+
attached_collision_meshes=attached_collision_meshes)
1131+
11331132
# Scale everything back to robot's scale
11341133
for pt in trajectory.points:
11351134
pt.scale(self.scale_factor)

0 commit comments

Comments
 (0)