Example #1
0
def main():
    if len(sys.argv) == 3:
        serialID = sys.argv[2]
    else:
        serialID = 'LOCL'

    linkbot = TestLinkbot(serialID)

    print('Testing robot:', linkbot.getSerialId())
    # Get firmware checksum
    print('Firmware checksum:', linkbot.readEeprom(0x423, 2))

    # Test LED
    print('Testing LED...')
    linkbot.setLedColor(255, 0, 0)
    time.sleep(1)
    linkbot.setLedColor(0, 255, 0)
    time.sleep(1)
    linkbot.setLedColor(0, 0, 255)

    # Test buzzer
    print('Testing buzzer...')
    for i in range(440, 550, 5):
        linkbot.setBuzzerFrequency(i)
    linkbot.setBuzzerFrequency(0)

    print('Current accel readings: ' + str(linkbot.getAccelerometer()))

    print('Press all three buttons on the Linkbot...')

    def buttonCB(button, state, timestamp):
        global buttons
        buttons = buttons & ~(1 << button)

    linkbot.enableButtonEvents(buttonCB)
    while buttons:
        time.sleep(1)

    print('Testing motor power...')
    for i in range(1, 4):
        linkbot.setMotorPower(i, 128)
        time.sleep(1)
        linkbot.setMotorPower(i, -128)
        time.sleep(1)
        linkbot.setMotorPower(i, 0)

    print(
        'Testing encoders... Move the encoders around to generate encoder events.'
    )

    def encoderCB(jointNo, angle, timestamp):
        print(jointNo, angle, timestamp)

    linkbot.enableEncoderEvents(5, encoderCB)

    input('Press Enter to quit.')

    linkbot.disableEncoderEvents()
def main():
  if len(sys.argv) == 3:
    serialID = sys.argv[2]
  else:
    serialID = 'LOCL'

  linkbot = TestLinkbot(serialID)

  print('Testing robot:', linkbot.getSerialId())
  # Get firmware checksum
  print('Firmware checksum:', linkbot.readEeprom(0x423, 2))

  # Test LED
  print('Testing LED...')
  linkbot.setLedColor(255, 0, 0)
  time.sleep(1)
  linkbot.setLedColor(0, 255, 0)
  time.sleep(1)
  linkbot.setLedColor(0, 0, 255)

  # Test buzzer
  print('Testing buzzer...')
  for i in range(440, 550, 5):
      linkbot.setBuzzerFrequency(i)
  linkbot.setBuzzerFrequency(0)

  print('Current accel readings: ' + str(linkbot.getAccelerometer()))

  print('Press all three buttons on the Linkbot...')
  def buttonCB(button, state, timestamp):
    global buttons
    buttons = buttons & ~(1<<button)
  linkbot.enableButtonEvents(buttonCB)
  while buttons:
      time.sleep(1)

  print('Testing motor power...')
  for i in range(1,4):
      linkbot.setMotorPower(i, 128)
      time.sleep(1)
      linkbot.setMotorPower(i, -128)
      time.sleep(1)
      linkbot.setMotorPower(i, 0)
    
  print('Testing encoders... Move the encoders around to generate encoder events.')

  def encoderCB(jointNo, angle, timestamp):
    print(jointNo, angle, timestamp)
  

  linkbot.enableEncoderEvents(5, encoderCB)

  input('Press Enter to quit.')

  linkbot.disableEncoderEvents()
Example #3
0
def main():
    if len(sys.argv) == 2:
        serialID = sys.argv[1]
    else:
        serialID = 'LOCL'

    linkbot = TestLinkbot(serialID)

    print('Testing robot:', linkbot.getSerialId())
    # Get firmware checksum
    print('Firmware checksum:', linkbot.readEeprom(0x423, 2))

    # Test LED
    print('Testing LED...')
    linkbot.setLedColor(255, 0, 0)
    time.sleep(1)
    linkbot.setLedColor(0, 255, 0)
    time.sleep(1)
    linkbot.setLedColor(0, 0, 255)

    # Test buzzer
    print('Testing buzzer...')
    for i in range(440, 550, 5):
        linkbot.setBuzzerFrequency(i)
    linkbot.setBuzzerFrequency(0)

    print('Current accel readings: ' + str(linkbot.getAccelerometer()))

    print('Press all three buttons on the Linkbot...')

    def buttonCB(button, state, timestamp):
        global buttons
        buttons = buttons & ~(1 << button)

    linkbot.enableButtonEvents(buttonCB)
    while buttons:
        time.sleep(1)

    # con = sql.connect('testlog.db')
    initialize_tables(con.cursor())
    cur = con.cursor()
    # Check to see if this linkbot is in our database already. Add it if not
    cur.execute('SELECT * FROM robot_type WHERE Id=\'{}\''.format(
        linkbot.getSerialId()))
    rows = cur.fetchall()
    formFactor = None
    if linkbot.getFormFactor() == Linkbot.FormFactor.I:
        formFactor = "Linkbot-I"
        motor2index = 2
    elif linkbot.getFormFactor() == Linkbot.FormFactor.L:
        formFactor = "Linkbot-L"
        motor2index = 1
    else:
        formFactor = "UNKNOWN"
    print("Testing LinkBot {}".format(linkbot.getSerialId()))
    d = LinkbotDiagnostic(linkbot)
    results = d.runLinearityTest()
    now = time.strftime('%Y-%m-%d %H:%M:%S')
    if len(rows) == 0:
        cur.execute('INSERT INTO robot_type VALUES(\'{}\', \'{}\')'.format(
            linkbot.getSerialId(), formFactor))
    cur.execute("INSERT INTO linearity_tests "
                "VALUES('{}', '{}', {}, {}, {}, {}, {}, {}, {}, {})".format(
                    linkbot.getSerialId(), now, results[0]['forward_slope'],
                    results[0]['forward_rvalue'], results[0]['backward_slope'],
                    results[0]['backward_rvalue'],
                    results[motor2index]['forward_slope'],
                    results[motor2index]['forward_rvalue'],
                    results[motor2index]['backward_slope'],
                    results[motor2index]['backward_rvalue']))

    con.commit()
    con.close()
    linkbot.setBuzzerFrequency(440)
    time.sleep(0.5)
    linkbot.setBuzzerFrequency(0)
def oldmain():
  if len(sys.argv) == 2:
    serialID = sys.argv[1]
  else:
    serialID = 'LOCL'

  linkbot = TestLinkbot(serialID)

  print('Testing robot:', linkbot.getSerialId())
  # Get firmware checksum
  print('Firmware checksum:', linkbot.readEeprom(0x423, 2))

  # Test LED
  print('Testing LED...')
  linkbot.setLedColor(255, 0, 0)
  time.sleep(1)
  linkbot.setLedColor(0, 255, 0)
  time.sleep(1)
  linkbot.setLedColor(0, 0, 255)

  # Test buzzer
  print('Testing buzzer...')
  for i in range(440, 550, 5):
      linkbot.setBuzzerFrequency(i)
  linkbot.setBuzzerFrequency(0)

  print('Current accel readings: ' + str(linkbot.getAccelerometer()))

  print('Press all three buttons on the Linkbot...')
  def buttonCB(button, state, timestamp):
    global buttons
    buttons = buttons & ~(1<<button)
  linkbot.enableButtonEvents(buttonCB)
  while buttons:
      time.sleep(1)

  con = sql.connect('testlog.db')
  initialize_tables(con.cursor())
  cur = con.cursor()
# Check to see if this linkbot is in our database already. Add it if not
  cur.execute('SELECT * FROM robot_type WHERE Id=\'{}\''.format(linkbot.getSerialId()))
  rows = cur.fetchall()
  formFactor = None
  if linkbot.getFormFactor() == Linkbot.FormFactor.I:
    formFactor = "Linkbot-I"
    motor2index = 2
  elif linkbot.getFormFactor() == Linkbot.FormFactor.L:
    formFactor = "Linkbot-L"
    motor2index = 1
  else:
    formFactor = "UNKNOWN"
  print ("Testing LinkBot {}".format(linkbot.getSerialId()))
  d = LinkbotDiagnostic(linkbot)
  results = d.runLinearityTest()
  now = time.strftime('%Y-%m-%d %H:%M:%S')
  if len(rows) == 0:
    cur.execute('INSERT INTO robot_type VALUES(\'{}\', \'{}\')'.format(
        linkbot.getSerialId(), formFactor))
  cur.execute("INSERT INTO linearity_tests "
    "VALUES('{}', '{}', {}, {}, {}, {}, {}, {}, {}, {})".format(
      linkbot.getSerialId(),
      now,
      results[0]['forward_slope'],
      results[0]['forward_rvalue'],
      results[0]['backward_slope'],
      results[0]['backward_rvalue'],
      results[motor2index]['forward_slope'],
      results[motor2index]['forward_rvalue'],
      results[motor2index]['backward_slope'],
      results[motor2index]['backward_rvalue']))

  con.commit()
  con.close()
  linkbot.setBuzzerFrequency(440)
  time.sleep(0.5)
  linkbot.setBuzzerFrequency(0)