arduino-2020-06-04-2040.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658








660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708











                            <----SKIPPED LINES---->




  # 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)
  flight_present = False

  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))
        time.sleep(1)
        link.Write((90, 0, *LASER_RGB_OFF))
        time.sleep(1)
        link.Write((180, 0, *LASER_RGB_OFF))
        time.sleep(1)
        link.Write((270, 0, *LASER_RGB_OFF))

      new_flight = DifferentFlights(flight, last_flight)
      if new_flight:
        Log('Flight changed from %s to %s' % (
            messageboard.DisplayFlightNumber(last_flight),




                            <----SKIPPED LINES---->




        ), ser=link)

        # Turn off laser so that line isn't traced while it moves to new position
        link.Write((*last_angles, *LASER_RGB_OFF))

      last_flight = flight

    if time.time() >= next_read:
      heartbeat = link.Read()  # simple ack message sent by servos
      next_read = time.time() + READ_DELAY_TIME
      if heartbeat:
        Log(heartbeat)

    now = GetNow(json_desc_dict, additional_attr)

    current_angles = AzimuthAltitude(flight, now)
    if current_angles and time.time() > next_write:
      if current_angles[1] >= configuration['minimum_altitude_servo_tracking']:
        Log('Flight #: %s current_angles: %s' % (
            messageboard.DisplayFlightNumber(flight), str(current_angles)))
        flight_present = True
        laser_rgb = LaserRGBFlight(flight)
        link.Write((*current_angles, *laser_rgb))
        last_angles = current_angles

      # flight no longer tracked; send one more command to turn off lasers
      elif flight_present:
        link.Write((*last_angles, *LASER_RGB_OFF))
        flight_present = False

      next_write = time.time() + WRITE_DELAY_TIME

  link.Close(SHUTDOWN_TEXT)


LASER_RGB_OFF = (0, 0, 0)
def LaserRGBFlight(flight):
  """Based on flight attributes, set the laser."""
  if not flight:
    return LASER_RGB_OFF
  return 1, 0, 0


def DifferentFlights(f1, f2):
  """True if both squawk and flight number different; false otherwise."""
  if f1 is None and f2 is None:
    return True
  if f1 is None or f2 is None:
    return True




                            <----SKIPPED LINES---->





01234567890123456789012345678901234567890123456789012345678901234567890123456789









618619620621622623624625626627628629630631632633634635636637 638639640641642643644645646647648649650651652653654655656657








659660661662663664665666667668669670671672673674675676677678 679680681682683 684 685686687688689690691692693694695696697698699700701702703704











                            <----SKIPPED LINES---->




  # 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))
        time.sleep(1)
        link.Write((90, 0, *LASER_RGB_OFF))
        time.sleep(1)
        link.Write((180, 0, *LASER_RGB_OFF))
        time.sleep(1)
        link.Write((270, 0, *LASER_RGB_OFF))

      new_flight = DifferentFlights(flight, last_flight)
      if new_flight:
        Log('Flight changed from %s to %s' % (
            messageboard.DisplayFlightNumber(last_flight),




                            <----SKIPPED LINES---->




        ), ser=link)

        # Turn off laser so that line isn't traced while it moves to new position
        link.Write((*last_angles, *LASER_RGB_OFF))

      last_flight = flight

    if time.time() >= next_read:
      heartbeat = link.Read()  # simple ack message sent by servos
      next_read = time.time() + READ_DELAY_TIME
      if heartbeat:
        Log(heartbeat)

    now = GetNow(json_desc_dict, additional_attr)

    current_angles = AzimuthAltitude(flight, now)
    if current_angles and time.time() > next_write:
      if current_angles[1] >= configuration['minimum_altitude_servo_tracking']:
        Log('Flight #: %s current_angles: %s' % (
            messageboard.DisplayFlightNumber(flight), str(current_angles)))

        laser_rgb = LaserRGBFlight(flight)
        link.Write((*current_angles, *laser_rgb))
        last_angles = current_angles

      else:

        link.Write((*last_angles, *LASER_RGB_OFF))


      next_write = time.time() + WRITE_DELAY_TIME

  link.Close(SHUTDOWN_TEXT)


LASER_RGB_OFF = (0, 0, 0)
def LaserRGBFlight(flight):
  """Based on flight attributes, set the laser."""
  if not flight:
    return LASER_RGB_OFF
  return 1, 0, 0


def DifferentFlights(f1, f2):
  """True if both squawk and flight number different; false otherwise."""
  if f1 is None and f2 is None:
    return True
  if f1 is None or f2 is None:
    return True




                            <----SKIPPED LINES---->