test_publisher_float_sine_noise.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 import math
20 import random
21 from std_msgs.msg import Float64
22 
23 def inputPub():
24  rospy.init_node("test_publisher_float_sine_noise", anonymous=True)
25  #for testing behavior of moving_average and simpson_integrator
26 
27  input_pub = rospy.Publisher("input", Float64, queue_size=1)
28  rospy.sleep(1.0)
29 
30  freq = 100.0
31  r = rospy.Rate(freq)
32 
33  a = 0.05#2.0
34  b = 0.1 * (2.0*math.pi/freq)
35  c = 0.0#-math.pi/2.0
36  d = 0.0#a
37  i = 0.0
38 
39  input_msg = Float64()
40 
41  while not rospy.is_shutdown():
42  input_msg.data = a*math.sin(b*i+c) + d
43 
44  noise = random.uniform(-a, a)
45  #noise = random.uniform(-0.01, 0.01)
46  input_msg.data += noise
47 
48  input_pub.publish(input_msg)
49 
50  i += 1.0
51  r.sleep()
52 
53 if __name__ == '__main__':
54  try:
55  inputPub()
56  except rospy.ROSInterruptException: pass


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Apr 8 2021 02:40:01