Skip to content

Commit d04e31c

Browse files
committed
added gps_to_std_gt and services_timer from fuerte
1 parent 4b82475 commit d04e31c

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
import roslib; roslib.load_manifest('stereo_slam')
3+
import pylab
4+
import numpy as np
5+
from matplotlib import pyplot
6+
from mpl_toolkits.mplot3d import Axes3D
7+
8+
class Error(Exception):
9+
""" Base class for exceptions in this module. """
10+
pass
11+
12+
def get_xyz(gps_point):
13+
lat = gps_point[3]*np.pi/180 #converting to radians.
14+
lon = gps_point[4]*np.pi/180 #converting to radians.
15+
alt = gps_point[5]*np.pi/180 #converting to radians.
16+
a = 6378137.0 # earth semimajor axis in meters.
17+
f = 1/298.257223563 # reciprocal flattening.
18+
e2 = 2*f - np.power(f,2) # eccentricity squared.
19+
20+
chi = np.sqrt(1-e2 * np.power(np.sin(lat),2));
21+
x = (a/chi +alt) * np.cos(lat) * np.cos(lon);
22+
y = (a/chi +alt) * np.cos(lat) * np.sin(lon);
23+
z = (a*(1-e2)/chi + alt) * np.sin(lat);
24+
return x, y, z
25+
26+
if __name__ == "__main__":
27+
import argparse
28+
parser = argparse.ArgumentParser(
29+
description='Convert gps/fix topic to standard ground truth file',
30+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
31+
parser.add_argument('gps_topic_file',
32+
help='file with the gps/fix topic. Saved with "rostopic echo -p /gps/fix > data/anselm_turmeda/gt_gps.txt"')
33+
parser.add_argument('output_file',
34+
help='output file where the standard ground truth values will be saved.')
35+
args = parser.parse_args()
36+
37+
# Read the
38+
gps_topic = pylab.loadtxt(args.gps_topic_file, delimiter=',', skiprows=1, usecols=(0,1,2,6,7,8))
39+
40+
# Write the x, y, z data to the output file
41+
with open(args.output_file, 'w') as outfile:
42+
outfile.write("%time,field.header.seq,field.header.stamp,field.header.frame_id,field.child_frame_id,x,y,z,qx,qy,qz,qw\n")
43+
x0, y0, z0 = get_xyz(gps_topic[0])
44+
gt = []
45+
gt.append([0.0, 0.0, 0.0])
46+
for i in range(len(gps_topic)-1):
47+
x, y, z = get_xyz(gps_topic[i+1])
48+
x = x-x0
49+
y = y-y0
50+
z = z-z0
51+
gt.append([x, y, z])
52+
outfile.write("%.9F," % gps_topic[i+1, 0])
53+
outfile.write(str(gps_topic[i+1, 1]) + "," + str(gps_topic[i+1, 2]) + ",/gps,,")
54+
outfile.write("%.9F," % x)
55+
outfile.write("%.9F," % y)
56+
outfile.write("%.9F," % z)
57+
outfile.write("0.0,0.0,0.0,0.0")
58+
outfile.write("\n")
59+
gt = np.array(gt)
60+
61+
# Init figure
62+
fig = pylab.figure(1)
63+
ax = Axes3D(fig)
64+
ax.grid(True)
65+
ax.set_title("GT Viewer")
66+
ax.set_xlabel("X")
67+
ax.set_ylabel("Y")
68+
ax.set_zlabel("Z")
69+
70+
ax.plot(gt[:,0], gt[:,1], gt[:,2], 'g', label='Ground Truth')
71+
ax.legend()
72+
73+
pyplot.draw()
74+
pylab.show()
75+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2013,
5+
Systems, Robotics and Vision Group
6+
University of the Balearican Islands
7+
All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
* Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
* Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
* Neither the name of Systems, Robotics and Vision Group, University of
17+
the Balearican Islands nor the names of its contributors may be used to
18+
endorse or promote products derived from this software without specific
19+
prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
"""
32+
33+
34+
35+
import roslib; roslib.load_manifest('launch_tools')
36+
import sys
37+
import rospy
38+
import rosservice
39+
import threading
40+
41+
42+
## Class for calling a service using a timer.
43+
class TimedService(threading.Thread):
44+
45+
## The constructor
46+
# @param self The object pointer.
47+
# @param name The service name this class is going to call
48+
# @param freq The desired timer period
49+
def __init__(self, name, period):
50+
threading.Thread.__init__(self)
51+
self._service_name = name
52+
self._service_period = period
53+
54+
## Run function required by threading library
55+
def run(self):
56+
rospy.wait_for_service(self._service_name)
57+
rospy.Timer(rospy.Duration(self._service_period), self.callback)
58+
rospy.loginfo('Initialized timer for service: \n\t* Name: %s\n\t* Period: %f ', self._service_name, self._service_period)
59+
60+
## Timer callback
61+
# @param event The event that has generated this callback
62+
def callback(self,event):
63+
rospy.wait_for_service(self._service_name)
64+
service_class = rosservice.get_service_class_by_name(self._service_name)
65+
try:
66+
service = rospy.ServiceProxy(self._service_name,service_class)
67+
service()
68+
rospy.loginfo('Service %s called.', self._service_name)
69+
except rospy.ServiceException, e:
70+
rospy.logwarn('Service %s call failed: %s',self._service_name,e)
71+
72+
## @var _service_name
73+
# The service name going to be called
74+
_service_name = "service"
75+
76+
## @var _service_period
77+
# The timer period to call the service
78+
_service_period = 1.0
79+
80+
## Print usage for people that does not deserve to use this awesome python node.
81+
def usage():
82+
return "%s service period [service period ...]"%sys.argv[0]
83+
84+
## main function
85+
if __name__ == "__main__":
86+
rospy.init_node('services_timer')
87+
if len(sys.argv) >= 3:
88+
names = sys.argv[1:len(sys.argv):2]
89+
periods = sys.argv[2:len(sys.argv):2]
90+
print 'names: ', names
91+
print 'periods: ', periods
92+
ts_list = []
93+
for name,period in zip(names,periods):
94+
ts_list.append(TimedService(str(name), float(period)))
95+
for ts in ts_list:
96+
ts.start()
97+
else:
98+
print usage()
99+
sys.exit(1)
100+
rospy.spin()

0 commit comments

Comments
 (0)