Example #1
0
static void cmd_bias(BaseSequentialStream *chp, int argc, char *argv[]) {
  (void)argv;
  if (argc != 1) {
    chprintf(chp, "Usage: bias [sample|reset]\r\n");
    return;
  }
  if(!strcmp (argv[0], "sample")) {
#if CHPRINTF_USE_ANSI_CODE
    chprintf(chp, "\033[2J\033[1;1H");
#endif
    chprintf(chp, "Please don't move the device while Green LED is on!\r\n");
    chprintf(chp, "Press a key to start...\r\n");
    while (chnGetTimeout((BaseChannel *)chp, 500) == Q_TIMEOUT)
      ;
    palSetLine(LINE_LED4);

    chThdSleepMilliseconds(1000);
    gyroscopeSampleBias(&L3GD20D1);
    palClearLine(LINE_LED4);


    chprintf(chp, "Procedure completed!\r\n");
  }
  else if(!strcmp (argv[0], "reset")) {
#if CHPRINTF_USE_ANSI_CODE
    chprintf(chp, "\033[2J\033[1;1H");
#endif
    gyroscopeResetBias(&L3GD20D1);
    chprintf(chp, "Bias correction removed!\r\n");
  }
  else {
    chprintf(chp, "Usage: bias [sample|reset]\r\n");
    return;
  }
}
Example #2
0
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);

  /*
   * L3GD20 Object Initialization
   */
  l3gd20ObjectInit(&L3GD20D1);

  /*
   * Activates the L3GD20 driver.
   */
  l3gd20Start(&L3GD20D1, &l3gd20cfg);

  while(!palReadLine(LINE_BUTTON)){
    chprintf(chp, "Press BTN to calibrate gyroscope...\r\n");
    chThdSleepMilliseconds(150);
#if CHPRINTF_USE_ANSI_CODE
    chprintf(chp, "\033[2J\033[1;1H");
#endif
  }

  chprintf(chp, "Calibrating Gyroscope sampling bias...\r\n");
  chprintf(chp, "Keep it in the rest position while red LED is on\r\n");
  chThdSleepMilliseconds(3000);

  palSetLine(LINE_LED10_RED);
  chThdSleepMilliseconds(1000);

  gyroscopeSampleBias(&L3GD20D1);
  palClearLine(LINE_LED10_RED);
#if CHPRINTF_USE_ANSI_CODE
  chprintf(chp, "\033[2J\033[1;1H");
#endif

  while (TRUE) {
    palToggleLine(LINE_LED10_RED);
    gyroscopeReadRaw(&L3GD20D1, rawdata);
    for(i = 0; i < L3GD20_NUMBER_OF_AXES; i++)
      chprintf(chp, "RAW-%c:%d\r\n", axesID[i], rawdata[i]);

    gyroscopeReadCooked(&L3GD20D1, cookeddata);
    for(i = 0; i < L3GD20_NUMBER_OF_AXES; i++)
      chprintf(chp, "COOKED-%c:%.3f\r\n", axesID[i], cookeddata[i]);

    gyroscopeGetTemp(&L3GD20D1, &temperature);
    chprintf(chp, "TEMP:%.1f C°\r\n", temperature);

    chThdSleepMilliseconds(150);
#if CHPRINTF_USE_ANSI_CODE
    chprintf(chp, "\033[2J\033[1;1H");
#endif
  }
  l3gd20Stop(&L3GD20D1);
}