《北京航空航天大学-附录A-主程序-包含模糊算法》由会员分享,可在线阅读,更多相关《北京航空航天大学-附录A-主程序-包含模糊算法(19页珍藏版)》请在金锄头文库上搜索。
1、/ =/ File : MainTask.c/ =/*Purpose: * * Version: 1.0.0*/* Including used modules for compilling procedure */#include #include #include #include “Cpu.h“/* Include shared modules, which are used for whole project */#include “PE_Types.h“#include “PE_Error.h“#include “PE_Const.h“#include “IO_Map.h“#incl
2、ude “hidef.h“ #include “DataType.h“#include “state_comm.h“#include “init.h“#include “command.h“ #include “globals_fun.h“#include “sci.h“#include “eeprom.h“#include “IIC.h“#include “Timer.h“#include “PWM.h“#include “spi.h“#include “nRF2401.h“#include “target.h“#include “various.h“#include “lcd.h“#inc
3、lude “keyboard.h“#include “lcd.h“#include “lcdlogo.h“#define MAIN_TASK_GLOBALS#include “MainTask.h“#include “InterfaceTask.h“#include “timer.h“#include “Argument.h“#include “video.h“#include “ad.h“#include “menu.h“#include “ccd.h“#include “MainControl.h“#include “ConfigArgument.h“void main(void ) un
4、signed char ucKey,ucMode;PE_low_level_init();PLL_Init();GlobalsInit();EEPROM_Init();Argument_Init();SCI0_Communication_Init();TimerModule_Init();Timer0_Init(1);PWM23_45_67_Init(); Motor_Init();Various_Init();nRF2401_Init();KeyboardInit(); /LCDInitCHN();ucKey = test1;Video_Init(); CCD_Init();AD1_Init
5、();EnableInterrupts; Delay_MS(100);g_ucRunMode = CheckRunMode();Delay_MS(100); InterfaceInit();INTERFACE_STANDBY; for(;)#if(COMMAND_HANDLE_IN_INTERRUPT = 0)Command_Handle();#endifStatusMonitor();MainControl();/发车/ =/File : MainControl.c/ =/*Purpose:* Version: 1.0.0*/#include #include #include “DataT
6、ype.h“#include “video.h“#include “ccd.h“#define MAIN_CTRL_GLOBALS#include “MainControl.h“#include “CalInformation.h“#include “SpecialHandle.h“#include “pid.h“#include “various.h“#include “ccd.h“#include “Argument.h“#include “pwm.h“#include “Cpu.h“#include “IO_Map.h“#include “init.h“#include “timer.h
7、“#include “target.h“#include “ResultHandle.h“#include “Keyboard.h“#include “globals_fun.h“#include “MainTask.h“#include “state_comm.h“#include “command.h“#include “lcd.h“#include “BCB_Simulator.h“#include “target.h“#include “Uart_Command.h“#include “nRF2401.h“#include “ad.h“#include “various.h“#incl
8、ude “pid2.h“extern int abs (int i); #if(BCB_DEBUG = 1)extern int DoEvent(void);extern int WaitMS(int nTime);extern void DrawVideoLine(void);#endif#if(BCB_DEBUG = 0)void DebugMode_Init(void)TIMER0_STOP;MOTOR_SPEED_AD_CONVERSION; /启动 AD 采集小车速度MAINCTRL_CLEARSCREEN;g_ucSampleFlag = SAMPLE_FLAG_CAR;/启动图像
9、采集g_uiControlCount = 0;g_ucSpecialHandleFlag = FALSE;PID_Init();void DebugMode(void)unsigned char ucMask = 0xff;MAINCTRL_CLEARSCREEN;LCDOutTextCHN(LINE2, “ 调试模式“);NRF2401_INTERRUPT_DISABLE;g_ucSampleFlag = SAMPLE_FLAG_CAR;/启动图像采集DebugMode_Init();while(g_uc_CCD_FrameFlag = FALSE); /等待新的一帧开始g_uc_CCD_F
10、rameFlag = FALSE;for(;)StatusMonitor();while(g_uc_CCD_FrameFlag = FALSE) /*Command_Handle()*/;g_uc_CCD_FrameFlag = FALSE;memcpy(g_ucVideoSendBuffer, g_ucCCD_LinePixel, g_ucCCD_SampleLines);NRF2401_ISR();Command_Handle();ucMask = 0xff;if(ucMask) LED1_ON;else LED1_OFF;#endif void MainControl_Init(void
11、)TIMER0_STOP;MOTOR_SPEED_AD_CONVERSION; /启动 AD 采集小车速度MAINCTRL_CLEARSCREEN;g_ucSampleFlag = SAMPLE_FLAG_CAR;/启动图像采集g_uiControlCount = 0;g_ucSpecialHandleFlag = FALSE;PID_Init();#if(BCB_DEBUG = 0)if(g_ucDebugOutput = 0)MOTOR_DUTY_LIMIT_ENABLE;Set_SM_Duty(g_u16StartSpeed);/设置电机转速if(g_ucMotorRunMode = 0
12、)/设置电机的驱动模式SetMotorRunMode(MOTOR_RUN_MODE_BIPOLAR);elseSetMotorRunMode(MOTOR_RUN_MODE_BREAK_FRONT);Set_DM_Duty(g_u16_DM_CenterDuty);/舵机设为 0 角度g_sc_Angle = g_u16_DM_CenterDuty;g_ucCarSpeed = 0;Delay_MS(100);MOTOR_DUTY_LIMIT_DISABLE;#endif #if(BCB_DEBUG = 0)BOOLEAN MainControlWaitCCD(void)while(g_uc_C
13、CD_FrameFlag = FALSE)/等待一帧采集完成CalInformation();/在采集时间间隙中计算赛道信息g_uc_CCD_FrameFlag = FALSE;return TRUE;#elseBOOLEAN MainControlWaitCCD(void)unsigned char ucBufferCCD_SAMPLE_MAX_LINES;U16 SpeedDuty, AngleDuty;SpeedDuty = (U16)(long)g_ucCarSpeed * (g_u16_SM_MaxSpeed - g_u16_SM_MinSpeed) / 100 + g_u16_SM
14、_MinSpeed);AngleDuty = AngleToDuty(g_sc_Angle);SpeedDuty += g_u16_SM_DeathDuty;Debug_Printf(“CarSpeed = %-5d Angle = %-5d Angle Duty = %-5d, Speed Duty = %-5d“,g_ucCarSpeed, g_sc_Angle, AngleDuty, SpeedDuty);if(SendCarControlInformationDuty(AngleDuty, SpeedDuty, 0, 0, MOTOR_RUN_MODE_BIPOLAR,ucBuffer, return FALSE;memcpy(g_ucCCD_LinePixel, ucBuffer, g_ucCCD_SampleLines);memset(g_ucCCD_LineStatus, LINE_STATUS_OK, g_ucCCD_SampleLines);DrawVideoLine();CalInformation();/计算赛道信息 DoEvent();return TRUE;#endif/*-主模糊控制算法-