8 import dynamic_reconfigure.client
11 from yocs_navigator
import BasicMoveController
12 import std_msgs.msg
as std_msgs
13 import yocs_msgs.msg
as yocs_msgs
14 import geometry_msgs.msg
as geometry_msgs
18 Uses poses from a pose tracker to initialise the global robot pose 19 using a pose initialisation node such as fake_localization 22 _localize_action_name =
'localize' 30 if self.
param[
'simulation']:
31 self.
loginfo(
"Running in simulation mode.")
33 self.
_client = dynamic_reconfigure.client.Client(rospy.get_param(
'~pose_tracker',
'ar_track_alvar'))
36 self.
_pub_init_pose = rospy.Publisher(
'initialpose', geometry_msgs.PoseWithCovarianceStamped, latch=
True, queue_size=3)
44 param[
'sleeptime'] = rospy.Duration(1 / rospy.get_param(
'~spin_freq', 10))
45 param[
'simulation'] = rospy.get_param(
'~simulation',
False)
46 param[
'ar_pair_baseline'] = rospy.get_param(
'ar_pair/baseline', 0.28)
47 param[
'ar_pair_target_offset'] = rospy.get_param(
'ar_pair/target_offset', 0.5)
48 param[
'timeout'] = rospy.get_param(
'~timeout', 10.0)
51 param[
'sim_global_frame'] = rospy.get_param(
'~simulation_global_frame',
'map')
52 param[
'sim_x'] = rospy.get_param(
'~simulation_x', 0.0)
53 param[
'sim_y'] = rospy.get_param(
'~simulation_y', 0.0)
54 param[
'sim_a'] = rospy.get_param(
'~simulation_a', 0.0)
61 msg.header.stamp -= rospy.Duration(0.2)
62 cov = list(msg.pose.covariance)
65 msg.pose.covariance = tuple(cov)
66 self._pub_init_pose.publish(msg)
67 self.
loginfo(
"localization done.")
71 goal = self._as_localize.accept_new_goal()
73 self.
loginfo(
"Received Localize goal %s"%str(goal))
76 message =
'robot is initialising already. Ignore the command' 79 if self.
param[
'simulation']:
80 pose_msg = geometry_msgs.PoseWithCovarianceStamped()
81 pose_msg.header.frame_id = self.
param[
'sim_global_frame']
82 pose_msg.header.stamp = rospy.Time.now() - rospy.Duration(0.2)
83 pose_msg.pose.pose.position.x = self.
param[
'sim_x']
84 pose_msg.pose.pose.position.y = self.
param[
'sim_y']
85 pose_msg.pose.pose.position.z = 0.0
86 quat = tf.transformations.quaternion_from_euler(0, 0, self.
param[
'sim_a'])
87 pose_msg.pose.pose.orientation = geometry_msgs.Quaternion(*quat)
88 self._pub_init_pose.publish(pose_msg)
90 self.
_send_result(
True,
'Initialisation done in simulation.')
91 elif goal.command == goal.STAND_AND_LOCALIZE:
94 elif goal.command == goal.SPIN_AND_LOCALIZE:
98 message =
'Invalid command %s'%str(goal.command)
102 self.
logwarn(
'Received Preempt Request')
106 self.
loginfo(
"Stand and Localization started.")
112 timeout = self.
param[
'timeout']
113 sleeptime = self.
param[
'sleeptime']
114 start_time = rospy.Time.now()
115 while not rospy.is_shutdown()
and self.
_initialise:
116 current_time = rospy.Time.now()
117 dif = (current_time - start_time).to_sec()
120 rospy.sleep(sleeptime)
128 self.
_send_result(
False,
"couldn't localize in time %s"%str(dif))
133 self.
loginfo(
"Spin and localization started")
138 self._basic_move_controller.spin_clockwise()
143 self.
_send_result(
False,
"couldn't localise after full spining")
152 r = yocs_msgs.LocalizeResult()
155 self._as_localize.set_succeeded(r)
158 params = {
'enabled' : enabled}
159 config = self._client.update_configuration(params)
162 rospy.loginfo(
'Localization Manager : ' + str(msg))
165 rospy.logwarn(
'Localization Manager : ' + str(msg))
168 sleeptime = self.
param[
'sleeptime']
169 self._as_localize.start()
170 while not rospy.is_shutdown():
171 rospy.sleep(sleeptime)
def _process_localize_preempt(self)
def _send_result(self, success, message)
def _process_localize_goal(self)
string _localize_action_name
def _stand_and_localize(self)
def _update_tracker(self, enabled)
def _spin_and_localize(self)
def _tracked_poses_callback(self, msg)