-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockSensorModule.py
More file actions
executable file
·36 lines (27 loc) · 995 Bytes
/
mockSensorModule.py
File metadata and controls
executable file
·36 lines (27 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
import os, random
import robomodules as rm
from messages import *
ADDRESS = os.environ.get("BIND_ADDRESS","localhost")
PORT = os.environ.get("BIND_PORT", 11297)
FREQUENCY = 2
class MockSensorModule(rm.ProtoModule):
def __init__(self, addr, port):
self.subscriptions = []
super().__init__(addr, port, message_buffers, MsgType, FREQUENCY)
def msg_received(self, msg, msg_type):
# This gets called whenever any message is received
# This module only sends data, so we ignore incoming messages
return
def tick(self):
# this function will get called in a loop with FREQUENCY frequency
# for this mock module we will just send a random int
msg = MockMsg()
msg.mockValue = random.randint(1, 9)
msg = msg.SerializeToString()
self.write(msg, MsgType.MOCK_MSG)
def main():
module = MockSensorModule(ADDRESS, PORT)
module.run()
if __name__ == "__main__":
main()