Skip to content

Commit b117b74

Browse files
authored
Merge pull request #157 from SemRoCo/set_odom_without_group_name
made group_name in set_odometry optional
2 parents 5c24a45 + 9cc4548 commit b117b74

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/giskardpy/goals/joint_goals.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ def __init__(self,
4949

5050

5151
class SetOdometry(NonMotionGoal):
52+
odom_joints = (OmniDrive, DiffDrive, OmniDrivePR22)
5253
def __init__(self,
53-
group_name: str,
5454
base_pose: PoseStamped,
55+
group_name: Optional[str] = None,
5556
name: Optional[str] = None,
5657
start_condition: cas.Expression = cas.TrueSymbol,
5758
hold_condition: cas.Expression = cas.FalseSymbol,
@@ -62,10 +63,19 @@ def __init__(self,
6263
super().__init__(name)
6364
if god_map.is_goal_msg_type_execute() and not god_map.is_standalone():
6465
raise GoalInitalizationException(f'It is not allowed to combine {str(self)} with plan and execute.')
65-
brumbrum_joint_name = god_map.world.groups[group_name].root_link.child_joint_names[0]
66-
brumbrum_joint = god_map.world.joints[brumbrum_joint_name]
67-
if not isinstance(brumbrum_joint, (OmniDrive, DiffDrive, OmniDrivePR22)):
68-
raise GoalInitalizationException(f'Group {group_name} has no odometry joint.')
66+
if self.group_name is None:
67+
drive_joints = god_map.world.search_for_joint_of_type(self.odom_joints)
68+
if len(drive_joints) == 0:
69+
raise GoalInitalizationException('No drive joints in world')
70+
elif len(drive_joints) == 1:
71+
brumbrum_joint = drive_joints[0]
72+
else:
73+
raise GoalInitalizationException('Multiple drive joint found in world, please set \'group_name\'')
74+
else:
75+
brumbrum_joint_name = god_map.world.groups[group_name].root_link.child_joint_names[0]
76+
brumbrum_joint = god_map.world.joints[brumbrum_joint_name]
77+
if not isinstance(brumbrum_joint, self.odom_joints):
78+
raise GoalInitalizationException(f'Group {self.group_name} has no odometry joint.')
6979
base_pose = transform_msg(brumbrum_joint.parent_link_name, base_pose).pose
7080
god_map.world.state[brumbrum_joint.x.name].position = base_pose.position.x
7181
god_map.world.state[brumbrum_joint.y.name].position = base_pose.position.y

test/test_integration_pr2.py

+16
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,22 @@ def test_SetSeedConfiguration(self, zero_pose: PR2TestWrapper):
10981098
zero_pose.set_joint_goal(zero_pose.default_pose)
10991099
zero_pose.plan()
11001100

1101+
def test_SetOdometry(self, zero_pose: PR2TestWrapper):
1102+
pose = PoseStamped()
1103+
pose.header.frame_id = 'map'
1104+
pose.pose.position.x = 1
1105+
pose.pose.orientation.w = 1
1106+
zero_pose.set_seed_odometry(base_pose=pose)
1107+
zero_pose.set_joint_goal(zero_pose.better_pose)
1108+
zero_pose.plan()
1109+
pose = PoseStamped()
1110+
pose.header.frame_id = 'map'
1111+
pose.pose.position.x = 1
1112+
pose.pose.orientation.w = 1
1113+
zero_pose.set_seed_odometry(base_pose=pose, group_name=zero_pose.robot_name)
1114+
zero_pose.set_joint_goal(zero_pose.better_pose)
1115+
zero_pose.plan()
1116+
11011117
def test_drive_into_apartment(self, apartment_setup: PR2TestWrapper):
11021118
base_pose = PoseStamped()
11031119
base_pose.header.frame_id = 'base_footprint'

test/utils_for_tests.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,8 @@ def has_odometry_joint(self, group_name: Optional[str] = None):
252252
return isinstance(joint, (OmniDrive, DiffDrive))
253253

254254
def set_seed_odometry(self, base_pose, group_name: Optional[str] = None):
255-
if group_name is None:
256-
group_name = self.robot_name
257-
self.motion_goals.set_seed_odometry(group_name=group_name,
258-
base_pose=base_pose)
255+
self.motion_goals.set_seed_odometry(base_pose=base_pose,
256+
group_name=group_name)
259257

260258
def set_localization(self, map_T_odom: PoseStamped):
261259
if self.set_localization_srv is not None:

0 commit comments

Comments
 (0)