Skip to content

Commit 2f10449

Browse files
committed
Better support for passive and multiple active groups on kinematic planning
1 parent 817d4de commit 2f10449

File tree

6 files changed

+82
-41
lines changed

6 files changed

+82
-41
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Unreleased
1717
**Changed**
1818

1919
* Updated to COMPAS 0.10
20-
* Add support for passive joints on IK
20+
* Add better support for passive joints on IK, Cartesian and Kinematic planning
2121

2222
**Removed**
2323

docs/examples/03_backends_ros/files/04_plan_cartesian_motion_ros_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
semantics = RobotSemantics.from_srdf_string(srdf, model)
1818

1919
robot = Robot(model, semantics=semantics, client=client)
20-
group = 'panda_arm'
20+
group = robot.main_group_name
2121

2222
frames = []
2323
frames.append(Frame((0.2925, 0.3949, 0.5066), (0, 1, 0), (0, 0, 1)))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import math
2+
from compas.geometry import Frame
3+
from compas.robots import RobotModel
4+
5+
from compas_fab.backends import RosClient
6+
from compas_fab.backends import RosFileServerLoader
7+
from compas_fab.robots import Configuration
8+
from compas_fab.robots import Robot
9+
from compas_fab.robots import RobotSemantics
10+
11+
with RosClient() as client:
12+
loader = RosFileServerLoader(client)
13+
14+
urdf = loader.load_urdf()
15+
srdf = loader.load_srdf()
16+
17+
model = RobotModel.from_urdf_string(urdf)
18+
semantics = RobotSemantics.from_srdf_string(srdf, model)
19+
20+
robot = Robot(model, semantics=semantics, client=client)
21+
group = robot.main_group_name
22+
23+
frame = Frame([0.4, 0.3, 0.4], [0, 1, 0], [0, 0, 1])
24+
tolerance_position = 0.001
25+
tolerance_axes = [math.radians(1)] * 3
26+
27+
start_configuration = Configuration(
28+
(0.667, -0.298, 0.336, -2.333, -1.787, 2.123, 0.571), (0, 0, 0, 0, 0, 0, 0))
29+
30+
# create goal constraints from frame
31+
goal_constraints = robot.constraints_from_frame(frame,
32+
tolerance_position,
33+
tolerance_axes,
34+
group)
35+
36+
trajectory = robot.plan_motion(goal_constraints,
37+
start_configuration,
38+
group,
39+
planner_id='RRT')
40+
41+
print("Computed kinematic path with %d configurations." % len(trajectory.points))
42+
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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,19 @@ def plan_cartesian_motion(self,
160160

161161
return await_callback(self.plan_cartesian_motion_async, **kwargs)
162162

163-
def plan_motion(self, goal_constraints, base_link, ee_link, group,
164-
joint_names, joint_types, start_configuration, path_constraints=None,
165-
trajectory_constraints=None, planner_id='',
166-
num_planning_attempts=8, allowed_planning_time=2.,
163+
def plan_motion(self, robot, goal_constraints, start_configuration, group,
164+
path_constraints=None, trajectory_constraints=None,
165+
planner_id='', num_planning_attempts=8,
166+
allowed_planning_time=2.,
167167
max_velocity_scaling_factor=1.,
168168
max_acceleration_scaling_factor=1.,
169169
attached_collision_meshes=None,
170170
workspace_parameters=None):
171-
172171
kwargs = {}
172+
kwargs['robot'] = robot
173173
kwargs['goal_constraints'] = goal_constraints
174-
kwargs['base_link'] = base_link
175-
kwargs['ee_link'] = ee_link
176-
kwargs['group'] = group
177-
kwargs['joint_names'] = joint_names
178-
kwargs['joint_types'] = joint_types
179174
kwargs['start_configuration'] = start_configuration
175+
kwargs['group'] = group
180176
kwargs['path_constraints'] = path_constraints
181177
kwargs['trajectory_constraints'] = trajectory_constraints
182178
kwargs['planner_id'] = planner_id

src/compas_fab/backends/ros/planner_backend_moveit.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ def convert_to_trajectory(response):
215215

216216
self.GET_CARTESIAN_PATH(self, request, convert_to_trajectory, errback)
217217

218-
def plan_motion_async(self, callback, errback, goal_constraints, base_link,
219-
ee_link, group, joint_names, joint_types,
220-
start_configuration, path_constraints=None,
221-
trajectory_constraints=None,
218+
def plan_motion_async(self, callback, errback,
219+
robot, goal_constraints, start_configuration, group,
220+
path_constraints=None, trajectory_constraints=None,
222221
planner_id='', num_planning_attempts=8,
223222
allowed_planning_time=2.,
224223
max_velocity_scaling_factor=1.,
@@ -229,6 +228,8 @@ def plan_motion_async(self, callback, errback, goal_constraints, base_link,
229228

230229
# http://docs.ros.org/jade/api/moveit_core/html/utils_8cpp_source.html
231230
# TODO: if list of frames (goals) => receive multiple solutions?
231+
base_link = robot.get_base_link_name(group)
232+
joint_names = robot.get_configurable_joint_names(group)
232233

233234
header = Header(frame_id=base_link)
234235
joint_state = JointState(
@@ -290,10 +291,16 @@ def convert_to_trajectory(response):
290291
trajectory.source_message = response
291292
trajectory.fraction = 1.
292293
trajectory.joint_names = response.trajectory.joint_trajectory.joint_names
293-
trajectory.points = convert_trajectory_points(response.trajectory.joint_trajectory.points, joint_types)
294-
trajectory.start_configuration = Configuration(response.trajectory_start.joint_state.position, start_configuration.types)
295294
trajectory.planning_time = response.planning_time
296295

296+
joint_types = robot.get_joint_types_by_names(trajectory.joint_names)
297+
trajectory.points = convert_trajectory_points(
298+
response.trajectory.joint_trajectory.points, joint_types)
299+
300+
start_state = response.trajectory_start.joint_state
301+
start_state_types = robot.get_joint_types_by_names(start_state.name)
302+
trajectory.start_configuration = Configuration(start_state.position, start_state_types)
303+
297304
callback(trajectory)
298305

299306
self.GET_MOTION_PLAN(self, request, convert_to_trajectory, errback)

src/compas_fab/robots/robot.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,12 @@ def plan_motion(self, goal_constraints, start_configuration=None,
12171217
if not group:
12181218
group = self.main_group_name # ensure semantics
12191219

1220+
start_configuration = start_configuration.copy() if start_configuration else self.init_configuration()
1221+
12201222
# Transform goal constraints to RCF and scale
1221-
T = self._get_current_transformation_WCF_RCF(start_configuration, group)
1223+
full_configuration = self.merge_group_with_full_configuration(start_configuration, self.init_configuration(), group)
1224+
1225+
T = self._get_current_transformation_WCF_RCF(full_configuration, group)
12221226
goal_constraints_RCF_scaled = []
12231227
for c in goal_constraints:
12241228
cp = c.copy()
@@ -1247,30 +1251,22 @@ def plan_motion(self, goal_constraints, start_configuration=None,
12471251
else:
12481252
path_constraints_RCF_scaled = None
12491253

1250-
joint_names = self.get_configurable_joint_names()
1251-
joint_types = self.get_configurable_joint_types(group)
1252-
start_configuration = start_configuration.copy() if start_configuration else self.init_configuration()
12531254
start_configuration.scale(1. / self.scale_factor)
12541255

1255-
kwargs = {}
1256-
kwargs['goal_constraints'] = goal_constraints_RCF_scaled
1257-
kwargs['base_link'] = self.get_base_link_name(group)
1258-
kwargs['ee_link'] = self.get_end_effector_link_name(group)
1259-
kwargs['group'] = group
1260-
kwargs['joint_names'] = joint_names
1261-
kwargs['joint_types'] = joint_types
1262-
kwargs['start_configuration'] = start_configuration
1263-
kwargs['path_constraints'] = path_constraints_RCF_scaled
1264-
kwargs['trajectory_constraints'] = None
1265-
kwargs['planner_id'] = planner_id
1266-
kwargs['num_planning_attempts'] = num_planning_attempts
1267-
kwargs['allowed_planning_time'] = allowed_planning_time
1268-
kwargs['max_velocity_scaling_factor'] = max_velocity_scaling_factor
1269-
kwargs['max_acceleration_scaling_factor'] = max_acceleration_scaling_factor
1270-
kwargs['attached_collision_meshes'] = attached_collision_meshes
1271-
kwargs['workspace_parameters'] = None
1272-
1273-
trajectory = self.client.plan_motion(**kwargs)
1256+
trajectory = self.client.plan_motion(
1257+
robot=self,
1258+
goal_constraints=goal_constraints_RCF_scaled,
1259+
start_configuration=start_configuration,
1260+
group=group,
1261+
path_constraints=path_constraints_RCF_scaled,
1262+
trajectory_constraints=None,
1263+
planner_id=planner_id,
1264+
num_planning_attempts=num_planning_attempts,
1265+
allowed_planning_time=allowed_planning_time,
1266+
max_velocity_scaling_factor=max_velocity_scaling_factor,
1267+
max_acceleration_scaling_factor=max_acceleration_scaling_factor,
1268+
attached_collision_meshes=attached_collision_meshes,
1269+
workspace_parameters=None)
12741270

12751271
# Scale everything back to robot's scale
12761272
for pt in trajectory.points:

0 commit comments

Comments
 (0)