Skip to content

Commit 300a0b9

Browse files
committed
Merge pull request #7 from mandad/master
Timewarp setting & getting
2 parents 9dc948f + fb328ec commit 300a0b9

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/.DS_Store
2+
/build
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()

pyMOOS.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ BOOST_PYTHON_MODULE(pymoos)
398398
bp::def("time", &MOOSTime, time_overloads());
399399
bp::def("local_time", &MOOSLocalTime, time_overloads());
400400
bp::def("is_little_end_in", &IsLittleEndian);
401+
bp::def("set_moos_timewarp", &SetMOOSTimeWarp);
402+
bp::def("get_moos_timewarp", &GetMOOSTimeWarp);
401403

402404
bp::register_exception_translator<pyMOOSException>(&MOOSExceptionTranslator);
403405

0 commit comments

Comments
 (0)