9
9
from geometry_msgs .msg import PoseWithCovarianceStamped , PointStamped
10
10
from std_msgs .msg import Float64
11
11
import tf
12
+ import sys
12
13
13
14
class GPSSpoofer :
14
15
def __init__ (self ):
16
+ # Parameters
17
+ self .altitude_input = rospy .get_param ('~altitude_input' , 'vicon' )
18
+ self .publish_pose = rospy .get_param ('~publish_pose' , True )
19
+
20
+ # TODO: load params from param server
21
+ self .max_R_noise = 0.0 # [m] max tested: 0.15
22
+ self .pub_period = 0.1 # [s], publish disturbed pose every X s
23
+ # self.pos_var = pow(max(0.0707, self.max_R_noise/2.0), 2)
24
+ # self.pos_var = 0.005;
25
+
15
26
self .fix = NavSatFix ()
16
27
#self.fix.header.stamp = ...
17
28
self .fix .header .frame_id = 'fcu'
@@ -22,17 +33,7 @@ def __init__(self):
22
33
self .fix .altitude = 0.0
23
34
# TODO: fill GPS covariance
24
35
25
- self .altitude = Float64 ()
26
-
27
- self .altitude_input = rospy .get_param ('altitude_input' , 'vicon' )
28
-
29
- # TODO: load params from param server
30
- self .max_R_noise = 0.0 # [m] max tested: 0.15
31
- self .pub_period = 0.2 # [s], publish disturbed pose every X s
32
-
33
- # self.pos_var = pow(max(0.0707, self.max_R_noise/2.0), 2)
34
- # self.pos_var = 0.005;
35
-
36
+ self .latest_altitude_message = Float64 ()
36
37
self .latest_imu_message = Imu ()
37
38
38
39
self .pwc = PoseWithCovarianceStamped ()
@@ -55,7 +56,7 @@ def __init__(self):
55
56
56
57
self .pub_spoofed_gps = rospy .Publisher ('spoofed_gps' , NavSatFix , queue_size = 1 )
57
58
self .pub_disturbed_pose = rospy .Publisher ('disturbed_pose' , PoseWithCovarianceStamped , queue_size = 1 , tcp_nodelay = True )
58
- self .pub_point = rospy .Publisher ('vicon_point' , PointStamped , queue_size = 1 , tcp_nodelay = True )
59
+ self .pub_point = rospy .Publisher ('vicon_point' , PointStamped , queue_size = 1 , tcp_nodelay = True )
59
60
60
61
self .sub_altitude = rospy .Subscriber ('laser_altitude' , Float64 , self .callback_altitude , tcp_nodelay = True )
61
62
self .sub_gps = rospy .Subscriber ('gps' , NavSatFix , self .callback_gps , tcp_nodelay = True )
@@ -79,7 +80,6 @@ def callback_odometry(self, data):
79
80
y = data .pose .pose .position .y
80
81
81
82
# Angle between vi-con x axis and ENU East-aligned x axis
82
- #angle = radians(-7.0) #imu compass
83
83
angle = - 2.73
84
84
85
85
# Rotate x and y to align x to East
@@ -100,10 +100,11 @@ def callback_odometry(self, data):
100
100
self .pwc .pose .pose .position .z = data .pose .pose .position .z
101
101
self .point .point .z = data .pose .pose .position .z
102
102
elif (self .altitude_input == 'external' ):
103
- self .pwc .pose .pose .position .z = self .altitude .data
104
- self .point .point .z = self .altitude .data
103
+ self .pwc .pose .pose .position .z = self .latest_altitude_message .data
104
+ self .point .point .z = self .latest_altitude_message .data
105
105
else :
106
- ROS_WARN ("Unknown altitude input parameter" )
106
+ rospy .signal_shutdown ("Unknown altitude input parameter" )
107
+ sys .exit ()
107
108
108
109
if not self .got_odometry :
109
110
print "GPSSpoofer: initializing timers"
@@ -115,7 +116,7 @@ def callback_imu(self, data):
115
116
self .latest_imu_message = data
116
117
117
118
def callback_altitude (self , data ):
118
- self .altitude = data
119
+ self .latest_altitude_message = data
119
120
120
121
def sample_noise (self , event ):
121
122
#print "Resampling noise"
@@ -127,7 +128,9 @@ def publish_noisy_positions(self, event):
127
128
#print "Publishing odometry"
128
129
self .pwc .pose .pose .position .x += self .R_noise * cos (self .theta_noise )
129
130
self .pwc .pose .pose .position .y += self .R_noise * sin (self .theta_noise )
130
- self .pub_disturbed_pose .publish (self .pwc )
131
+
132
+ if (self .publish_pose == True ):
133
+ self .pub_disturbed_pose .publish (self .pwc )
131
134
132
135
self .point .point .x += self .R_noise * cos (self .theta_noise )
133
136
self .point .point .y += self .R_noise * sin (self .theta_noise )
0 commit comments