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