-
Notifications
You must be signed in to change notification settings - Fork 2
/
gps_noise.py
38 lines (31 loc) · 1019 Bytes
/
gps_noise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import rospy
from sensor_msgs.msg import NavSatFix
import numpy as np
## Python file to add gaussian noise to GPS readings to create a noisy GPS readings
gps_noisy = rospy.Publisher("/noise_gps",NavSatFix,queue_size=1000)
def gpscbk(data):
""" Function receives GPS data from topic and publishes a new topic with noisy GPS data
Args:
data: GPS data from topic with "Sensor_msgs/NavsatFix" message type
"""
global pub1
time = data.header.stamp
lat = data.latitude
lon = data.longitude
alt = data.altitude
# Adding Gaussian noise
noise = np.random.normal(0,0.0000001)
print(noise)
gps_sen = NavSatFix()
gps_sen.header.stamp = time
gps_sen.latitude = lat+noise
gps_sen.longitude = lon+noise
gps_sen.altitude = alt+noise
gps_noisy.publish(gps_sen)
def listener():
""" Function runs thee ROS init node
"""
rospy.init_node("gen_noise_gps")
rospy.Subscriber("/vectornav/gps/data",NavSatFix,gpscbk)
rospy.spin()
listener()