Skip to content

Commit 5e091d7

Browse files
Merge pull request #202 from FS-Online/sinewave-upgrade
Upgrade the sinewave to be more robust and send finish signals
2 parents a8111c0 + c07f5fc commit 5e091d7

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import rospy, math
33
from 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)
67
STEERING_PERIOD = 5
@@ -11,26 +12,28 @@
1112
# The throtle. This is just a static value.
1213
THROTLE = 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

Comments
 (0)