@@ -49,9 +49,10 @@ def __init__(self,
49
49
50
50
51
51
class SetOdometry (NonMotionGoal ):
52
+ odom_joints = (OmniDrive , DiffDrive , OmniDrivePR22 )
52
53
def __init__ (self ,
53
- group_name : str ,
54
54
base_pose : PoseStamped ,
55
+ group_name : Optional [str ] = None ,
55
56
name : Optional [str ] = None ,
56
57
start_condition : cas .Expression = cas .TrueSymbol ,
57
58
hold_condition : cas .Expression = cas .FalseSymbol ,
@@ -62,10 +63,19 @@ def __init__(self,
62
63
super ().__init__ (name )
63
64
if god_map .is_goal_msg_type_execute () and not god_map .is_standalone ():
64
65
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.' )
69
79
base_pose = transform_msg (brumbrum_joint .parent_link_name , base_pose ).pose
70
80
god_map .world .state [brumbrum_joint .x .name ].position = base_pose .position .x
71
81
god_map .world .state [brumbrum_joint .y .name ].position = base_pose .position .y
0 commit comments