v1

Dependencies:   mbed Servo

Committer:
eric11fr
Date:
Thu Sep 03 21:45:56 2020 +0000
Revision:
0:b8bade04f24f
Child:
1:d8964d9ff503
Child:
2:065d789dbcbd
V1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eric11fr 0:b8bade04f24f 1 #include "mbed.h"
eric11fr 0:b8bade04f24f 2 #include "mpu9250.h"
eric11fr 0:b8bade04f24f 3 #include "SDFileSystem.h"
eric11fr 0:b8bade04f24f 4 #include "soft_uart.h"
eric11fr 0:b8bade04f24f 5 #include <string.h>
eric11fr 0:b8bade04f24f 6 #include "ArduCAM2640.h"
eric11fr 0:b8bade04f24f 7 #define IMAGE_JPG_SIZE 16*1024
eric11fr 0:b8bade04f24f 8 #define MIN(x,y) x < y ? x : y
eric11fr 0:b8bade04f24f 9 float sum = 0;
eric11fr 0:b8bade04f24f 10 uint32_t sumCount = 0;
eric11fr 0:b8bade04f24f 11 char buffer[14];
eric11fr 0:b8bade04f24f 12 char buf[100];
eric11fr 0:b8bade04f24f 13 unsigned int framepos=0;
eric11fr 0:b8bade04f24f 14 ArduCAM2640 g_arducam;
eric11fr 0:b8bade04f24f 15 I2C camI2C(PB_7, PB_6);
eric11fr 0:b8bade04f24f 16 //I2C camI2C(PB_7,PB_6); //SDA/SCL
eric11fr 0:b8bade04f24f 17 SPI camSPI(PB_5,PB_4,PB_3);//MOSI/MISO/SCL
eric11fr 0:b8bade04f24f 18 DigitalOut cam_spi_cs(PA_8);// cs _camera PA_8
eric11fr 0:b8bade04f24f 19 DigitalOut sdcard_spi_cs(PA_11);// cs _sdcard PA_11
eric11fr 0:b8bade04f24f 20 MPU9250 mpu9250;
eric11fr 0:b8bade04f24f 21 Timer t;
eric11fr 0:b8bade04f24f 22 // serial port for USB, camera, GPS and XBEE
eric11fr 0:b8bade04f24f 23 Serial pc(USBTX, USBRX); // usb serial tx, rx
eric11fr 0:b8bade04f24f 24
eric11fr 0:b8bade04f24f 25 //Serial ser(pa3, pa4);//GPS softserial TX, RX
eric11fr 0:b8bade04f24f 26 Serial xbee(PA_9, PA_10); //xbee serial pin TX,RX
eric11fr 0:b8bade04f24f 27 //sdcard
eric11fr 0:b8bade04f24f 28 SDFileSystem sd(PB_5, PB_4, PB_3, PA_11, "sd"); //MOSI,MISO,SCK,CS the pinout on the mbed Cool Components workshop board
eric11fr 0:b8bade04f24f 29
eric11fr 0:b8bade04f24f 30 // activation 3.3V power supply on sensors board
eric11fr 0:b8bade04f24f 31 DigitalOut activ_sensors(PA_7); //
eric11fr 0:b8bade04f24f 32 // Analog pin sensors : battery and temperature
eric11fr 0:b8bade04f24f 33 AnalogIn batin(PA_0);//battery pin pA0
eric11fr 0:b8bade04f24f 34 AnalogIn tempin(PA_1);//temperature pin pa1
eric11fr 0:b8bade04f24f 35 uint8_t g_image_buffer[IMAGE_JPG_SIZE];
eric11fr 0:b8bade04f24f 36
eric11fr 0:b8bade04f24f 37 void telegram_bot();
eric11fr 0:b8bade04f24f 38 void init_serial(void)
eric11fr 0:b8bade04f24f 39 {
eric11fr 0:b8bade04f24f 40 pc.baud(9600);
eric11fr 0:b8bade04f24f 41 xbee.baud(38400);
eric11fr 0:b8bade04f24f 42 // came.baud(38400);
eric11fr 0:b8bade04f24f 43 }
eric11fr 0:b8bade04f24f 44
eric11fr 0:b8bade04f24f 45 void Init_Inisat(void)
eric11fr 0:b8bade04f24f 46 {
eric11fr 0:b8bade04f24f 47 activ_sensors = 0; // 3.3V power sensors board Off
eric11fr 0:b8bade04f24f 48
eric11fr 0:b8bade04f24f 49 }
eric11fr 0:b8bade04f24f 50
eric11fr 0:b8bade04f24f 51 void test_imu(void)
eric11fr 0:b8bade04f24f 52 {
eric11fr 0:b8bade04f24f 53 unsigned char stop;
eric11fr 0:b8bade04f24f 54 //cam_spi_cs=0;
eric11fr 0:b8bade04f24f 55 // sdcard_spi_cs=0;
eric11fr 0:b8bade04f24f 56 //test mpu9250-IMU
eric11fr 0:b8bade04f24f 57 pc.printf("\r\n/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 58 pc.printf("\t IMU9250 test\r\n");
eric11fr 0:b8bade04f24f 59 pc.printf("send \"s\" to stop\r\n");
eric11fr 0:b8bade04f24f 60 pc.printf("/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 61 activ_sensors = 1; // 3.3V power sensors board On
eric11fr 0:b8bade04f24f 62 wait(2);
eric11fr 0:b8bade04f24f 63
eric11fr 0:b8bade04f24f 64 //Set up I2C
eric11fr 0:b8bade04f24f 65 i2c.frequency(400000); // use fast (400 kHz) I2C
eric11fr 0:b8bade04f24f 66 t.start();
eric11fr 0:b8bade04f24f 67 // Read the WHO_AM_I register, this is a good test of communication
eric11fr 0:b8bade04f24f 68 uint8_t whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); // Read WHO_AM_I register for MPU-9250
eric11fr 0:b8bade04f24f 69 pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x71\n\r");
eric11fr 0:b8bade04f24f 70 if (whoami == 0x71) // WHO_AM_I should always be 0x68
eric11fr 0:b8bade04f24f 71 {
eric11fr 0:b8bade04f24f 72 pc.printf("MPU9250 WHO_AM_I is 0x%x\n\r", whoami);
eric11fr 0:b8bade04f24f 73 pc.printf("MPU9250 is online...\n\r");
eric11fr 0:b8bade04f24f 74 sprintf(buffer, "0x%x", whoami);
eric11fr 0:b8bade04f24f 75 wait(1);
eric11fr 0:b8bade04f24f 76 mpu9250.resetMPU9250(); // Reset registers to default in preparation for device calibration
eric11fr 0:b8bade04f24f 77 // mpu9250.MPU9250SelfTest(SelfTest); // Start by performing self test and reporting values
eric11fr 0:b8bade04f24f 78 mpu9250.calibrateMPU9250(gyroBias, accelBias); // Calibrate gyro and accelerometers, load biases in bias registers
eric11fr 0:b8bade04f24f 79 wait(2);
eric11fr 0:b8bade04f24f 80 mpu9250.initMPU9250();
eric11fr 0:b8bade04f24f 81 pc.printf("MPU9250 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature
eric11fr 0:b8bade04f24f 82 mpu9250.initAK8963(magCalibration);
eric11fr 0:b8bade04f24f 83 pc.printf("AK8963 initialized for active data mode....\n\r"); // Initialize device for active mode read of magnetometer
eric11fr 0:b8bade04f24f 84 pc.printf("Accelerometer full-scale range = %f g\n\r", 2.0f*(float)(1<<Ascale));
eric11fr 0:b8bade04f24f 85 pc.printf("Gyroscope full-scale range = %f deg/s\n\r", 250.0f*(float)(1<<Gscale));
eric11fr 0:b8bade04f24f 86 if(Mscale == 0) pc.printf("Magnetometer resolution = 14 bits\n\r");
eric11fr 0:b8bade04f24f 87 if(Mscale == 1) pc.printf("Magnetometer resolution = 16 bits\n\r");
eric11fr 0:b8bade04f24f 88 if(Mmode == 2) pc.printf("Magnetometer ODR = 8 Hz\n\r");
eric11fr 0:b8bade04f24f 89 if(Mmode == 6) pc.printf("Magnetometer ODR = 100 Hz\n\r");
eric11fr 0:b8bade04f24f 90 wait(1);
eric11fr 0:b8bade04f24f 91 }
eric11fr 0:b8bade04f24f 92 else
eric11fr 0:b8bade04f24f 93 {
eric11fr 0:b8bade04f24f 94 pc.printf("Could not connect to MPU9250: \n\r");
eric11fr 0:b8bade04f24f 95 pc.printf("%#x \n", whoami);
eric11fr 0:b8bade04f24f 96 sprintf(buffer, "WHO_AM_I 0x%x", whoami);
eric11fr 0:b8bade04f24f 97 }
eric11fr 0:b8bade04f24f 98 mpu9250.getAres(); // Get accelerometer sensitivity
eric11fr 0:b8bade04f24f 99 mpu9250.getGres(); // Get gyro sensitivity
eric11fr 0:b8bade04f24f 100 mpu9250.getMres(); // Get magnetometer sensitivity
eric11fr 0:b8bade04f24f 101 pc.printf("Accelerometer sensitivity is %f LSB/g \n\r", 1.0f/aRes);
eric11fr 0:b8bade04f24f 102 pc.printf("Gyroscope sensitivity is %f LSB/deg/s \n\r", 1.0f/gRes);
eric11fr 0:b8bade04f24f 103 pc.printf("Magnetometer sensitivity is %f LSB/G \n\r", 1.0f/mRes);
eric11fr 0:b8bade04f24f 104 magbias[0] = +470.; // User environmental x-axis correction in milliGauss, should be automatically calculated
eric11fr 0:b8bade04f24f 105 magbias[1] = +120.; // User environmental x-axis correction in milliGauss
eric11fr 0:b8bade04f24f 106 magbias[2] = +125.; // User environmental x-axis correction in milliGauss
eric11fr 0:b8bade04f24f 107 do
eric11fr 0:b8bade04f24f 108 {
eric11fr 0:b8bade04f24f 109 // If intPin goes high, all data registers have new data
eric11fr 0:b8bade04f24f 110 if(mpu9250.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01)
eric11fr 0:b8bade04f24f 111 { // On interrupt, check if data ready interrupt
eric11fr 0:b8bade04f24f 112 mpu9250.readAccelData(accelCount); // Read the x/y/z adc values
eric11fr 0:b8bade04f24f 113 // Now we'll calculate the accleration value into actual g's
eric11fr 0:b8bade04f24f 114 ax = (float)accelCount[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set
eric11fr 0:b8bade04f24f 115 ay = (float)accelCount[1]*aRes - accelBias[1];
eric11fr 0:b8bade04f24f 116 az = (float)accelCount[2]*aRes - accelBias[2];
eric11fr 0:b8bade04f24f 117 mpu9250.readGyroData(gyroCount); // Read the x/y/z adc values
eric11fr 0:b8bade04f24f 118 // Calculate the gyro value into actual degrees per second
eric11fr 0:b8bade04f24f 119 gx = (float)gyroCount[0]*gRes - gyroBias[0]; // get actual gyro value, this depends on scale being set
eric11fr 0:b8bade04f24f 120 gy = (float)gyroCount[1]*gRes - gyroBias[1];
eric11fr 0:b8bade04f24f 121 gz = (float)gyroCount[2]*gRes - gyroBias[2];
eric11fr 0:b8bade04f24f 122 mpu9250.readMagData(magCount); // Read the x/y/z adc values
eric11fr 0:b8bade04f24f 123 // Calculate the magnetometer values in milliGauss
eric11fr 0:b8bade04f24f 124 // Include factory calibration per data sheet and user environmental corrections
eric11fr 0:b8bade04f24f 125 mx = (float)magCount[0]*mRes*magCalibration[0] - magbias[0]; // get actual magnetometer value, this depends on scale being set
eric11fr 0:b8bade04f24f 126 my = (float)magCount[1]*mRes*magCalibration[1] - magbias[1];
eric11fr 0:b8bade04f24f 127 mz = (float)magCount[2]*mRes*magCalibration[2] - magbias[2];
eric11fr 0:b8bade04f24f 128 }
eric11fr 0:b8bade04f24f 129 Now = t.read_us();
eric11fr 0:b8bade04f24f 130 deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update
eric11fr 0:b8bade04f24f 131 lastUpdate = Now;
eric11fr 0:b8bade04f24f 132 sum += deltat;
eric11fr 0:b8bade04f24f 133 sumCount++;
eric11fr 0:b8bade04f24f 134 // Pass gyro rate as rad/s
eric11fr 0:b8bade04f24f 135 // mpu9250.MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz);
eric11fr 0:b8bade04f24f 136 mpu9250.MahonyQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz);
eric11fr 0:b8bade04f24f 137 // Serial print and/or display at 0.5 s rate independent of data rates
eric11fr 0:b8bade04f24f 138 delt_t = t.read_ms() - countA;
eric11fr 0:b8bade04f24f 139 if (delt_t > 500)
eric11fr 0:b8bade04f24f 140 { // update LCD once per half-second independent of read rate
eric11fr 0:b8bade04f24f 141 pc.printf("ax = %f", 1000*ax);
eric11fr 0:b8bade04f24f 142 pc.printf(" ay = %f", 1000*ay);
eric11fr 0:b8bade04f24f 143 pc.printf(" az = %f mg\n\r", 1000*az);
eric11fr 0:b8bade04f24f 144 pc.printf("gx = %f", gx);
eric11fr 0:b8bade04f24f 145 pc.printf(" gy = %f", gy);
eric11fr 0:b8bade04f24f 146 pc.printf(" gz = %f deg/s\n\r", gz);
eric11fr 0:b8bade04f24f 147 pc.printf("gx = %f", mx);
eric11fr 0:b8bade04f24f 148 pc.printf(" gy = %f", my);
eric11fr 0:b8bade04f24f 149 pc.printf(" gz = %f mG\n\r", mz);
eric11fr 0:b8bade04f24f 150 tempCount = mpu9250.readTempData(); // Read the adc values
eric11fr 0:b8bade04f24f 151 temperature = ((float) tempCount) / 333.87f + 21.0f; // Temperature in degrees Centigrade
eric11fr 0:b8bade04f24f 152 pc.printf(" temperature = %f C\n\r", temperature);
eric11fr 0:b8bade04f24f 153 pc.printf("average rate = %f\n\r", (float) sumCount/sum);
eric11fr 0:b8bade04f24f 154 countA = t.read_ms();
eric11fr 0:b8bade04f24f 155 if(countA > 1<<21)
eric11fr 0:b8bade04f24f 156 {
eric11fr 0:b8bade04f24f 157 t.start(); // start the timer over again if ~30 minutes has passed
eric11fr 0:b8bade04f24f 158 countA = 0;
eric11fr 0:b8bade04f24f 159 deltat= 0;
eric11fr 0:b8bade04f24f 160 lastUpdate = t.read_us();
eric11fr 0:b8bade04f24f 161 }
eric11fr 0:b8bade04f24f 162 sum = 0;
eric11fr 0:b8bade04f24f 163 sumCount = 0;
eric11fr 0:b8bade04f24f 164 }
eric11fr 0:b8bade04f24f 165 if(pc.readable())
eric11fr 0:b8bade04f24f 166 stop=pc.getc();
eric11fr 0:b8bade04f24f 167 } while(stop!='s');
eric11fr 0:b8bade04f24f 168 //activ_sensors = 0; // 3.3V power sensors board Off
eric11fr 0:b8bade04f24f 169 }
eric11fr 0:b8bade04f24f 170
eric11fr 0:b8bade04f24f 171 void telegram_bot()
eric11fr 0:b8bade04f24f 172 {
eric11fr 0:b8bade04f24f 173
eric11fr 0:b8bade04f24f 174
eric11fr 0:b8bade04f24f 175
eric11fr 0:b8bade04f24f 176 /* main loop */
eric11fr 0:b8bade04f24f 177 // while (1)
eric11fr 0:b8bade04f24f 178 {sdcard_spi_cs=1;//deactivate sdcard cs
eric11fr 0:b8bade04f24f 179 cam_spi_cs=0;
eric11fr 0:b8bade04f24f 180
eric11fr 0:b8bade04f24f 181
eric11fr 0:b8bade04f24f 182 uint32_t image_size;
eric11fr 0:b8bade04f24f 183 uint32_t idx;
eric11fr 0:b8bade04f24f 184
eric11fr 0:b8bade04f24f 185
eric11fr 0:b8bade04f24f 186 for(int i=0; i<3; i++)
eric11fr 0:b8bade04f24f 187 {
eric11fr 0:b8bade04f24f 188 image_size = g_arducam.CaptureImage(g_image_buffer,IMAGE_JPG_SIZE,&idx);
eric11fr 0:b8bade04f24f 189 if( image_size == 0 )
eric11fr 0:b8bade04f24f 190 {
eric11fr 0:b8bade04f24f 191 printf("Photo failure %d\r\n",image_size);
eric11fr 0:b8bade04f24f 192 break;
eric11fr 0:b8bade04f24f 193 }
eric11fr 0:b8bade04f24f 194 else
eric11fr 0:b8bade04f24f 195 pc.printf("taille image%d",image_size);
eric11fr 0:b8bade04f24f 196 }
eric11fr 0:b8bade04f24f 197 sdcard_spi_cs=0;//activate sdcard cs, deactivate cam
eric11fr 0:b8bade04f24f 198 cam_spi_cs=1;
eric11fr 0:b8bade04f24f 199 FILE *fp = fopen("/sd/mydir/image.jpg", "w");
eric11fr 0:b8bade04f24f 200 if(fp == NULL) {
eric11fr 0:b8bade04f24f 201 error("Could not open file for write\n");
eric11fr 0:b8bade04f24f 202 }
eric11fr 0:b8bade04f24f 203
eric11fr 0:b8bade04f24f 204
eric11fr 0:b8bade04f24f 205 for (uint32_t l=1;l<image_size+1;l++)
eric11fr 0:b8bade04f24f 206 fprintf(fp, "%c",g_image_buffer[l]);
eric11fr 0:b8bade04f24f 207 //pc.printf("%c",g_image_buffer[l]);
eric11fr 0:b8bade04f24f 208 fclose(fp);
eric11fr 0:b8bade04f24f 209 }
eric11fr 0:b8bade04f24f 210 }
eric11fr 0:b8bade04f24f 211 void test_camera(void)
eric11fr 0:b8bade04f24f 212 {
eric11fr 0:b8bade04f24f 213 sdcard_spi_cs=1;//deactivate sdcard cs
eric11fr 0:b8bade04f24f 214 cam_spi_cs=0;
eric11fr 0:b8bade04f24f 215 // pc.baud(9600);
eric11fr 0:b8bade04f24f 216 if( g_arducam.Setup( OV_RESOLUTION_CIF/*OV_RESOLUTION_QQVGA*/,92, &cam_spi_cs, &camSPI, &camI2C) == false)
eric11fr 0:b8bade04f24f 217 {
eric11fr 0:b8bade04f24f 218 pc.printf("Arducam setup error \r\n");
eric11fr 0:b8bade04f24f 219 exit(0);
eric11fr 0:b8bade04f24f 220 }
eric11fr 0:b8bade04f24f 221 else
eric11fr 0:b8bade04f24f 222 pc.printf("init_ok");
eric11fr 0:b8bade04f24f 223 /* start chatbot */
eric11fr 0:b8bade04f24f 224 telegram_bot();
eric11fr 0:b8bade04f24f 225
eric11fr 0:b8bade04f24f 226 }
eric11fr 0:b8bade04f24f 227
eric11fr 0:b8bade04f24f 228 void test_gps(void)
eric11fr 0:b8bade04f24f 229 {unsigned char tmp;
eric11fr 0:b8bade04f24f 230 unsigned char stop=0;
eric11fr 0:b8bade04f24f 231 // ser.baud(9600);
eric11fr 0:b8bade04f24f 232 //GPS selection
eric11fr 0:b8bade04f24f 233 activ_sensors = 1; // 3.3V power sensors board On
eric11fr 0:b8bade04f24f 234
eric11fr 0:b8bade04f24f 235 init_uart();
eric11fr 0:b8bade04f24f 236 pc.printf("\r\n/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 237 pc.printf("\tGPS module test\r\n");
eric11fr 0:b8bade04f24f 238 pc.printf("send \"s\" to stop\r\n");
eric11fr 0:b8bade04f24f 239 pc.printf("/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 240 wait(2);
eric11fr 0:b8bade04f24f 241 do
eric11fr 0:b8bade04f24f 242 {
eric11fr 0:b8bade04f24f 243 do
eric11fr 0:b8bade04f24f 244 {
eric11fr 0:b8bade04f24f 245 tmp= _getchar();
eric11fr 0:b8bade04f24f 246 pc.printf("%c",tmp);
eric11fr 0:b8bade04f24f 247 }while(tmp!='\r');
eric11fr 0:b8bade04f24f 248 if(pc.readable())
eric11fr 0:b8bade04f24f 249 stop=pc.getc();
eric11fr 0:b8bade04f24f 250 } while(stop!='s');
eric11fr 0:b8bade04f24f 251 }
eric11fr 0:b8bade04f24f 252
eric11fr 0:b8bade04f24f 253 void test_sdcard(void)
eric11fr 0:b8bade04f24f 254 {
eric11fr 0:b8bade04f24f 255 char buf[50];
eric11fr 0:b8bade04f24f 256 cam_spi_cs=1; //deactivate CS camera
eric11fr 0:b8bade04f24f 257
eric11fr 0:b8bade04f24f 258 pc.printf("\r\n/*----------------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 259 pc.printf("\t SDCard module test\r\n");
eric11fr 0:b8bade04f24f 260 pc.printf("/*----------------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 261 pc.printf("Write some words in sdtest.txt on sd/mydir directory\r\n");
eric11fr 0:b8bade04f24f 262 mkdir("/sd/mydir", 0777);
eric11fr 0:b8bade04f24f 263 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
eric11fr 0:b8bade04f24f 264 if(fp == NULL) {
eric11fr 0:b8bade04f24f 265 error("Could not open file for write\n");
eric11fr 0:b8bade04f24f 266 }
eric11fr 0:b8bade04f24f 267 fprintf(fp, "Hello World, greats from Inisat!");
eric11fr 0:b8bade04f24f 268 fclose(fp);
eric11fr 0:b8bade04f24f 269 FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r");
eric11fr 0:b8bade04f24f 270 if(fp1 == NULL) {
eric11fr 0:b8bade04f24f 271 error("Could not open file for write\n");
eric11fr 0:b8bade04f24f 272 }
eric11fr 0:b8bade04f24f 273 //fscanf(fp,"%s",buf);
eric11fr 0:b8bade04f24f 274 fgets(buf,50,fp1);
eric11fr 0:b8bade04f24f 275 wait(2);
eric11fr 0:b8bade04f24f 276 pc.printf("read from sd/mydir directory : %s\r\n",buf);
eric11fr 0:b8bade04f24f 277 fclose(fp1);
eric11fr 0:b8bade04f24f 278 }
eric11fr 0:b8bade04f24f 279
eric11fr 0:b8bade04f24f 280 void test_xbee_comm()
eric11fr 0:b8bade04f24f 281 {
eric11fr 0:b8bade04f24f 282 char buf[250];
eric11fr 0:b8bade04f24f 283 pc.printf("\r\n/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 284 pc.printf("\t xbee module test\r\n");
eric11fr 0:b8bade04f24f 285 pc.printf("/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 286
eric11fr 0:b8bade04f24f 287 xbee.printf("Hello from inisat\r\nTest receiving data from Ground Station : type a sentence and press enter to loopback\r\n");
eric11fr 0:b8bade04f24f 288 while(pc.getc()!='s')
eric11fr 0:b8bade04f24f 289 {
eric11fr 0:b8bade04f24f 290 xbee.printf("%s\r\n",pc.gets(buf,250)); // Echo
eric11fr 0:b8bade04f24f 291
eric11fr 0:b8bade04f24f 292 }
eric11fr 0:b8bade04f24f 293 while(xbee.getc()!='s')
eric11fr 0:b8bade04f24f 294 pc.printf("%c\r\n",xbee.getc());
eric11fr 0:b8bade04f24f 295 }
eric11fr 0:b8bade04f24f 296
eric11fr 0:b8bade04f24f 297 void test_analog_sensor(void)
eric11fr 0:b8bade04f24f 298 {
eric11fr 0:b8bade04f24f 299 unsigned char stop=0;
eric11fr 0:b8bade04f24f 300 activ_sensors = 1;
eric11fr 0:b8bade04f24f 301 pc.printf("\r\n/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 302 pc.printf("\t Battery level and temperature sensor test\r\n");
eric11fr 0:b8bade04f24f 303 pc.printf("send \"s\" to stop\r\n");
eric11fr 0:b8bade04f24f 304 pc.printf("/*----------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 305 wait(2);
eric11fr 0:b8bade04f24f 306 do
eric11fr 0:b8bade04f24f 307 {
eric11fr 0:b8bade04f24f 308 wait_ms(300);
eric11fr 0:b8bade04f24f 309 pc.printf("battery: %.2f V\t\t",batin.read()*4.59f); // 3.3 * 13.9/10
eric11fr 0:b8bade04f24f 310 pc.printf("temperature: %.1f degC\r\n",(tempin.read()*3.3f-0.5f)/0.01f);
eric11fr 0:b8bade04f24f 311 if(pc.readable())
eric11fr 0:b8bade04f24f 312 stop=pc.getc();
eric11fr 0:b8bade04f24f 313 }while(stop!='s');
eric11fr 0:b8bade04f24f 314 }
eric11fr 0:b8bade04f24f 315 void quit(void)
eric11fr 0:b8bade04f24f 316 {
eric11fr 0:b8bade04f24f 317 //do nothing
eric11fr 0:b8bade04f24f 318 pc.printf("\r\nbye bye...");
eric11fr 0:b8bade04f24f 319 exit(0);
eric11fr 0:b8bade04f24f 320 }
eric11fr 0:b8bade04f24f 321 int menu(void)
eric11fr 0:b8bade04f24f 322 {int choice=0;
eric11fr 0:b8bade04f24f 323 // menu tests
eric11fr 0:b8bade04f24f 324 //pc.putc(27);//to clear terminal screen
eric11fr 0:b8bade04f24f 325 //pc.printf("[2J");
eric11fr 0:b8bade04f24f 326 pc.printf("\r\n/*-------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 327 pc.printf("\t1. Test IMU\r\n");
eric11fr 0:b8bade04f24f 328 pc.printf("\t2. Test SDCARD\r\n");
eric11fr 0:b8bade04f24f 329 pc.printf("\t3. Test GPS\r\n");
eric11fr 0:b8bade04f24f 330 pc.printf("\t4. Test CAMERA\r\n");
eric11fr 0:b8bade04f24f 331 pc.printf("\t5. Test temperature sensor & battery level \r\n");
eric11fr 0:b8bade04f24f 332 pc.printf("\t6. Test XBEE communication\r\n");
eric11fr 0:b8bade04f24f 333 pc.printf("\t7. Quit\r\n");
eric11fr 0:b8bade04f24f 334 pc.printf("/*-------------------------------------------*/\r\n");
eric11fr 0:b8bade04f24f 335 do
eric11fr 0:b8bade04f24f 336 {
eric11fr 0:b8bade04f24f 337 pc.printf("Please enter your choice (1 to 7):");
eric11fr 0:b8bade04f24f 338 choice=pc.getc();
eric11fr 0:b8bade04f24f 339 }while(choice<0x31||choice>0x37);
eric11fr 0:b8bade04f24f 340 return choice;
eric11fr 0:b8bade04f24f 341 }
eric11fr 0:b8bade04f24f 342
eric11fr 0:b8bade04f24f 343 int main()
eric11fr 0:b8bade04f24f 344 {
eric11fr 0:b8bade04f24f 345 float batest;
eric11fr 0:b8bade04f24f 346 unsigned char start;
eric11fr 0:b8bade04f24f 347
eric11fr 0:b8bade04f24f 348 int status=0;
eric11fr 0:b8bade04f24f 349 //initialise serial communication
eric11fr 0:b8bade04f24f 350 init_serial();
eric11fr 0:b8bade04f24f 351 //initialise inisat port
eric11fr 0:b8bade04f24f 352 Init_Inisat();
eric11fr 0:b8bade04f24f 353 batest=batin.read()*4.59f;
eric11fr 0:b8bade04f24f 354 pc.printf("battery: %.2f V\r\n",batest);
eric11fr 0:b8bade04f24f 355
eric11fr 0:b8bade04f24f 356 /* if (batest < 3.3f)
eric11fr 0:b8bade04f24f 357 {
eric11fr 0:b8bade04f24f 358 pc.printf("low battery, please recharge\r\n");
eric11fr 0:b8bade04f24f 359 exit(0);
eric11fr 0:b8bade04f24f 360 }*/
eric11fr 0:b8bade04f24f 361 pc.printf("Press \"S\" to Start\r\n");
eric11fr 0:b8bade04f24f 362 do
eric11fr 0:b8bade04f24f 363 {
eric11fr 0:b8bade04f24f 364 if(pc.readable())
eric11fr 0:b8bade04f24f 365 start=pc.getc();
eric11fr 0:b8bade04f24f 366 }while((start!='S') && (start != 's'));
eric11fr 0:b8bade04f24f 367
eric11fr 0:b8bade04f24f 368 while(1)
eric11fr 0:b8bade04f24f 369 {
eric11fr 0:b8bade04f24f 370 switch(status)
eric11fr 0:b8bade04f24f 371 {
eric11fr 0:b8bade04f24f 372 case 0 : status=menu();
eric11fr 0:b8bade04f24f 373 break;
eric11fr 0:b8bade04f24f 374 case '1' : test_imu();
eric11fr 0:b8bade04f24f 375 status=0;
eric11fr 0:b8bade04f24f 376 break;
eric11fr 0:b8bade04f24f 377 case '2' : test_sdcard();
eric11fr 0:b8bade04f24f 378 status=0;
eric11fr 0:b8bade04f24f 379 break;
eric11fr 0:b8bade04f24f 380 case '3' : test_gps();
eric11fr 0:b8bade04f24f 381 status=0;
eric11fr 0:b8bade04f24f 382 break;
eric11fr 0:b8bade04f24f 383 case '4' : test_camera();
eric11fr 0:b8bade04f24f 384 status=0;
eric11fr 0:b8bade04f24f 385 break;
eric11fr 0:b8bade04f24f 386 case '5' : test_analog_sensor();
eric11fr 0:b8bade04f24f 387 status=0;
eric11fr 0:b8bade04f24f 388 break;
eric11fr 0:b8bade04f24f 389 case '6' : test_xbee_comm();
eric11fr 0:b8bade04f24f 390 status=0;
eric11fr 0:b8bade04f24f 391 break;
eric11fr 0:b8bade04f24f 392 //case 7: all_test();
eric11fr 0:b8bade04f24f 393 // break;
eric11fr 0:b8bade04f24f 394 case '7' : quit();
eric11fr 0:b8bade04f24f 395 break;
eric11fr 0:b8bade04f24f 396 }
eric11fr 0:b8bade04f24f 397 }
eric11fr 0:b8bade04f24f 398 }