3333from compas_fab .backends .ros .messages import PositionConstraint
3434from compas_fab .backends .ros .messages import PositionIKRequest
3535from compas_fab .backends .ros .messages import RobotState
36+ from compas_fab .backends .ros .messages import TrajectoryConstraints
3637from compas_fab .backends .ros .planner_backend import PlannerBackend
3738from compas_fab .backends .ros .planner_backend import ServiceDescription
3839from compas_fab .robots import Configuration
@@ -113,6 +114,27 @@ def dispose_planner(self):
113114 if hasattr (self , 'attached_collision_object_topic' ) and self .attached_collision_object_topic :
114115 self .attached_collision_object_topic .unadvertise ()
115116
117+ def _convert_constraints_to_rosmsg (self , constraints , header ):
118+ """Convert COMPAS FAB constraints into ROS Messages."""
119+ if not constraints :
120+ return None
121+
122+ ros_constraints = Constraints ()
123+ for c in constraints :
124+ if c .type == c .JOINT :
125+ ros_constraints .joint_constraints .append (
126+ JointConstraint .from_joint_constraint (c ))
127+ elif c .type == c .POSITION :
128+ ros_constraints .position_constraints .append (
129+ PositionConstraint .from_position_constraint (header , c ))
130+ elif c .type == c .ORIENTATION :
131+ ros_constraints .orientation_constraints .append (
132+ OrientationConstraint .from_orientation_constraint (header , c ))
133+ else :
134+ raise NotImplementedError
135+
136+ return ros_constraints
137+
116138 # ==========================================================================
117139 # planning services
118140 # ==========================================================================
@@ -133,6 +155,8 @@ def inverse_kinematics_async(self, callback, errback, frame, base_link, group,
133155 aco = AttachedCollisionObject .from_attached_collision_mesh (acm )
134156 start_state .attached_collision_objects .append (aco )
135157
158+ constraints = self ._convert_constraints_to_rosmsg (constraints , header )
159+
136160 ik_request = PositionIKRequest (group_name = group ,
137161 robot_state = start_state ,
138162 constraints = constraints ,
@@ -183,6 +207,8 @@ def plan_cartesian_motion_async(self, callback, errback,
183207 aco = AttachedCollisionObject .from_attached_collision_mesh (acm )
184208 start_state .attached_collision_objects .append (aco )
185209
210+ path_constraints = self ._convert_constraints_to_rosmsg (path_constraints , header )
211+
186212 request = dict (header = header ,
187213 start_state = start_state ,
188214 group_name = group ,
@@ -241,38 +267,12 @@ def plan_motion_async(self, callback, errback,
241267 aco = AttachedCollisionObject .from_attached_collision_mesh (acm )
242268 start_state .attached_collision_objects .append (aco )
243269
244- # goal constraints
245- constraints = Constraints ()
246- for c in goal_constraints :
247- if c .type == c .JOINT :
248- constraints .joint_constraints .append (
249- JointConstraint .from_joint_constraint (c ))
250- elif c .type == c .POSITION :
251- constraints .position_constraints .append (
252- PositionConstraint .from_position_constraint (header , c ))
253- elif c .type == c .ORIENTATION :
254- constraints .orientation_constraints .append (
255- OrientationConstraint .from_orientation_constraint (header , c ))
256- else :
257- raise NotImplementedError
258- goal_constraints = [constraints ]
259-
260- # path constraints
261- if path_constraints :
262- constraints = Constraints ()
263- for c in path_constraints :
264- if c .type == c .JOINT :
265- constraints .joint_constraints .append (
266- JointConstraint .from_joint_constraint (c ))
267- elif c .type == c .POSITION :
268- constraints .position_constraints .append (
269- PositionConstraint .from_position_constraint (header , c ))
270- elif c .type == c .ORIENTATION :
271- constraints .orientation_constraints .append (
272- OrientationConstraint .from_orientation_constraint (header , c ))
273- else :
274- raise NotImplementedError
275- path_constraints = constraints
270+ # convert constraints
271+ goal_constraints = [self ._convert_constraints_to_rosmsg (goal_constraints , header )]
272+ path_constraints = self ._convert_constraints_to_rosmsg (path_constraints , header )
273+
274+ if trajectory_constraints is not None :
275+ trajectory_constraints = TrajectoryConstraints (constraints = self ._convert_constraints_to_rosmsg (path_constraints , header ))
276276
277277 request = dict (start_state = start_state ,
278278 goal_constraints = goal_constraints ,
0 commit comments