task main(){


  start_gyro(full_scale_range);  // Fire up the gyro.  Initialize it.             Only needs to be done once.
  long x_val, y_val, z_val;      // Our assembled values.

  const string sFileName = "GYRO2000.txt";  // Our destination KML File
  TFileIOResult nIoResult;
  TFileHandle hFileHandle;
  int nFileSize = 5500;
  hFileHandle = 0;
  Delete(sFileName, nIoResult);
  OpenWrite(hFileHandle, nIoResult, sFileName, nFileSize);

  while (true){

        // Read the GYROSCOPE
        //x_val = gryo_axis_reading(0x00);    // Get x-axis in dps.
        y_val = gryo_axis_reading_linked(0x00);
        //y_val = gryo_axis_reading(0x01);    // Get x-axis in dps.
        //z_val = gryo_axis_reading(0x02);    // Get x-axis in dps.

        string str_x_val = (string)x_val;     // Turn it into a string to write to file.

        nxtDisplayTextLine(5, "%i", x_val);
        nxtDisplayTextLine(6, "%i", y_val);
        nxtDisplayTextLine(7, "%i", z_val);

        string write_coords = " ";
        strcat(write_coords, str_x_val);
        strcat(write_coords, "\r\n");         // Every line is a return and new line.
        WriteString(hFileHandle, nIoResult, write_coords);    // Write it all to file.
        wait1Msec(50);
  }
}
예제 #2
0
task main(){
  start_gyro();      // Fire up the gyro.  Initialize it.             Only needs to be done once.
  start_accl();      // Fire up the accelerometer.  Initialize it.    Only needs to be done once.
  long x_val, y_val, z_val;      // Our assembled values.

  while (true){


      // GYROSCOPE
      // Get x axis data.
      //ubyte x_hb = gyro_axis_reading(0x29);
      //ubyte x_lb = gyro_axis_reading(0x28);
      // Get y axis data.
      //ubyte y_hb = gyro_axis_reading(0x2B);
      //ubyte y_lb = gyro_axis_reading(0x2A);
      // Get z axis data.
      //ubyte z_hb = gyro_axis_reading(0x2D);
      //ubyte z_lb = gyro_axis_reading(0x2C);

      // Compute out the values.
      //x_val = (x_lb+((long)(x_hb<<8)))/10;
      //y_val = (y_lb+((long)(y_hb<<8)))/10;
      //z_val = (z_lb+((long)(z_hb<<8)))/10;

      //nxtDisplayTextLine(5, "%i", x_val);
      //nxtDisplayTextLine(6, "%i", y_val);
      //nxtDisplayTextLine(7, "%i", z_val);

      // ACCELEROMETER
      // In this example, we'll just get the 8-bit data.  This can be extended to
      // 10 bit by going into the data sheet.

      byte x_acc = accl_axis_reading(0x06);         // Get x axis data.
      //byte y_acc = accl_axis_reading(0x07);         // Get y axis data.
      //byte z_acc = accl_axis_reading(0x08);         // Get z axis data.

      // 2g is 64 LSB/g
      // 4g is 32 LSB/g  //
      // 8g is 16 LSB/g  // Also note if 8g, must use LSB/MSB

      nxtDisplayTextLine(1, "%i", x_acc);
      //nxtDisplayTextLine(2, "%i", y_acc);
      //nxtDisplayTextLine(3, "%i", z_acc);

    wait1Msec(5);
  }
}
예제 #3
0
/*************************************************************************************************
          Main
**************************************************************************************************/
void main(void)
{
 
  HAL_BOARD_INIT();
  
  UART_init();
  U0CSR &= ~0x04;
  ENABLE_RX();
  
  /*setup sensors*/
  sensors_init();
  sensor_int_init();
  
  /* Setup LED's */  
  P1DIR |= BV(0);
  P0DIR |= BV(4);
  
  P1_0 = 0;
 
   
  start_gyro(); //start the gyro
  init_acc();   //start the accelerometer
  start_mag();
  start_baro();
  
  //zero_mag();
  
  EA = 1;

  SLEEPCMD |= 0x02;  //pm 2
  
  uint8 flag;
  uint8 IDbyte;
  
  
  uint8 baro_stage = 1;

  
   while(1){      
        
     if (RXin)
     {
      //If it is a cal data request 
      if ( active_sensors & BV(4) )
      {
        flag = 0x03;
        flush_data(&flag);
        baro_read_cal();
        
        //End of line char
        flag = 0x00;
        flush_byte(&flag);
        
      } else if ( active_sensors > 0 ) {
       
     //  P0_4 = 1;
    /**************************************************************************/
    /* Read and transmit sensor data                                          */
    flag = 0x04;
    flush_byte(&flag);   
    flush_byte(&active_sensors);
     
    /*---------------------------------------------------------------------*/ 
    //Read accelerometer and gyro
    
     if ( active_sensors & BV(0) )
     {       
       IDbyte = BV(0);
       flush_data(&IDbyte);
      
      while( !( acc_int_status() ) ); //wait for interrupt 
      read_acc();                 //read the accelerometer

      while( !(gyro_int_status() & BV(0) ) ); //wait for interrupt
      read_gyro();

     }
    
    /*---------------------------------------------------------------------*/
    //Read Magnetometer
    //start_interrupts(MAG_INT);
     
     if ( active_sensors & BV(1) )
     {
       
    
       IDbyte = BV(1);
       flush_data(&IDbyte);
       
       //PCON |= 1;
       while( !(mag_status() & 0x08 ) );
       read_mag();
 
      // mag_sleep(TRUE);  
     } 
    
    /*---------------------------------------------------------------------*/
    //Barometer
    
    //uint16 delay_ticks;
    uint8 baro_res = 2;
    
    
    if ( active_sensors & BV(2) )
    {
       IDbyte = BV(2);
       flush_data(&IDbyte);
       
       if (active_sensors & 0x40)
       {
         //delay_ticks = 0xFA00;
         baro_capture_press(baro_res);
         //while(delay_ticks--);
         baro_read_press(TRUE);
         
         //delay_ticks = 0xFA00;         
         baro_capture_temp();
         //while(delay_ticks--);
         baro_read_temp(TRUE); 
       }else{
      
         uint8 nullbyte = 3;
         switch (baro_stage)
         {
         case 1 :
            baro_capture_press(baro_res);
            baro_read_press(FALSE);
            baro_read_temp(FALSE);
            baro_stage++;
            break;
         case 2 :
            baro_read_press(TRUE);
            baro_read_temp(FALSE);
            baro_stage++;
            break;
         case 3 :
            baro_capture_temp();
            baro_read_press(FALSE);
            baro_read_temp(FALSE);
            baro_stage++;
            break;
         case 4 :
           baro_read_press(FALSE);
           baro_read_temp(TRUE);
           baro_stage = 1;
           break;
         }
       }

      //baro_shutdown();
    }
    
    /*---------------------------------------------------------------------*/
    //Humidity
    
    if ( active_sensors & BV(3) )
    {
      IDbyte = BV(3);
      flush_data(&IDbyte);
      humid_init();
      humid_read_humidity(TRUE);
    }
    
    /*---------------------------------------------------------------------*/

    
    //End of line char
    flag = 0x00;
    flush_byte(&flag);
    
    }
       

    if ( !(active_sensors & BV(5)) )        //if autopoll is off
    {
      P0_4 = 1;
      RXin = 0;                             //clear the RX flag
    }else{
      P0_4 = 0;
    }

    }
    
   IEN0 |= 0x04; 
   U0CSR &= ~0x04;
   }
   
}