Exemplo n.º 1
0
int main(void)
{ 
  RCC_Configuration();		 	//配置RCC
	initDesireAngles();
	
	TIMER4_Enable();					//定时器4
	TIMER4_Configuration();		//配置中断
	
  USART1_GPIO_Config();		 	//配置GPIO
	USART1_NVIC_Config();			//配置中断
  USART1_Configuration();	 	//配置串口1
	
	USART2_GPIO_Config();
	USART2_Configuration();

	I2C_GPIO_Config();				//配置IIC使用端口
  Delayms(10);				 			//延时
	Init_MPU6050();		     //初始化MPU6050
	
	PWM_Configuration();
		
	while(1)
	{

	}
	 			//回车
	
}
Exemplo n.º 2
0
void rt_init_thread_entry(void* parameter)
{
    /* init board */
    //    rt_hw_led_init();
    I2C_init();
    pwm_init();
    Init_MPU6050();
    HMC5883L_Initialize();

    //    at_application_init();

#ifdef RT_USING_COMPONENTS_INIT
    /* initialization RT-Thread Components */
    rt_components_init();
#endif

#ifdef  RT_USING_FINSH
    finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif  /* RT_USING_FINSH */

    /* Filesystem Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
    /* mount sd card fat partition 1 as root directory */
    if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
    {
        rt_kprintf("File System initialized!\n");
    }
    else
        rt_kprintf("File System initialzation failed!\n");
#endif  /* RT_USING_DFS */

    at_application_init();
    BT_application_init();
    imu_application_init();
}
Exemplo n.º 3
0
//----------------------------------------------------------------------------------------------------------------------------------------
// Hauptprogramm
//----------------------------------------------------------------------------------------------------------------------------------------
int main (void)
{ 	
	// I2C initialisieren
	I2C_LowLevel_Init(I2C1, I2C_Clockspeed , I2C_OwnAddress);		// I2C initialisieren -> Kanal 1, clockspeed, Materadresse
	
	// Systick timer initialisieren
  InitSysTick();																							// SysTick timer initialisieren (Ladewert, Clockspeed)
		
	// Timer2 initialisieren
	InitTIM2_PWM();																							// Timer 2 initialisieren -> notwendig um PWM Signal auszugeben
	
	// Aktiviere Port C für Motor Polarität
	RCC->APB2ENR |= (1UL << 4);     														// Enable GPIOC
	GPIOC->CRL		=  0x33333333;    														// PortC 0..7 als Output -> Output Mode, max speed 50MHz ; General purpose output Open-drain
	
	// MPU-6050 initialisieren
	Init_MPU6050();
	
	// Beschleunigungswerte und Drehraten vom MPU-6050 lesen
	i2cData[0] = 0x3B;
	I2C_Write(I2C1, i2cData, 1, I2C_MPUAddress);
	I2C_Read(I2C1, i2cDataRead, 14, I2C_MPUAddress);
	
	// Daten ordnen und abspeichern
	accY = ((i2cDataRead[2] << 8) | i2cDataRead[3]);
	accZ = ((i2cDataRead[4] << 8) | i2cDataRead[5]);
	gyroX = ((i2cDataRead[8] << 8) | i2cData[9]);
	
	//Kalibrierung von accY, accZ und gyroX - Werte wurden in einem Versuch ermittelt
	accY = accY - 150;
  accZ = accZ - 451.63;
  gyroX = gyroX + 273.25;
	
	//Winkel initialisieren
	accYangle = (atan2(accY, accZ))*RAD_TO_DEG; 				// Winkel aus Beschleunigungswerten berechnen
	setAngle(accYangle);																// Kalman-(Start)Winkel setzen
	gyroAngle = accYangle;															// Drehratenwinkel initialisieren
	compAngle = accYangle;															// Komplementärwinkel initialisieren
	
	SysTick->CTRL |= 0x01; 															// Systick timer einschalten - sonst würde dieser bereits vor der Inittialisierung auslösen
	
	
	//while-Schleife um auf den Interrupt des Systick timers zu warten
	while(1) {
		
	}//while

}//int main
Exemplo n.º 4
0
int main(void)
{
  int16_t data[9];

  int16_t result[3];
  int i=0;

  SystemInit();
  delay_init(72);
  GPIO_Configuration();
  Initial_UART1(115200L);
  I2C_GPIO_Config();
  NVIC_Configuration();
  
  delay_ms(10);
  Init_MPU6050();
  
  delay_ms(10);
  HMC5883L_Init();
  delay_ms(10);

  IMU_init();
  
  Initial_Timer3();
  system_microsec=micros();

  
  while(1)
  {
    //delay_ms(10);

    //if(micros()-system_microsec>upload_time)
    {
    
      Read_MPU6050_ACC(&data[0]);
      Read_MPU6050_GYRO(&data[3]);
      HMC5883L_Read(&data[6]);
      IMU_getYawPitchRoll(result,data);
      
      UART1_Put_Char(0xff);
      UART1_Put_Char(0xaa);

      /*out_int16_t(&data[0]);
      out_int16_t(&data[1]);
      out_int16_t(&data[2]);

      out_int16_t(&data[3]);
      out_int16_t(&data[4]);
      out_int16_t(&data[5]);

      out_int16_t(&data[6]);
      out_int16_t(&data[7]);
      out_int16_t(&data[8]);
      
      */
      out_int16_t(&result[0]);
      out_int16_t(&result[1]);
      out_int16_t(&result[2]);
      
      //out_int16_t(&_hlt);
      //system_microsec = micros();
    }

    

  }
		     
}
Exemplo n.º 5
0
int main(){
	
	DDRD = 0xF0;
	DDRC = 0x00;
	int i=0;
	int wifiout = 100;					//value to display on chart in Thingspeak.
	int16_t xa1, ya1, za1;
	int16_t xi1 = 0;
	int16_t yi1 = 0;
	int16_t zi1 = 0;
	//gyro
	/*int16_t gyrox, gyroy, gyroz;
	int16_t gix = 0;	//45
	int16_t giy = 0;	//47
	int16_t giz = 0;	//49*/
	
	//declare average calibrated accelerometer values
	//initialize calibarition values
	//declare accelerometer value strings

	usart_init();//initialize usart
	//USART_tx_string(test);
	i2c_init();     // init I2C interface
	_delay_ms(2000);  // Wait for 200 ms.
	Init_MPU6050(MPU60501);    // sensor init
	_delay_ms(2000);     // Wait for 200 ms.
	//snprintf(outs,sizeof(outs),"6050 initialized \n\r");
	//USART_tx_string(outs);
	
	//resetting and setting up modes of wifi module
	_delay_ms(1000);
	snprintf(ATs,sizeof(ATs), "AT+RST\r");
	USART_tx_string(ATs);
	_delay_ms(2000);
	snprintf(ATs,sizeof(ATs), "AT+CIPMODE=0\r");
	USART_tx_string(ATs);
	_delay_ms(1000);
	snprintf(ATs,sizeof(ATs), "AT+CIPMUX=1\r");
	USART_tx_string(ATs);
	_delay_ms(2000);
	
	//Start infinite loop
	while(1){
		//grab 3 values, average, and divide by MSB
		//now multiplied by 2 because doubles dont want to print. This way at lease we get usabel values.
		// read raw X acceleration from fifo
		xa1 = MPU6050_signed_readreg(MPU60501,0x3B)+MPU6050_signed_readreg(MPU60501,0x3B)+MPU6050_signed_readreg(MPU60501,0x3B);   		
		xa1 = (2.00*(xa1/3.00))/2048.00;
		// read raw Y acceleration from fifo
		ya1 = MPU6050_signed_readreg(MPU60501,0x3D)+MPU6050_signed_readreg(MPU60501,0x3D)+MPU6050_signed_readreg(MPU60501,0x3D);   
		ya1 = (2.00*(ya1/3.00))/2048.00;
		// read raw Z acceleration from fifo
		za1 = MPU6050_signed_readreg(MPU60501,0x3F)+MPU6050_signed_readreg(MPU60501,0x3F)+MPU6050_signed_readreg(MPU60501,0x3F);   
		za1 = (2.00*(za1/3.00))/2048.00;

		//print out the values
		/*snprintf(outs,sizeof(outs),"Xaxis: %2d\n\r", xa1);
		USART_tx_string(outs);
		snprintf(outs,sizeof(outs),"Yaxis: %2d\n\r", ya1);
		USART_tx_string(outs);
		snprintf(outs,sizeof(outs),"Zaxis: %2d\n\r", za1);
		USART_tx_string(outs);
		_delay_ms(1000);*/
		
		if ((za1 == 1) && (xa1 == 0) && (ya1 == 0))
		{
			wifiout = wifiout;							//while flat, keep last mode			
		}
		else if (ya1 == 0)
		{
			wifiout = 0;								//application: to see if phone is in landscape mode, vertical
		}
		else if (xa1 == 0)
		{
			wifiout = 100;								//application, to see if phone is in portrait mode, horizontal
		}
		
		
		//Send to WIFI MODULE
		//every 25 secs
		//send code
		
	//za1 = 101;
	_delay_ms(100);
		snprintf(ATs,sizeof(ATs), "AT+CIPSTART=0,\"TCP\",\"api.thingspeak.com\",80\r");
		USART_tx_string(ATs);
		_delay_ms(2000);
		snprintf(ATs,sizeof(ATs), "AT+CIPSEND=0,125\r");
		USART_tx_string(ATs);
		_delay_ms(1000);
		snprintf(ATs,sizeof(ATs), "GET https://api.thingspeak.com/update?api_key=KX3UE6FR4YHJOFL1&field1=%i HTTP/1.0\n\r", wifiout);
		USART_tx_string(ATs);
		snprintf(ATs,sizeof(ATs), "\n\r");
		while (i < 22)
		{
			i++;			//needed to push data through.
		USART_tx_string(ATs);
		_delay_ms(1000);
		}
		i=0;
		_delay_ms(100);
	} 
	
	return 0;
}