11#!/usr/bin/env python
22import rospy , math
33from fs_msgs .msg import ControlCommand
4+ from fs_msgs .msg import FinishedSignal
45
56# the number of seconds to do a full steering cycle (neutral -> full right -> full left -> neutroal)
67STEERING_PERIOD = 5
1112# The throtle. This is just a static value.
1213THROTLE = 0.5
1314
14- def publishloop ():
15- controllpublisher = rospy .Publisher ('/fsds/control_command' , ControlCommand , queue_size = 10 )
16- rate = rospy .Rate (5 ) # 5hz
17- time = 0
18- while not rospy .is_shutdown ():
19- cc = ControlCommand ()
20- cc .header .stamp = rospy .Time .now ()
21- cc .throttle = THROTLE
22- cc .steering = math .sin (time * (math .pi / STEERING_PERIOD ))
23- cc .brake = 0
24-
25- controllpublisher .publish (cc )
26- time += 1.0 / SETPOINT_FREQUENCY
27- rate .sleep ()
28-
29-
30- def listeners ():
31- pass
32-
33- if __name__ == '__main__' :
34- rospy .init_node ('example_sinewave' )
35- listeners ()
36- publishloop ()
15+ rospy .init_node ('example_sinewave' )
16+ controllpublisher = rospy .Publisher ('/fsds/control_command' , ControlCommand , queue_size = 10 )
17+ finishedpublisher = rospy .Publisher ('/fsds/signal/finished' , FinishedSignal , queue_size = 1 )
18+
19+ time = 0
20+
21+ def publish (x ):
22+ global time
23+ global controllpublisher
24+ cc = ControlCommand ()
25+ cc .header .stamp = rospy .Time .now ()
26+ cc .throttle = THROTLE
27+ cc .steering = math .sin (time * (math .pi / STEERING_PERIOD ))
28+ cc .brake = 0
29+ controllpublisher .publish (cc )
30+
31+ time += 1.0 / SETPOINT_FREQUENCY
32+
33+ def finish (x ):
34+ finishedpublisher .publish (FinishedSignal ())
35+
36+ rospy .Timer (rospy .Duration (0.1 ), publish )
37+ rospy .Timer (rospy .Duration (30 ), finish )
38+
39+ rospy .spin ()
0 commit comments