Skip to content

Commit

Permalink
Fix bugs in pose setting for locations (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass committed Nov 28, 2024
1 parent ad8c139 commit 78ef10b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 23 deletions.
14 changes: 8 additions & 6 deletions pyrobosim/pyrobosim/core/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ def set_pose(self, pose):
if "offset" in self.metadata["footprint"]:
p_off = self.metadata["footprint"]["offset"]
else:
p_off = (0, 0)
p_off = (0.0, 0.0)
for p in self.metadata["nav_poses"]:
rot_p = rot2d((p[0] + p_off[0], p[1] + p_off[1]), self.pose.get_yaw())
p = Pose.construct(p)
rot_p = rot2d((p.x + p_off[0], p.y + p_off[1]), self.pose.get_yaw())
nav_pose = Pose(
x=rot_p[0] + self.pose.x,
y=rot_p[1] + self.pose.y,
z=self.pose.z,
yaw=p[2] + self.pose.get_yaw(),
yaw=p.get_yaw() + self.pose.get_yaw(),
)
if self.parent.is_collision_free(nav_pose):
self.nav_poses.append(nav_pose)
Expand Down Expand Up @@ -285,16 +286,17 @@ def set_pose_from_parent(self):
if "offset" in self.metadata["footprint"]:
p_off = self.metadata["footprint"]["offset"]
else:
p_off = (0, 0)
p_off = (0.0, 0.0)
for p in self.metadata["nav_poses"]:
p = Pose.construct(p)
rot_p = rot2d(
(p[0] + p_off[0], p[1] + p_off[1]), self.parent.pose.get_yaw()
(p.x + p_off[0], p.y + p_off[1]), self.parent.pose.get_yaw()
)
nav_pose = Pose(
x=rot_p[0] + self.parent.pose.x,
y=rot_p[1] + self.parent.pose.y,
z=self.parent.pose.z,
yaw=p[2] + self.parent.pose.get_yaw(),
yaw=p.get_yaw() + self.parent.pose.get_yaw(),
)
if self.parent.parent.is_collision_free(nav_pose):
self.nav_poses.append(nav_pose)
Expand Down
3 changes: 2 additions & 1 deletion pyrobosim/pyrobosim/core/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def add_locations(self):
"""Add locations for object spawning to the world."""
for loc_data in self.data.get("locations", []):
loc_args = copy.deepcopy(loc_data)
loc_args["pose"] = Pose.construct(loc_args["pose"])
if "pose" in loc_args:
loc_args["pose"] = Pose.construct(loc_args["pose"])
self.world.add_location(**loc_args)

def add_objects(self):
Expand Down
88 changes: 72 additions & 16 deletions pyrobosim/pyrobosim/data/example_location_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ table:
dims: [0.9, 1.2]
height: 0.5
nav_poses:
- [-0.75, 0, 0]
- [0.75, 0, 3.14]
- position: # left
x: -0.75
y: 0.0
- position: # right
x: 0.75
y: 0.0
rotation_eul:
yaw: 3.14
locations:
- name: "tabletop"
footprint:
Expand All @@ -31,10 +37,24 @@ desk:
footprint:
type: parent
nav_poses:
- [0, -0.5, 1.57]
- [-0.5, 0, 0]
- [0, 0.5, -1.57]
- [0.5, 0, 3.14]
- position: # below
x: 0.0
y: -0.5
rotation_eul:
yaw: 1.57
- position: # left
x: -0.5
y: 0.0
- position: # above
x: 0.0
y: 0.5
rotation_eul:
yaw: -1.57
- position: # right
x: 0.5
y: 0.0
rotation_eul:
yaw: 3.14

counter:
footprint:
Expand All @@ -52,8 +72,16 @@ counter:
- [-0.25, 0.25]
offset: [0.3, 0]
nav_poses:
- [0, 0.5, -1.57]
- [0, -0.5, 1.57]
- position: # below
x: 0.0
y: -0.5
rotation_eul:
yaw: 1.57
- position: # above
x: 0.0
y: 0.5
rotation_eul:
yaw: -1.57
- name: "right"
footprint:
type: polygon
Expand All @@ -64,8 +92,16 @@ counter:
- [-0.25, 0.25]
offset: [-0.3, 0]
nav_poses:
- [0, 0.5, -1.57]
- [0, -0.5, 1.57]
- position: # below
x: 0.0
y: -0.5
rotation_eul:
yaw: 1.57
- position: # above
x: 0.0
y: 0.5
rotation_eul:
yaw: -1.57
color: [0, 0.2, 0]

trash_can:
Expand All @@ -79,8 +115,14 @@ trash_can:
type: parent
padding: 0.05
nav_poses:
- [0.5, 0.0, 3.14]
- [-0.5, 0.0, 0.0]
- position: # left
x: -0.5
y: 0.0
- position: # right
x: 0.5
y: 0.0
rotation_eul:
yaw: 3.14
color: [0, 0.35, 0.2]

charger:
Expand All @@ -97,8 +139,22 @@ charger:
footprint:
type: parent
nav_poses:
- [0, -0.35, 1.57]
- [-0.5, 0, 0]
- [0, 0.35, -1.57]
- [0.5, 0, 3.14]
- position: # below
x: 0.0
y: -0.5
rotation_eul:
yaw: 1.57
- position: # left
x: -0.35
y: 0.0
- position: # above
x: 0.0
y: 0.5
rotation_eul:
yaw: -1.57
- position: # right
x: 0.35
y: 0.0
rotation_eul:
yaw: 3.14
color: [0.4, 0.4, 0]

0 comments on commit 78ef10b

Please sign in to comment.