Mission and multiprocessingΒΆ
Mission is responsible for spreading the robotic processing out over a the four cores of the Nvidia TX1. This section is Unix only!
"""
This node represents a data collection unit. In particular, this is what will
be implimented for the zed camera.
"""
import os, time, sys
import pickle
import numpy as np
from zoidberg import utils
pipe_name = 'pipe_test'
def parent():
if not os.path.exists(pipe_name):
print("No pipe exists, exiting")
return
# generate some fake data
stamped_data = [utils.timestamp(), np.random.randn(3, 3)]
outobj = pickle.dumps(stamped_data)
#Make sure that the pipe is cleared before putting new data out
try:
pipe = os.open(pipe_name, os.O_RDONLY | os.O_NONBLOCK)
line = os.read(pipe, 0)
except OSError as err:
print(err)
if err.errno == 11:
# this error indicates that the pipe has no data in it
pass
else:
raise err
finally:
os.close(pipe)
# Dump latest data to pipe
try:
pipe = os.open(pipe_name, os.O_WRONLY | os.O_NONBLOCK)
os.write(pipe, outobj)
os.close(pipe)
except OSError as err:
if err.errno == 6:
# This error indicates no consumer is connected to pipe
pass
else:
raise err
if __name__ == "__main__":
if not os.path.exists(pipe_name):
os.mkfifo(pipe_name)
try:
while True:
parent()
time.sleep(.5)
finally:
os.unlink(pipe_name)
"""
This node represents a data processing unit.
It is important that this works
the same way in two cases: when processing is faster than data collection, and
when processing is slower than data collection. In both cases this node expects
to read the latest data reading, and only the latest data reading, each time
it checks the pipe
"""
import os, time, sys
import pickle
import numpy as np
pipe_name = 'pipe_test'
def child():
# blocking wait for data
with open(pipe_name, 'rb') as infile:
line = infile.read()
data_out = pickle.loads(line)
print(data_out[0])
print(data_out[1])
if __name__=="__main__":
for _ in range(10):
child()
time.sleep(.001)