v1

Dependencies:   mbed Servo

Committer:
Giamarchi
Date:
Thu Sep 10 16:01:56 2020 +0000
Revision:
1:d8964d9ff503
Parent:
0:b8bade04f24f
Update Solar Panel Currents

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