Skip to content

Commit fb328ec

Browse files
committed
Moved timewarp example to its own file
1 parent fd7cc36 commit fb328ec

2 files changed

Lines changed: 41 additions & 13 deletions

File tree

Documentation/examples/callbackcomms.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
comms = pymoos.comms()
1010

1111
def c():
12-
print("\t|-Time Warp @ {0:.1f} \n".format(pymoos.get_moos_timewarp()))
13-
print("\t|-Time Warp delay @ {0:.1f} ms \n".format( \
14-
comms.get_comms_control_timewarp_scale_factor()*pymoos.get_moos_timewarp()))
1512
return comms.register('simple_var',0)
1613

1714
def m():
@@ -20,19 +17,13 @@ def m():
2017

2118
def main():
2219

23-
comms.set_on_connect_callback(c)
24-
comms.set_on_mail_callback(m)
25-
pymoos.set_moos_timewarp(20)
26-
comms.set_comms_control_timewarp_scale_factor(0.4)
20+
comms.set_on_connect_callback(c);
21+
comms.set_on_mail_callback(m);
2722
comms.run('localhost',9000,'pymoos')
2823

29-
last_time = time.time()
30-
3124
while True:
32-
time.sleep(1.0)
33-
# if time.time() - last_time > 1.0:
34-
comms.notify('simple_var','a string',pymoos.time())
35-
# last_time = time.time()
25+
time.sleep(1)
26+
comms.notify('simple_var','a string',pymoos.time());
3627

3728
if __name__=="__main__":
3829
main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pymoos
2+
import time
3+
4+
#another simple example - here we install a callback which
5+
#fires every time mail arrives. We need to call fetch to
6+
#retrieve it though. We send mail in simple forever loop
7+
#We also subscribe to the same message..
8+
9+
#This version demonstrates setting and using a timewarp that allows speeding up
10+
#simulations with MOOS
11+
12+
comms = pymoos.comms()
13+
14+
def c():
15+
print("\t|-Time Warp @ {0:.1f} \n".format(pymoos.get_moos_timewarp()))
16+
print("\t|-Time Warp delay @ {0:.1f} ms \n".format( \
17+
comms.get_comms_control_timewarp_scale_factor()*pymoos.get_moos_timewarp()))
18+
return comms.register('simple_var',0)
19+
20+
def m():
21+
map(lambda msg: msg.trace(), comms.fetch() )
22+
return True
23+
24+
def main():
25+
26+
comms.set_on_connect_callback(c)
27+
comms.set_on_mail_callback(m)
28+
pymoos.set_moos_timewarp(10)
29+
comms.set_comms_control_timewarp_scale_factor(0.4)
30+
comms.run('localhost',9000,'pymoos')
31+
32+
while True:
33+
time.sleep(1.0)
34+
comms.notify('simple_var','a string',pymoos.time())
35+
36+
if __name__=="__main__":
37+
main()

0 commit comments

Comments
 (0)