Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:34a8e94c6fd5, committed 2020-10-27
- Comitter:
- eric11fr
- Date:
- Tue Oct 27 22:22:14 2020 +0000
- Parent:
- 3:cb420000788e
- Commit message:
- test menu via xbee
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r cb420000788e -r 34a8e94c6fd5 main.cpp --- a/main.cpp Sat Oct 24 14:15:22 2020 +0000 +++ b/main.cpp Tue Oct 27 22:22:14 2020 +0000 @@ -40,12 +40,12 @@ AnalogIn sp_2in(PA_5);//Solar Panel Current 2 pin PA5 uint8_t g_image_buffer[IMAGE_JPG_SIZE]; -void telegram_bot(); +void get_image(void); + void init_serial(void) { pc.baud(9600); xbee.baud(38400); - // came.baud(38400); } void Init_Inisat(void) @@ -57,13 +57,16 @@ void test_imu(void) { unsigned char stop; - //cam_spi_cs=0; - // sdcard_spi_cs=0; - //test mpu9250-IMU + //test mpu9250-IMU pc.printf("\r\n/*----------------------------------------------*/\r\n"); pc.printf("\t IMU9250 test\r\n"); pc.printf("send \"s\" to stop\r\n"); pc.printf("/*----------------------------------------------*/\r\n"); + /*--------------------------------------------------------------*/ + xbee.printf("\r\n/*----------------------------------------------*/\r\n"); + xbee.printf("\t IMU9250 test\r\n"); + xbee.printf("send \"s\" to stop\r\n"); + xbee.printf("/*----------------------------------------------*/\r\n"); activ_sensors = 1; // 3.3V power sensors board On wait(2); @@ -72,11 +75,16 @@ t.start(); // Read the WHO_AM_I register, this is a good test of communication uint8_t whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); // Read WHO_AM_I register for MPU-9250 - pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x71\n\r"); + pc.printf("I AM 0x%x\n\r", whoami); + pc.printf("I SHOULD BE 0x71\n\r"); + xbee.printf("I AM 0x%x\n\r", whoami); + xbee.printf("I SHOULD BE 0x71\n\r"); if (whoami == 0x71) // WHO_AM_I should always be 0x68 { pc.printf("MPU9250 WHO_AM_I is 0x%x\n\r", whoami); pc.printf("MPU9250 is online...\n\r"); + xbee.printf("MPU9250 WHO_AM_I is 0x%x\n\r", whoami); + xbee.printf("MPU9250 is online...\n\r"); sprintf(buffer, "0x%x", whoami); wait(1); mpu9250.resetMPU9250(); // Reset registers to default in preparation for device calibration @@ -84,29 +92,32 @@ mpu9250.calibrateMPU9250(gyroBias, accelBias); // Calibrate gyro and accelerometers, load biases in bias registers wait(2); mpu9250.initMPU9250(); - pc.printf("MPU9250 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature + // pc.printf("MPU9250 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature mpu9250.initAK8963(magCalibration); - pc.printf("AK8963 initialized for active data mode....\n\r"); // Initialize device for active mode read of magnetometer - pc.printf("Accelerometer full-scale range = %f g\n\r", 2.0f*(float)(1<<Ascale)); - pc.printf("Gyroscope full-scale range = %f deg/s\n\r", 250.0f*(float)(1<<Gscale)); - if(Mscale == 0) pc.printf("Magnetometer resolution = 14 bits\n\r"); - if(Mscale == 1) pc.printf("Magnetometer resolution = 16 bits\n\r"); - if(Mmode == 2) pc.printf("Magnetometer ODR = 8 Hz\n\r"); - if(Mmode == 6) pc.printf("Magnetometer ODR = 100 Hz\n\r"); + // pc.printf("AK8963 initialized for active data mode....\n\r"); // Initialize device for active mode read of magnetometer + // pc.printf("Accelerometer full-scale range = %f g\n\r", 2.0f*(float)(1<<Ascale)); + // pc.printf("Gyroscope full-scale range = %f deg/s\n\r", 250.0f*(float)(1<<Gscale)); + // if(Mscale == 0) pc.printf("Magnetometer resolution = 14 bits\n\r"); + // if(Mscale == 1) pc.printf("Magnetometer resolution = 16 bits\n\r"); + // if(Mmode == 2) pc.printf("Magnetometer ODR = 8 Hz\n\r"); + // if(Mmode == 6) pc.printf("Magnetometer ODR = 100 Hz\n\r"); wait(1); } else { pc.printf("Could not connect to MPU9250: \n\r"); pc.printf("%#x \n", whoami); + xbee.printf("Could not connect to MPU9250: \n\r"); + xbee.printf("%#x \n", whoami); sprintf(buffer, "WHO_AM_I 0x%x", whoami); + exit(0); } mpu9250.getAres(); // Get accelerometer sensitivity mpu9250.getGres(); // Get gyro sensitivity mpu9250.getMres(); // Get magnetometer sensitivity - pc.printf("Accelerometer sensitivity is %f LSB/g \n\r", 1.0f/aRes); - pc.printf("Gyroscope sensitivity is %f LSB/deg/s \n\r", 1.0f/gRes); - pc.printf("Magnetometer sensitivity is %f LSB/G \n\r", 1.0f/mRes); + // pc.printf("Accelerometer sensitivity is %f LSB/g \n\r", 1.0f/aRes); + // pc.printf("Gyroscope sensitivity is %f LSB/deg/s \n\r", 1.0f/gRes); + // pc.printf("Magnetometer sensitivity is %f LSB/G \n\r", 1.0f/mRes); magbias[0] = +470.; // User environmental x-axis correction in milliGauss, should be automatically calculated magbias[1] = +120.; // User environmental x-axis correction in milliGauss magbias[2] = +125.; // User environmental x-axis correction in milliGauss @@ -142,7 +153,7 @@ mpu9250.MahonyQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz); // Serial print and/or display at 0.5 s rate independent of data rates delt_t = t.read_ms() - countA; - if (delt_t > 500) + if (delt_t > 1000) { // update LCD once per half-second independent of read rate pc.printf("ax = %f", 1000*ax); pc.printf(" ay = %f", 1000*ay); @@ -153,10 +164,22 @@ pc.printf("gx = %f", mx); pc.printf(" gy = %f", my); pc.printf(" gz = %f mG\n\r", mz); + /*---------------------------------------------------*/ + xbee.printf("ax = %f", 1000*ax); + xbee.printf(" ay = %f", 1000*ay); + xbee.printf(" az = %f mg\n\r", 1000*az); + xbee.printf("gx = %f", gx); + xbee.printf(" gy = %f", gy); + xbee.printf(" gz = %f deg/s\n\r", gz); + xbee.printf("gx = %f", mx); + xbee.printf(" gy = %f", my); + xbee.printf(" gz = %f mG\n\r", mz); tempCount = mpu9250.readTempData(); // Read the adc values temperature = ((float) tempCount) / 333.87f + 21.0f; // Temperature in degrees Centigrade pc.printf(" temperature = %f C\n\r", temperature); pc.printf("average rate = %f\n\r", (float) sumCount/sum); + xbee.printf(" temperature = %f C\n\r", temperature); + xbee.printf("average rate = %f\n\r", (float) sumCount/sum); countA = t.read_ms(); if(countA > 1<<21) { @@ -170,15 +193,14 @@ } if(pc.readable()) stop=pc.getc(); - } while(stop!='s'); + if(xbee.readable()) + stop=xbee.getc(); + } while(stop!='s'&& (stop != 'S')); //activ_sensors = 0; // 3.3V power sensors board Off } -void telegram_bot() -{ - - - +void get_image(void) +{ /* main loop */ // while (1) {sdcard_spi_cs=1;//deactivate sdcard cs @@ -194,11 +216,15 @@ image_size = g_arducam.CaptureImage(g_image_buffer,IMAGE_JPG_SIZE,&idx); if( image_size == 0 ) { - printf("Photo failure %d\r\n",image_size); + pc.printf("Photo failure %d\r\n",image_size); + xbee.printf("Photo failure %d\r\n",image_size); break; } else - pc.printf("taille image%d",image_size); + { + pc.printf("taille image%d",image_size); + xbee.printf("taille image%d",image_size); + } } sdcard_spi_cs=0;//activate sdcard cs, deactivate cam cam_spi_cs=1; @@ -218,23 +244,22 @@ { sdcard_spi_cs=1;//deactivate sdcard cs cam_spi_cs=0; - // pc.baud(9600); if( g_arducam.Setup( OV_RESOLUTION_CIF/*OV_RESOLUTION_QQVGA*/,92, &cam_spi_cs, &camSPI, &camI2C) == false) { pc.printf("Arducam setup error \r\n"); + xbee.printf("Arducam setup error \r\n"); exit(0); } else pc.printf("init_ok"); - /* start chatbot */ - telegram_bot(); + xbee.printf("init_ok"); + get_image(); } void test_gps(void) {unsigned char tmp; unsigned char stop=0; - // ser.baud(9600); //GPS selection activ_sensors = 1; // 3.3V power sensors board On @@ -243,6 +268,11 @@ pc.printf("\tGPS module test\r\n"); pc.printf("send \"s\" to stop\r\n"); pc.printf("/*----------------------------------------------*/\r\n"); + /*----------------------------------------------------------------*/ + xbee.printf("\r\n/*----------------------------------------------*/\r\n"); + xbee.printf("\tGPS module test\r\n"); + xbee.printf("send \"s\" to stop\r\n"); + xbee.printf("/*----------------------------------------------*/\r\n"); wait(2); do { @@ -250,10 +280,13 @@ { tmp= _getchar(); pc.printf("%c",tmp); + xbee.printf("%c",tmp); }while(tmp!='\r'); if(pc.readable()) stop=pc.getc(); - } while(stop!='s'); + if(xbee.readable()) + stop=xbee.getc(); + } while(stop!='s'&& (stop != 'S')); } void test_sdcard(void) @@ -265,6 +298,11 @@ pc.printf("\t SDCard module test\r\n"); pc.printf("/*----------------------------------------------------*/\r\n"); pc.printf("Write some words in sdtest.txt on sd/mydir directory\r\n"); + /*----------------------------------------------------------------*/ + xbee.printf("\r\n/*----------------------------------------------------*/\r\n"); + xbee.printf("\t SDCard module test\r\n"); + xbee.printf("/*----------------------------------------------------*/\r\n"); + xbee.printf("Write some words in sdtest.txt on sd/mydir directory\r\n"); mkdir("/sd/mydir", 0777); FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { @@ -280,25 +318,25 @@ fgets(buf,50,fp1); wait(2); pc.printf("read from sd/mydir directory : %s\r\n",buf); + xbee.printf("read from sd/mydir directory : %s\r\n",buf); fclose(fp1); } -void test_xbee_comm() -{ - char buf[250]; - pc.printf("\r\n/*----------------------------------------------*/\r\n"); - pc.printf("\t xbee module test\r\n"); - pc.printf("/*----------------------------------------------*/\r\n"); - - xbee.printf("Hello from inisat\r\nTest receiving data from Ground Station : type a sentence and press enter to loopback\r\n"); - while(pc.getc()!='s') - { - xbee.printf("%s\r\n",pc.gets(buf,250)); // Echo +//void test_xbee_comm() +//{ +// char buf[250]; +// pc.printf("\r\n/*----------------------------------------------*/\r\n"); +// pc.printf("\t xbee module test\r\n"); +// pc.printf("/*----------------------------------------------*/\r\n"); +// xbee.printf("Hello from inisat\r\nTest receiving data from Ground Station : type a sentence and press enter to loopback\r\n"); +// while(pc.getc()!='s') +// { +// xbee.printf("%s\r\n",pc.gets(buf,250)); // Echo - } - while(xbee.getc()!='s') - pc.printf("%c\r\n",xbee.getc()); -} +// } +// while(xbee.getc()!='s') +// pc.printf("%c\r\n",xbee.getc()); +//} void test_analog_sensor(void) { @@ -309,6 +347,12 @@ pc.printf("\t Solar Panel 1 and 2 Currents test\r\n"); pc.printf("send \"s\" to stop\r\n"); pc.printf("/*----------------------------------------------*/\r\n"); + /*-------------------------------------------------------------------*/ + xbee.printf("\r\n/*----------------------------------------------*/\r\n"); + xbee.printf("\t Battery level, temperature sensor test\r\n"); + xbee.printf("\t Solar Panel 1 and 2 Currents test\r\n"); + xbee.printf("send \"s\" to stop\r\n"); + xbee.printf("/*----------------------------------------------*/\r\n"); wait(2); do { @@ -317,91 +361,118 @@ pc.printf("temperature: %.1f degC\r\n",(tempin.read()*3.3f-0.5f)/0.01f); pc.printf("solar panel 1: %.1f mA\t",(sp_1in.read()*3.3f*50)); pc.printf("and 2: %.1f mA\r\n",(sp_2in.read()*3.3f*50)); + /*--------------------------------------------------------------*/ + xbee.printf("battery: %.2f V\t\t",batin.read()*4.59f); // 3.3 * 13.9/10 + xbee.printf("temperature: %.1f degC\r\n",(tempin.read()*3.3f-0.5f)/0.01f); + xbee.printf("solar panel 1: %.1f mA\t",(sp_1in.read()*3.3f*50)); + xbee.printf("and 2: %.1f mA\r\n",(sp_2in.read()*3.3f*50)); if(pc.readable()) stop=pc.getc(); - }while(stop!='s'); + if(xbee.readable()) + stop=xbee.getc(); + }while(stop!='s'&& (stop != 'S')); } -void quit(void) +/*void quit(void) { //do nothing pc.printf("\r\nbye bye..."); exit(0); -} +}*/ void test_pan_tilt(void) -{unsigned char stop=0; +{ + unsigned char stop=0; pc.printf("\r\n/*----------------------------------------------*/\r\n"); - pc.printf("\t Pan Tilt test\r\n"); + pc.printf("\t Pan Tilt stage test\r\n"); pc.printf("send \"s\" to stop\r\n"); pc.printf("/*----------------------------------------------*/\r\n"); - wait(2); + xbee.printf("\r\n/*----------------------------------------------*/\r\n"); + xbee.printf("\t Pan Tilt stage test\r\n"); + xbee.printf("send \"s\" to stop\r\n"); + xbee.printf("/*----------------------------------------------*/\r\n"); + wait(1); do { for(float p=0.2; p<0.7; p += 0.1) { servo_pan = p; - servo_tilt=p; + servo_tilt= p; wait(0.4); } for(float p=0.7; p>0.2; p -= 0.1) { servo_pan = p; - servo_tilt=p; + servo_tilt= p; wait(0.4); } if(pc.readable()) stop=pc.getc(); - }while(stop!='s'); - servo_pan = 0.5; + if(xbee.readable()) + stop=xbee.getc(); + }while(stop!='s'&& (stop != 'S')); + servo_pan = 0.5; servo_tilt=0.5; } int menu(void) {int choice=0; // menu tests - //pc.putc(27);//to clear terminal screen - //pc.printf("[2J"); pc.printf("\r\n/*-------------------------------------------*/\r\n"); pc.printf("\t1. Test IMU\r\n"); pc.printf("\t2. Test SDCARD\r\n"); pc.printf("\t3. Test GPS\r\n"); pc.printf("\t4. Test CAMERA\r\n"); pc.printf("\t5. Test Analog Sensors\r\n"); - pc.printf("\t6. Test XBEE communication\r\n"); - pc.printf("\t7. Test pan/tilt plates \r\n"); - pc.printf("\t8. Quit\r\n"); + pc.printf("\t6. Test pan/tilt plates \r\n"); pc.printf("/*-------------------------------------------*/\r\n"); + /*---------------------------------------------------------------------*/ + xbee.printf("\r\n/*-------------------------------------------*/\r\n"); + xbee.printf("\t1. Test IMU\r\n"); + xbee.printf("\t2. Test SDCARD\r\n"); + xbee.printf("\t3. Test GPS\r\n"); + xbee.printf("\t4. Test CAMERA\r\n"); + xbee.printf("\t5. Test Analog Sensors\r\n"); + xbee.printf("\t6. Test pan/tilt plates \r\n"); + xbee.printf("/*-------------------------------------------*/\r\n"); do { - pc.printf("Please enter your choice (1 to 8):"); - choice=pc.getc(); - }while(choice<0x31||choice>0x38); + pc.printf("Please enter your choice (1 to 6):"); + xbee.printf("Please enter your choice (1 to 6):"); + if (pc.readable()) + choice=pc.getc(); + if (xbee.readable()) + choice=xbee.getc(); + }while(choice<0x31||choice>0x36); return choice; } int main() { -float batest; -unsigned char start; - + float batest; + unsigned char start; int status=0; + // NVIC_SystemReset(); //initialise serial communication init_serial(); //initialise inisat port Init_Inisat(); batest=batin.read()*4.59f; pc.printf("battery: %.2f V\r\n",batest); - - /* if (batest < 3.3f) + xbee.printf("battery: %.2f V \r\n",batest); + if (batest < 3.3f) { pc.printf("low battery, please recharge\r\n"); + xbee.printf("low battery, please recharge \r\n"); exit(0); - }*/ + } pc.printf("Press \"S\" to Start\r\n"); + xbee.printf("Press \"S\" or \"s\" to Start\r\n"); do { if(pc.readable()) start=pc.getc(); + if(xbee.readable()) + start=xbee.getc(); }while((start!='S') && (start != 's')); while(1) @@ -425,16 +496,13 @@ case '5' : test_analog_sensor(); status=0; break; - case '6' : test_xbee_comm(); + // case '6' : test_xbee_comm(); + // status=0; + // break; + case '6' : test_pan_tilt(); status=0; break; - case '7' : test_pan_tilt(); - status=0; - break; - //case 7: all_test(); - // break; - case '8' : quit(); - break; + default : break; } } } \ No newline at end of file