8 from geographiclib.geodesic
import Geodesic
9 from actionlib_msgs.msg
import GoalStatus
10 from geometry_msgs.msg
import PoseStamped
11 from move_base_msgs.msg
import MoveBaseAction, MoveBaseGoal
12 from sensor_msgs.msg
import NavSatFix
17 degrees, minutes, seconds = lat.split(
',')
18 degrees, minutes, seconds = float(degrees), float(minutes), float(seconds)
22 lat = degrees + minutes/60 + seconds/3600
24 degrees, minutes, seconds = long.split(
',')
25 degrees, minutes, seconds = float(degrees), float(minutes), float(seconds)
29 long = degrees + minutes/60 + seconds/3600
33 rospy.loginfo(
'Given GPS goal: lat %s, long %s.' % (lat, long))
38 rospy.loginfo(
"Waiting for a message to initialize the origin GPS location...")
39 origin_pose = rospy.wait_for_message(
'local_xy_origin', PoseStamped)
40 origin_lat = origin_pose.pose.position.y
41 origin_long = origin_pose.pose.position.x
42 rospy.loginfo(
'Received origin: lat %s, long %s.' % (origin_lat, origin_long))
43 return origin_lat, origin_long
45 def calc_goal(origin_lat, origin_long, goal_lat, goal_long):
48 g = geod.Inverse(origin_lat, origin_long, goal_lat, goal_long)
49 hypotenuse = distance = g[
's12']
50 rospy.loginfo(
"The distance from the origin to the goal is {:.3f} m.".format(distance))
52 rospy.loginfo(
"The azimuth from the origin to the goal is {:.3f} degrees.".format(azimuth))
56 azimuth = math.radians(azimuth)
57 x = adjacent = math.cos(azimuth) * hypotenuse
58 y = opposite = math.sin(azimuth) * hypotenuse
59 rospy.loginfo(
"The translation from the origin to the goal is (x,y) {:.3f}, {:.3f} m.".format(x, y))
65 rospy.init_node(
'gps_goal')
67 rospy.loginfo(
"Connecting to move_base...")
69 self.move_base.wait_for_server()
70 rospy.loginfo(
"Connected.")
78 def do_gps_goal(self, goal_lat, goal_long, z=0, yaw=0, roll=0, pitch=0):
82 self.
publish_goal(x=x, y=y, z=z, yaw=yaw, roll=roll, pitch=pitch)
85 lat = data.pose.position.y
86 long = data.pose.position.x
87 z = data.pose.position.z
88 euler = tf.transformations.euler_from_quaternion(data.pose.orientation)
92 self.
do_gps_goal(lat, long, z=z, yaw=yaw, roll=roll, pitch=pitch)
100 goal.target_pose.header.frame_id = rospy.get_param(
'~frame_id',
'map')
101 goal.target_pose.pose.position.x = x
102 goal.target_pose.pose.position.y = y
103 goal.target_pose.pose.position.z = z
104 quaternion = tf.transformations.quaternion_from_euler(roll, pitch, yaw)
105 goal.target_pose.pose.orientation.x = quaternion[0]
106 goal.target_pose.pose.orientation.y = quaternion[1]
107 goal.target_pose.pose.orientation.z = quaternion[2]
108 goal.target_pose.pose.orientation.w = quaternion[3]
109 rospy.loginfo(
'Executing move_base goal to position (x,y) %s, %s, with %s degrees yaw.' %
111 rospy.loginfo(
"To cancel the goal: 'rostopic pub -1 /move_base/cancel actionlib_msgs/GoalID -- {}'")
114 self.move_base.send_goal(goal)
115 rospy.loginfo(
'Inital goal status: %s' % GoalStatus.to_string(self.move_base.get_state()))
116 status = self.move_base.get_goal_status_text()
118 rospy.loginfo(status)
121 self.move_base.wait_for_result()
122 rospy.loginfo(
'Final goal status: %s' % GoalStatus.to_string(self.move_base.get_state()))
123 status = self.move_base.get_goal_status_text()
125 rospy.loginfo(status)
128 @click.option(
'--lat', prompt=
'Latitude', help=
'Latitude')
129 @click.option(
'--long', prompt=
'Longitude', help=
'Longitude')
130 @click.option(
'--roll',
'-r', help=
'Set target roll for goal', default=0.0)
131 @click.option(
'--pitch',
'-p', help=
'Set target pitch for goal', default=0.0)
132 @click.option(
'--yaw',
'-y', help=
'Set target yaw for goal', default=0.0)
134 """Send goal to move_base given latitude and longitude 138 gps_goal.py --lat 43.658 --long -79.379 # decimal format 139 gps_goal.py --lat 43,39,31 --long -79,22,45 # DMS format 145 gpsGoal.do_gps_goal(lat, long, roll=roll, pitch=pitch, yaw=yaw)
152 if __name__ ==
'__main__':
def gps_goal_fix_callback(self, data)
def gps_goal_pose_callback(self, data)
def cli_main(lat, long, roll, pitch, yaw)
def calc_goal(origin_lat, origin_long, goal_lat, goal_long)
def get_origin_lat_long()
def do_gps_goal(self, goal_lat, goal_long, z=0, yaw=0, roll=0, pitch=0)
def DMS_to_decimal_format(lat, long)
def publish_goal(self, x=0, y=0, z=0, yaw=0, roll=0, pitch=0)