01234567890123456789012345678901234567890123456789012345678901234567890123456789
896897898899900901902903904905906907908909910911912913914915 916917918919920921922923924925926927928929930931932933934935 954955956957958959960961962963964965966967968969970971972973 974975976977 978979980 981982 983984985986987988989990991992993994995996997998999100010011002 | <----SKIPPED LINES----> #pylint: enable = bad-whitespace write_keys, write_format_tuple, write_format_string = SplitFormat( write_config) # write_format: azimuth, altitude, R, G, & B intensity # read heartbeat: millis link = Serial( *SERVO_CONNECTION, read_timeout=60, error_pin=messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, to_parent_q=to_parent_q, read_format='l', write_format=write_format_string, name='Servo') link.Open() last_flight = {} flight, json_desc_dict, configuration, additional_attr = InitialMessageValues( to_arduino_q) next_read = 0 next_write = 0 now = GetNow(json_desc_dict, additional_attr) gamma = GetGamma(configuration) while not shutdown.value: SetLoggingGlobals(configuration) if not to_arduino_q.empty(): flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get( block=False) if 'test_servos_ordinal' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_ordinal') ServoTestOrdinal(link, write_keys, write_format_tuple) elif 'test_servos_sweep' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_sweep') ServoTestSweep(link, write_keys, write_format_tuple) elif 'test_servos_rgb' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_rgb') ServoTestRgb(link, write_keys, write_format_tuple) elif 'test_servos_dim' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_dim') ServoTestDim( link, write_keys, write_format_tuple, <----SKIPPED LINES----> if time.time() >= next_read: heartbeat = link.Read() # simple ack message sent by servos next_read = time.time() + READ_DELAY_TIME_SERVO if heartbeat and VERBOSE: Log('Heartbeat read by Servo: %s' % str(heartbeat)) now = GetNow(json_desc_dict, additional_attr) current_angles = AzimuthAltitude(flight, now) if time.time() > next_write: if (current_angles and current_angles[1] >= configuration['minimum_altitude_servo_tracking'] and configuration['servo_mode'] in ('laser_only', 'both')): if VERBOSE: Log('Flight #: %s current_angles: %s' % ( messageboard.DisplayFlightNumber(flight), str(current_angles))) laser_rgb = LaserRGBFlight(flight) message_dict = GenerateServoMessage( laser=laser_rgb, angles=current_angles, led=LED_OFF) elif configuration['servo_mode'] == 'laser_only': message_dict = GenerateServoMessage(laser=LASER_OFF, led=LED_OFF) else: rgb_tuple = GammaRGB( HexColorToRGBTuple(configuration['led_color']), gamma) message_dict = GenerateServoMessage(laser=LASER_OFF, led=rgb_tuple) message_tuple = DictToValueTuple( message_dict, write_keys, write_format_tuple) link.Write(message_tuple) next_write = time.time() + WRITE_DELAY_TIME # One final write telling Arduino to do a software reset message_dict = GenerateServoMessage(laser=LASER_OFF, reset=True) message_tuple = DictToValueTuple(message_dict, write_keys, write_format_tuple) link.Write(message_tuple) link.Close(SHUTDOWN_TEXT) def LaserRGBFlight(flight): """Based on flight attributes, set the laser.""" # Possible assignment based on: # - ascending / descending / level <----SKIPPED LINES----> |
01234567890123456789012345678901234567890123456789012345678901234567890123456789
896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937 956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017 | <----SKIPPED LINES----> #pylint: enable = bad-whitespace write_keys, write_format_tuple, write_format_string = SplitFormat( write_config) # write_format: azimuth, altitude, R, G, & B intensity # read heartbeat: millis link = Serial( *SERVO_CONNECTION, read_timeout=60, error_pin=messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, to_parent_q=to_parent_q, read_format='l', write_format=write_format_string, name='Servo') link.Open() last_flight = {} flight, json_desc_dict, configuration, additional_attr = InitialMessageValues( to_arduino_q) next_read = 0 next_write = 0 now = GetNow(json_desc_dict, additional_attr) gamma = GetGamma(configuration) brightness = 1.0 brightness_step = 0.1 while not shutdown.value: SetLoggingGlobals(configuration) if not to_arduino_q.empty(): flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get( block=False) if 'test_servos_ordinal' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_ordinal') ServoTestOrdinal(link, write_keys, write_format_tuple) elif 'test_servos_sweep' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_sweep') ServoTestSweep(link, write_keys, write_format_tuple) elif 'test_servos_rgb' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_rgb') ServoTestRgb(link, write_keys, write_format_tuple) elif 'test_servos_dim' in configuration: messageboard.RemoveSetting(configuration, 'test_servos_dim') ServoTestDim( link, write_keys, write_format_tuple, <----SKIPPED LINES----> if time.time() >= next_read: heartbeat = link.Read() # simple ack message sent by servos next_read = time.time() + READ_DELAY_TIME_SERVO if heartbeat and VERBOSE: Log('Heartbeat read by Servo: %s' % str(heartbeat)) now = GetNow(json_desc_dict, additional_attr) current_angles = AzimuthAltitude(flight, now) if time.time() > next_write: if (current_angles and current_angles[1] >= configuration['minimum_altitude_servo_tracking'] and configuration['servo_mode'] in ('laser_only', 'both')): if VERBOSE: Log('Flight #: %s current_angles: %s' % ( messageboard.DisplayFlightNumber(flight), str(current_angles))) laser_rgb = LaserRGBFlight(flight) if brightness > 0: brightness -= brightness_step rgb_tuple = GammaRGB( HexColorToRGBTuple(configuration['led_color']), gamma, brightness=brightness) message_dict = GenerateServoMessage( laser=laser_rgb, angles=current_angles, led=rgb_tuple) elif configuration['servo_mode'] == 'laser_only': if brightness > 0: brightness -= brightness_step rgb_tuple = GammaRGB( HexColorToRGBTuple(configuration['led_color']), gamma, brightness=brightness) message_dict = GenerateServoMessage(laser=LASER_OFF, led=rgb_tuple) else: if brightness < 1: brightness += brightness_step rgb_tuple = GammaRGB( HexColorToRGBTuple(configuration['led_color']), gamma, brightness=brightness) message_dict = GenerateServoMessage(laser=LASER_OFF, led=rgb_tuple) message_tuple = DictToValueTuple( message_dict, write_keys, write_format_tuple) link.Write(message_tuple) next_write = time.time() + WRITE_DELAY_TIME # One final write telling Arduino to do a software reset message_dict = GenerateServoMessage(laser=LASER_OFF, reset=True) message_tuple = DictToValueTuple(message_dict, write_keys, write_format_tuple) link.Write(message_tuple) link.Close(SHUTDOWN_TEXT) def LaserRGBFlight(flight): """Based on flight attributes, set the laser.""" # Possible assignment based on: # - ascending / descending / level <----SKIPPED LINES----> |