Skip to content

Commit 9d62fc1

Browse files
amalnanavatiTaylor Kessler Faulkner
andauthored
Change in_front_of_face_wall based on the planning scene namespace (#192)
* Add service to add or remove collision scene objects * Remove hardcoded in-front-of-wheelchair wall from ada_feeding * Changes from testing in real * Fixes from testing * Speed up adding in-front-of-face wall --------- Co-authored-by: Taylor Kessler Faulkner <taylorkf@cs.washington.edu>
1 parent 6c8a91f commit 9d62fc1

22 files changed

+608
-277
lines changed

ada_feeding/ada_feeding/behaviors/moveit2/moveit2_plan.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,21 @@ def terminate(self, new_status: py_trees.common.Status) -> None:
499499
self.moveit2.clear_path_constraints()
500500

501501
@staticmethod
502-
def get_path_len(path: JointTrajectory) -> Tuple[float, Dict[str, float]]:
502+
def get_path_len(
503+
path: JointTrajectory, exclude_j6: bool = True
504+
) -> Tuple[float, Dict[str, float]]:
503505
"""
504506
Get the integrated path length of a trajectory in trajectory units.
505507
506508
Uses only the position component of waypoints.
507509
508510
Note: assumes joint values are in R1 (i.e. no wrap-around)
509511
512+
Parameters
513+
----------
514+
exclude_j6: If True, exclude the last joint from the path length calculation. This is
515+
because the last joint doesn't cause swivels, which is what we want to avoid.
516+
510517
Returns:
511518
* length of the path in joint config space
512519
* Dict: joint_name -> distance that joint travels
@@ -521,11 +528,21 @@ def get_path_len(path: JointTrajectory) -> Tuple[float, Dict[str, float]]:
521528
if len(path.points) == 0:
522529
return total_len, joint_lens
523530

531+
j6_i = None
532+
if exclude_j6 and "j2n6s200_joint_6" in path.joint_names:
533+
j6_i = path.joint_names.index("j2n6s200_joint_6")
534+
524535
prev_pos = np.array(path.points[0].positions)
525536
for point in path.points:
526537
curr_pos = np.array(point.positions)
527538
seg_len = np.abs(curr_pos - prev_pos)
528-
total_len += np.linalg.norm(seg_len)
539+
if j6_i is not None:
540+
j6_len = seg_len[j6_i]
541+
seg_len[j6_i] = 0.0
542+
total_len += np.linalg.norm(seg_len)
543+
seg_len[j6_i] = j6_len
544+
else:
545+
total_len += np.linalg.norm(seg_len)
529546
for index, name in enumerate(path.joint_names):
530547
joint_lens[name] += seg_len[index]
531548
prev_pos = curr_pos

ada_feeding/ada_feeding/behaviors/ros/tf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ def update(self) -> py_trees.common.Status:
341341
if self.tf_lock.locked():
342342
return py_trees.common.Status.RUNNING
343343

344+
self.logger.debug(f"Applying transform to {stamped_msg}")
345+
344346
transformed_msg = None
345347
with self.tf_lock:
346348
if target_frame is not None:

ada_feeding/ada_feeding/idioms/bite_transfer.py

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
from std_srvs.srv import SetBool
1616

1717
# Local imports
18+
from ada_feeding_msgs.srv import ModifyCollisionObject
1819
from ada_feeding.behaviors.moveit2 import (
19-
ModifyCollisionObject,
20-
ModifyCollisionObjectOperation,
2120
ToggleCollisionObject,
2221
)
2322
from .retry_call_ros_service import retry_call_ros_service
@@ -127,9 +126,49 @@ def get_toggle_watchdog_listener_behavior(
127126
return toggle_watchdog_listener
128127

129128

130-
def get_add_in_front_of_wheelchair_wall_behavior(
129+
def get_modify_collision_object_behavior(
130+
name: str,
131+
object_id: str,
132+
add: bool,
133+
) -> py_trees.behaviour.Behaviour:
134+
"""
135+
Creates a behaviour that adds or removes a collision object.
136+
137+
Parameters
138+
----------
139+
name: The name of the behaviour.
140+
object_id: The ID of the collision object to add or remove.
141+
add: Whether to add or remove the collision object.
142+
143+
Returns
144+
-------
145+
behavior: The behaviour that adds or removes the collision object.
146+
"""
147+
modify_collision_object_key_response = Blackboard.separator.join([name, "response"])
148+
return retry_call_ros_service(
149+
name=name,
150+
service_type=ModifyCollisionObject,
151+
service_name="~/modify_collision_object",
152+
key_request=None,
153+
request=ModifyCollisionObject.Request(
154+
operation=ModifyCollisionObject.Request.ADD
155+
if add
156+
else ModifyCollisionObject.Request.REMOVE,
157+
object_id=object_id,
158+
),
159+
key_response=modify_collision_object_key_response,
160+
response_checks=[
161+
py_trees.common.ComparisonExpression(
162+
variable=modify_collision_object_key_response + ".success",
163+
value=True,
164+
operator=operator.eq,
165+
)
166+
],
167+
)
168+
169+
170+
def get_add_in_front_of_face_wall_behavior(
131171
name: str,
132-
collision_object_id: str,
133172
):
134173
"""
135174
Creates a behavior that adds a collision wall between the staging pose and the user,
@@ -138,35 +177,20 @@ def get_add_in_front_of_wheelchair_wall_behavior(
138177
Parameters
139178
----------
140179
name: The name of the behaviour.
141-
collision_object_id: The ID of the collision object to add.
142180
143181
Returns
144182
-------
145183
behavior: The behaviour that adds the collision wall.
146184
"""
147-
# Create the behavior to add a collision wall between the staging pose and the user,
148-
# to prevent the robot from moving closer to the user.
149-
return ModifyCollisionObject(
185+
return get_modify_collision_object_behavior(
150186
name=name,
151-
inputs={
152-
"operation": ModifyCollisionObjectOperation.ADD,
153-
"collision_object_id": collision_object_id,
154-
"collision_object_position": (0.37, 0.17, 0.85),
155-
"collision_object_orientation": (0.0, 0.0, 0.0, 1.0),
156-
"prim_type": 1, # Box=1. See shape_msgs/SolidPrimitive.msg
157-
"dims": [
158-
0.65,
159-
0.01,
160-
0.4,
161-
], # Box has 3 dims: [x, y, z]
162-
"frame_id": "root",
163-
},
187+
object_id="in_front_of_face_wall",
188+
add=True,
164189
)
165190

166191

167-
def get_remove_in_front_of_wheelchair_wall_behavior(
192+
def get_remove_in_front_of_face_wall_behavior(
168193
name: str,
169-
collision_object_id: str,
170194
):
171195
"""
172196
Creates a behavior that removes the collision wall between the staging pose and the user.
@@ -179,13 +203,8 @@ def get_remove_in_front_of_wheelchair_wall_behavior(
179203
-------
180204
behavior: The behaviour that removes the collision wall.
181205
"""
182-
# Create the behavior to remove the collision wall between the staging pose and the user.
183-
remove_in_front_of_wheelchair_wall = ModifyCollisionObject(
206+
return get_modify_collision_object_behavior(
184207
name=name,
185-
inputs={
186-
"operation": ModifyCollisionObjectOperation.REMOVE,
187-
"collision_object_id": collision_object_id,
188-
},
208+
object_id="in_front_of_face_wall",
209+
add=False,
189210
)
190-
191-
return remove_in_front_of_wheelchair_wall

0 commit comments

Comments
 (0)