2 from clearpath_control_msgs.srv
import SetControlMode
3 from clearpath_control_msgs.msg
import ControlMode
4 from std_srvs.srv
import SetBool
5 from clearpath_localization_msgs.srv
import SetDatum
9 SET_MODE_SERVICE =
'control_selection/set_mode'
11 PAUSE_SERVICE =
'control_selection/autonomy_pause'
13 RESUME_SERVICE =
'control_selection/autonomy_resume'
15 SET_DATUM_SERVICE =
'localization/set_datum'
17 SET_OBSTACLE_AVOIDANCE_SERVICE =
'navigation/set_obstacle_avoidance'
21 """Encapsulates the services provided by the Autonomy API."""
25 """Sets the control mode (NEUTRAL, MANUAL, or AUTONOMY).
30 The current control mode (NEUTRAL, MANUAL, or AUTONOMY)
35 True if the mode was set successfully, else False
38 control_mode = ControlMode()
39 control_mode.mode = mode
40 rospy.wait_for_service(SET_MODE_SERVICE, timeout=2.0)
42 set_mode_service = rospy.ServiceProxy(SET_MODE_SERVICE, SetControlMode)
43 set_mode_service(control_mode)
45 except rospy.ServiceException
as e:
46 rospy.logerr(
"setMode Service call failed: %s" % e)
51 """Pauses the mission that is currently executing.
53 To resume the mission, see resumeMission().
54 To stop the mission, see stopMission().
59 True if the mission was paused successfully, else False
62 rospy.wait_for_service(PAUSE_SERVICE, timeout=2.0)
64 pause_service = rospy.ServiceProxy(PAUSE_SERVICE, SetBool)
65 resp = pause_service(
True)
67 except rospy.ServiceException
as e:
68 rospy.logerr(
"pauseMission Service call failed: %s" % e)
73 """Resumes the mission that was previously paused with pauseMission().
78 True if the mission was resumed successfully, else False
81 rospy.wait_for_service(RESUME_SERVICE, timeout=2.0)
83 resume_service = rospy.ServiceProxy(RESUME_SERVICE, SetBool)
84 resp = resume_service(
True)
86 except rospy.ServiceException
as e:
87 rospy.logerr(
"resumeMission Service call failed: %s" % e)
92 """Sets the datum position.
96 coordinate_lat_lon : CoordinateLatLon
97 The coordinate of the datum
102 True if the datum was set successfully, else False
105 rospy.wait_for_service(SET_DATUM_SERVICE, timeout=2.0)
107 set_datum_service = rospy.ServiceProxy(SET_DATUM_SERVICE, SetDatum)
108 resp = set_datum_service(
109 float(coordinate_lat_lon.getLat()), float(coordinate_lat_lon.getLon()))
111 except rospy.ServiceException
as e:
112 rospy.logerr(
"setDatum Service call failed: %s" % e)
117 """Enables/disables obstacle avoidance.
121 enable_avoidance : bool
122 If True, enable obstacle avoidance; if False, disable obstacle avoidance
127 True if obstacle avoidance was updated successfully, else False
130 rospy.wait_for_service(SET_OBSTACLE_AVOIDANCE_SERVICE, timeout=2.0)
132 set_avoidance_service = rospy.ServiceProxy(SET_OBSTACLE_AVOIDANCE_SERVICE, SetBool)
133 resp = set_avoidance_service(enable_avoidance)
135 except rospy.ServiceException
as e:
136 rospy.logerr(
"setObstacleAviodance Service call failed: %s" % e)