01234567890123456789012345678901234567890123456789012345678901234567890123456789
613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 11951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
<----SKIPPED LINES---->
def ServoMain(to_arduino_q, to_parent_q, shutdown):
"""Main servo controller for projecting the plane position on a hemisphere.
Takes the latest flight from the to_arduino_q and converts that to the current
azimuth and altitude of the plane on a hemisphere.
"""
sys.stderr = open(messageboard.STDERR_FILE, 'a')
Log('Process started with process id %d' % os.getpid())
# Ensures that the child can exit if the parent exits unexpectedly
# docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue.cancel_join_thread
to_arduino_q.cancel_join_thread()
to_parent_q.cancel_join_thread()
# write_format: azimuth, altitude, R, G, & B intensity
# read heartbeat: millis
link = Serial(
*SERVO_CONNECTION, read_timeout=7,
error_pin=messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, to_parent_q=to_parent_q,
read_format='l', write_format='ff???', name='Servo')
link.Open()
last_flight = {}
last_angles = (0, 0)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
now = GetNow(json_desc_dict, additional_attr)
while not shutdown.value:
if not to_arduino_q.empty():
flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get(
block=False)
if 'test_servos' in configuration:
messageboard.RemoveSetting(configuration, 'test_servos')
link.Write((0, 0, *LASER_RGB_OFF))
<----SKIPPED LINES---->
('setting_max_altitude', 'L'), # 4 bytes
('setting_on_time', 'H'), # 2 bytes
('setting_off_time', 'H'), # 2 bytes
('setting_delay', 'H'), # 2 bytes
('line1', '9s'), # 9 bytes; 8 character plus terminator
('line2', '9s'), # 9 bytes; 8 character plus terminator
('line1_dec_mask', 'H'), # 2 bytes
('line2_dec_mask', 'H'), # 2 bytes
('display_mode', 'H'), # 2 bytes
('last_flight_available', '?'), # 1 byte
)
#pylint: enable = bad-whitespace
read_keys, unused_read_format_tuple, read_format_string = SplitFormat(read_config)
write_keys, write_format_tuple, write_format_string = SplitFormat(write_config)
values_d = {}
low_batt = False
to_parent_q.put(('pin', (messageboard.GPIO_ERROR_BATTERY_CHARGE, low_batt)))
link = Serial(
*REMOTE_CONNECTION, read_timeout=7,
error_pin=messageboard.GPIO_ERROR_ARDUINO_REMOTE_CONNECTION, to_parent_q=to_parent_q,
read_format=read_format_string, write_format=write_format_string, name='Remote')
link.Open()
# Read in the saved display mode, if it exists
display_mode = messageboard.ReadFile(REMOTE_DISPLAY_MODE, log_exception=False)
if not display_mode:
display_mode = DISP_LAST_FLIGHT_NUMB_ORIG_DEST
else:
display_mode = int(display_mode)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
while not shutdown.value:
if not to_arduino_q.empty():
to_arduino_message = to_arduino_q.get(block=False)
flight, json_desc_dict, configuration, additional_attr = to_arduino_message
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 11951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
<----SKIPPED LINES---->
def ServoMain(to_arduino_q, to_parent_q, shutdown):
"""Main servo controller for projecting the plane position on a hemisphere.
Takes the latest flight from the to_arduino_q and converts that to the current
azimuth and altitude of the plane on a hemisphere.
"""
sys.stderr = open(messageboard.STDERR_FILE, 'a')
Log('Process started with process id %d' % os.getpid())
# Ensures that the child can exit if the parent exits unexpectedly
# docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue.cancel_join_thread
to_arduino_q.cancel_join_thread()
to_parent_q.cancel_join_thread()
# write_format: azimuth, altitude, R, G, & B intensity
# read heartbeat: millis
link = Serial(
*SERVO_CONNECTION, #read_timeout=7, TODO: maybe without this read timeout, we won't get the correlated BT failures
error_pin=messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, to_parent_q=to_parent_q,
read_format='l', write_format='ff???', name='Servo')
link.Open()
last_flight = {}
last_angles = (0, 0)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
now = GetNow(json_desc_dict, additional_attr)
while not shutdown.value:
if not to_arduino_q.empty():
flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get(
block=False)
if 'test_servos' in configuration:
messageboard.RemoveSetting(configuration, 'test_servos')
link.Write((0, 0, *LASER_RGB_OFF))
<----SKIPPED LINES---->
('setting_max_altitude', 'L'), # 4 bytes
('setting_on_time', 'H'), # 2 bytes
('setting_off_time', 'H'), # 2 bytes
('setting_delay', 'H'), # 2 bytes
('line1', '9s'), # 9 bytes; 8 character plus terminator
('line2', '9s'), # 9 bytes; 8 character plus terminator
('line1_dec_mask', 'H'), # 2 bytes
('line2_dec_mask', 'H'), # 2 bytes
('display_mode', 'H'), # 2 bytes
('last_flight_available', '?'), # 1 byte
)
#pylint: enable = bad-whitespace
read_keys, unused_read_format_tuple, read_format_string = SplitFormat(read_config)
write_keys, write_format_tuple, write_format_string = SplitFormat(write_config)
values_d = {}
low_batt = False
to_parent_q.put(('pin', (messageboard.GPIO_ERROR_BATTERY_CHARGE, low_batt)))
link = Serial(
*REMOTE_CONNECTION, #read_timeout=7, TODO: maybe without this read timeout, we won't get the correlated BT failures
error_pin=messageboard.GPIO_ERROR_ARDUINO_REMOTE_CONNECTION, to_parent_q=to_parent_q,
read_format=read_format_string, write_format=write_format_string, name='Remote')
link.Open()
# Read in the saved display mode, if it exists
display_mode = messageboard.ReadFile(REMOTE_DISPLAY_MODE, log_exception=False)
if not display_mode:
display_mode = DISP_LAST_FLIGHT_NUMB_ORIG_DEST
else:
display_mode = int(display_mode)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
while not shutdown.value:
if not to_arduino_q.empty():
to_arduino_message = to_arduino_q.get(block=False)
flight, json_desc_dict, configuration, additional_attr = to_arduino_message
<----SKIPPED LINES---->
|