/***************************************************************
** 作   者: Songyimiao
** 官    网:http://www.miaowlabs.com
** 淘    宝:http://miaowlabs.taobao.com
** 日   期: 2015年11月29日
** 函数名称: main()
** 功能描述: 主函数            
** 输   入:   
** 输   出:   
** 备    注: 
********************喵呜实验室版权所有**************************
***************************************************************/
void main()
{
	DisableInterrupts;//禁止总中断

	DriversInit();	  //MCU底层驱动初始化
	MPU6050Init();	  //MPU6050配置初始化
	CarStandInit();	  //应用程序变量初始化
	UltraInit();	  //超声波配置初始化
	Delaynms(50);	  //延时50ms 
	ON_LED0;		  //指示灯亮起,表示初始化完毕
	
	EnableInterrupts; //使能总中断	 

	while(1)
	{ 
		STC_ISP();
		Delaynms(50);	        //延时50ms 
		if(g_ucUart2Flag>=1)
		{
			BluetoothControl();	//蓝牙遥控函数
			g_ucUart2Flag = 0;
		}
		BatteryChecker();		//电池电量检测(电量不足时,亮红灯)
		if(EchoFlag)			//判断是否测距完成
		{ 
			g_ucUltraDis=UltraDis();//读取超声波测距结果
		}

#if DEBUG_UART  //调试启用 预编译命令 
//若要观察波形进行调试,需将DEBUG_UART设置成1,该版本不需要注释蓝牙控制函数
	
   		OutData[0] = g_fCarAngle;
   		OutData[1] = g_fGyroAngleSpeed;
   		OutData[2] = g_fLeftMotorOut ;
   		OutData[3] = g_fAngleControlOut;
   		OutPut_Data();		
		 	  
#endif	 		
					
	}
}
Esempio n. 2
0
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+.
     * 
     */
    usbDisconnectBus(serusbcfg.usbp);
    chThdSleepMilliseconds(500);
    usbStart(serusbcfg.usbp, &usbcfg);
    usbConnectBus(serusbcfg.usbp);

    /*
     *
     * Start I2C and set up sensors
     * 
     */
    i2cStart(&I2CD2, &i2cfg2);

    /* Initialize Accelerometer and Gyroscope */
    if (MPU6050Init(&mpu6050cfg) != MSG_OK)
        panic("MPU6050 init failed"); /* Initialization failed */

    /* Initialize Magnetometer */
    if (HMC5983Init(&hmc5983cfg) != MSG_OK)
        panic("HMC5983 init failed"); /* Initialization failed */

    /* Initialize Barometer */
    /* TODO: Add barometer code */

    /* Initialize sensor readout */
    if (SensorReadInit(&mpu6050cfg, &hmc5983cfg,
                       &mpu6050cal, &hmc5983cal) != MSG_OK)
        panic("Sensor Read init failed"); /* Initialization failed */

    /*
     *
     * Start the external interrupts
     *
     */
    extStart(&EXTD1, &extcfg);

    /*
     *
     * Initialize the RC Outputs
     *
     */
    if (RCOutputInit(&rcoutputcfg) != MSG_OK)
        panic("RC output init failed"); /* Initialization failed */

    /*
     *
     * Start RC Inputs
     *
     */
    eicuInit();
    eicuStart(&EICUD9, &rcinputcfg);
    eicuEnable(&EICUD9);

    /*
     *
     * Start test thread
     * 
     */
    chThdCreateStatic(  waThreadTestEvents,
                        sizeof(waThreadTestEvents),
                        HIGHPRIO,
                        ThreadTestEvents,
                        NULL);

    while(1)
    {
        chThdSleepMilliseconds(100);
        if (isUSBActive() == true)
            chprintf((BaseSequentialStream *)&SDU1, "Input width: %u\r\n", ic_test);
    }
}
Esempio n. 3
0
void MPU6050_Init(void){
		ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
		ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
		ROM_SysCtlDelay(3);
		ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
	
		ROM_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
		ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
	
		//ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_0);
    //GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_0);
    //ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE);
    //ROM_IntEnable(INT_GPIOB);
		ROM_I2CMasterEnable(I2C0_BASE);
		I2CMInit(&sI2CInst, I2C0_BASE, INT_I2C0, 0xff, 0xff, ROM_SysCtlClockGet());
		
		g_bMPU6050Done = false;
		MPU6050Init(&sMPU6050, &sI2CInst, 0x68, MPU6050_Callback, 0);
		while(!g_bMPU6050Done);
		
		g_bMPU6050Done = false;
		MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_PWR_MGMT_1,
		~MPU6050_PWR_MGMT_1_SLEEP,
		0, MPU6050_Callback,
		0);//从Sleep模式中激活设备,否则无法写入寄存器
		while(!g_bMPU6050Done);
		
		// Configure the MPU6050 for +/- 4 g accelerometer range.
		//
		g_bMPU6050Done = false;
		//先读取寄存器的值,再与上Mask,然后再或上Value,将得到的值写入寄存器
		MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_PWR_MGMT_1,
		~MPU6050_PWR_MGMT_1_CLKSEL_M,
		MPU6050_PWR_MGMT_1_CLKSEL_XG, MPU6050_Callback,
		0);
		while(!g_bMPU6050Done);
		
		g_bMPU6050Done = false;
		MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_ACCEL_CONFIG,
		~MPU6050_ACCEL_CONFIG_AFS_SEL_M,
		MPU6050_ACCEL_CONFIG_AFS_SEL_4G, MPU6050_Callback,
		0);
		while(!g_bMPU6050Done);
		
		g_bMPU6050Done = false;
		MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_CONFIG,
		~MPU6050_CONFIG_DLPF_CFG_M,
		MPU6050_CONFIG_DLPF_CFG_44_42, MPU6050_Callback,
		0);
		while(!g_bMPU6050Done);
		
		g_bMPU6050Done = false;
		MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_GYRO_CONFIG,
		~MPU6050_GYRO_CONFIG_FS_SEL_M,
		MPU6050_GYRO_CONFIG_FS_SEL_2000, MPU6050_Callback,
		0);
		while(!g_bMPU6050Done);
		
		MPU6050Read(&sMPU6050,MPU6050_O_WHO_AM_I,&deviceID,1,MPU6050_Callback,0);//MPU-60X0设备号默认0x68
		ROM_SysCtlDelay(ROM_SysCtlClockGet()/(3*1000));
		MPU6050Read(&sMPU6050,MPU6050_O_PWR_MGMT_1,&PowerInfo,1,MPU6050_Callback,0);//若读到的值是0x00,则设备处于激活状态。0x40则为休眠状态

}