Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 import math
00020 import random
00021 from std_msgs.msg import Float64
00022
00023 def inputPub():
00024 rospy.init_node("test_publisher_float_sine_noise", anonymous=True)
00025
00026
00027 input_pub = rospy.Publisher("input", Float64, queue_size=1)
00028 rospy.sleep(1.0)
00029
00030 freq = 100.0
00031 r = rospy.Rate(freq)
00032
00033 a = 0.05
00034 b = 0.1 * (2.0*math.pi/freq)
00035 c = 0.0
00036 d = 0.0
00037 i = 0.0
00038
00039 input_msg = Float64()
00040
00041 while not rospy.is_shutdown():
00042 input_msg.data = a*math.sin(b*i+c) + d
00043
00044 noise = random.uniform(-a, a)
00045
00046 input_msg.data += noise
00047
00048 input_pub.publish(input_msg)
00049
00050 i += 1.0
00051 r.sleep()
00052
00053 if __name__ == '__main__':
00054 try:
00055 inputPub()
00056 except rospy.ROSInterruptException: pass