int poweron_self_check() { int ret = -1; int timeout = 0; ret=spi_open(); #ifndef debug if(ret<0) fault_status_return(ret); #endif /* ret=adc_init(); #ifndef debug if(ret<0) fault_status_return(ret); #endif */ ret = sensor_open(); #ifndef debug if (ret < 0) { fault_status_return(ret); } #endif set_flying_status(AIRCRAFT_PREPARING); // wait for flying attitude sensor data while (timeout <= 600) { sleep(1); if(flying_attitude_sensor_is_active()) break; timeout++; } if (timeout >600) { print_err("flying attitude sensor is inactive, please check serial port is connected\n"); goto exit; } print_debug("Flying attitude sensor is active\n"); while (1) { flying_status_return(); usleep(500000); //500ms if (get_system_status() >= SYS_PREPARE_SETTING) { print_debug("Link is ready\n"); return 0; } //link_testing_send(); //usleep(20000); //20ms } exit: sensor_close(); return ret; }
int poweron_self_check() { int ret = -1; int timeout = 0; char set_system_time[50]; flying_attitude_s *p; //--------------spi initial------------------ ret=spi_open(); printf("CPLD logic version:%d\n",get_fpga_version()); printf("----------------------------------------------------------------\n"); #ifndef debug if(ret<0) fault_status_return(ret); #endif /* ret=adc_init(); #ifndef debug if(ret<0) fault_status_return(ret); #endif */ //---------------imu initial----------------- ret = sensor_open(); #ifndef debug if (ret < 0) { fault_status_return(ret); } #endif pressure_sensor_init(); set_flying_status(AIRCRAFT_PREPARING); if(command==0){ //UAV is working in normal mode // reset CPLD ,this should be check later ,if CPLD should be reset when CPU recovers from failure. reset_control_register(CTRL_REG_MASK_MANUAL); // wait for flying attitude sensor data while (timeout <= 600) { sleep(1); if(flying_attitude_sensor_is_active()) break; timeout++; } if (timeout >600) { print_err("flying attitude sensor is inactive, please check serial port is connected\n"); goto exit; } print_debug("Flying attitude sensor is active\n"); p=get_flying_attitude(); //printf("system beijing time %d-%d-%d,%d:%d:%d\n",p->year,p->month,p->day,p->hour+8,p->min,p->sec); sprintf(set_system_time,"date -s \"%d-%d-%d %d:%d:%d\"",p->year+2000,p->month,p->day,p->hour+8,p->min,p->sec); //printf("%s\n",set_system_time); system(set_system_time); }else if(command==1){ //UAV is working in test mode reset_control_register(CTRL_REG_MASK_MANUAL); printf("uav is working in test mode,IMU is by passed,using test data instead\n"); }else if(command==2){ //UAV is in mannual mode ,for pwm data capture set_flying_status(AIRCRAFT_MANUAL_MODE); set_control_register(CTRL_REG_MASK_MANUAL); set_system_status(SYS_PREPARE_SETTING); printf("UAV is now working in data capturing mode\n"); }else{ printf(" error command,please check the usage:\n"); printf(" usage: uav [command] [gap] ]\n"); printf(" [command]: 0--normal mode,used when run in the air\n"); printf(" [command]: 1--test mode,used for platform test.use this mode \n"); printf(" when no IMU connected ,\n"); printf(" [command]: 2--manual mode,used when capturing PWM data\n"); printf(" [frequency]: the frequency (ms/frame) in which UAV send fly status data\n"); } generate_file_name(log_file_name); if((fp_fly_status=fopen(log_file_name,"wb+"))==NULL){ printf("can not open file:%s\n",log_file_name); } heli_configuration_init(); control_parameter_init(); servo_test_enable=0; while (1) { if(get_system_status() < SYS_PREPARE_STEERING_TEST){ flying_status_return(1); usleep(500000); }else if(get_system_status() == SYS_PREPARE_STEERING_TEST){ steering_test(); usleep(20000); }else if(get_system_status() == SYS_PREPARE_TAKEOFF){ return 0; } /* if (get_system_status() >= SYS_PREPARE_SETTING) { print_debug("Link is ready\n"); return 0; } link_testing_send(); usleep(20000); //20ms */ } exit: sensor_close(); return ret; }