|
本帖最后由 点点&木木 于 2019-4-12 12:07 编辑 一个完全自动的坑洼探测器,可实时更新可视后端,并提供存储在SD卡上的详细数据。
硬件组件 STM32 Nucleo-L432KC × 1 Grove - 3轴数字加速度计(±1.5g) Seeed Grove - 3轴数字加速度计(±1.5g) × 1 Seeed Grove GPS × 1 Sigfox模块 × 1 夏普红外传感器 × 6 DFRobot Micro-SD模块 × 1 锂离子充电器MAX1555DS × 1 降压 - 升压转换器MCP1252 / 3 × 1 100kΩ电阻 × 1 1μF电容 × 4 10μF电容 × 2 太阳能电池 × 1 锂离子电池 × 1 10μF电容 × 12 介绍 每年,雷诺都会举办一场黑客攻击Twizy平台(基于电动城市车辆的设计)的比赛。我们参加了那次比赛(通过我们的大学,Polytech Sorbonne),并提出了破解平台的想法,制作一个坑洞探测车,可以实时更新地下坑洞的位置。 那么它是怎样工作的? 其安装在车辆下方的6个红外传感器阵列向下检测车辆与道路之间的距离变化,从而检测坑洼。系统的加速度计还可以检测由于异常垂直变化导致的车辆经历的坑洼和突然冲击。 系统然后将该信息(通过Sigfox模块)发送到我们使用MicrosoftAzure制作的后端,然后信息显示在我们使用PowerBI制作的地图界面上。该系统还以JSON格式存储有关板载micro-SD卡的详细数据,因此用户可以恢复该信息,以便构建系统检测到的每个坑洞严重程度的更清晰图像。
地图上的蓝点表示我们测试坑洞探测系统的位置。 该系统由锂离子电池供电,通过太阳能电池板充电。 现在让我们继续讨论如何制作这个项目! 主板PCB 首先,您需要按照主PCB原理图布线PCB:
主板PCB原理图 完成后,您可以将所有主要组件焊接到位:微控制器(注意不要将其放在后面!),红外传感器,GPS和加速度计模块,Sigfox以及最后SD模块的接头。一旦焊接或连接到PCB,您就可以焊接去耦电容。 电源PCB 现在是时候制作电源PCB为电池充电并为微控制器(以及主PCB的其余部分)提供稳定的5V电压。 您首先需要按照此原理图布线PCB:
电源PCB原理图 中间的两个点需要连接,因此需要在它们之间焊接跳线。然后,您可以将太阳能电池板焊接在图表右侧的连接焊盘上,并将电池焊接在两个中间点(+端子)的下部之间,并将 - 端子连接到地。您现在应该在左侧的连接点之间保持稳定的5V。您可以将两根电缆焊接到这些点,并在Nucleo微控制器上相应地连接到VIN和GND引脚。 3D打印外壳(可选) 您可以在您选择的建模软件中制作一个简单的盒子容器,然后进行3D打印,以便有一个容器可以放置您的电子产品。这是可选的(您也可以购买预制容器)。
我们的容器(我们添加了几个孔,因此我们可以访问模块:SD,Sigfox,GPS) 把它们放在一起 现在一切都在电子设备上工作,你可以将所有东西放在容器中,然后将红外传感器安装在可以安装到车辆上的条上:
最终产品 我们将数据传输到Sigfox后端。我们每天可以发送140封邮件。这是足够的,因为我们每天都没有检测到140个坑洞。我们发送它的经度和经度。 为了处理我们收集的所有信息,我们选择使用Microsoft Azure,因为我们可以为学生免费试用。我们通过这个github教程配置 后端分为两部分:Microsoft Azure用于收集信息,Power BI用于处理数据。鉴于我们从Sigfox后端收到的消息,我们将它打印在Power BI上的地图上,您可以在Story部分的屏幕截图中看到。 原理图 主PCB原理图
电源PCB原理图
功能图
能源消耗
外壳3D模型
代码 #include "mbed.h" #include "GroveGPS.h" #include <SDBlockDevice.h> #include <FATFileSystem.h> #include <string> #include <cstring> #include <sstream> #include <string> /////////////////////////// //// Various Constants //// /////////////////////////// #define COOLDOWN 100000 // Cooldown time #define GPS_SIZE 16 // Size of GPS position arrays #define NORMAL_DISTANCE 15 // Normal IR-sensor-to-ground distance (in cm) #define SENSITIVITY 3 // IR sensorsensitivity (in cm) AnalogIn ir1(A0); // IR sensor AnalogIn ir2(A1); AnalogIn ir3(A3); AnalogIn ir4(A4); AnalogIn ir5(A5); AnalogIn ir6(A6); Serial gpsSerial(D1, D0, 9600); // GPS module Serial sigfox(SERIAL_TX, SERIAL_RX, 9600); //Telecommunications module Serial pc(SERIAL_TX, SERIAL_RX, 9600); // Transistors DigitalOut line_5V(D7); DigitalOut line_3V(D8); SDBlockDevice sd(D11, D12, D13, D3); // SD card reader module FATFileSystem fs("sd"); // FAT file system to handle SD card Thread gpsThread; // Initialize two threads for the Thread irThread; // telemeter and the GPS. GroveGPS gps; // Initialize the Grove GPS I2C i2c(D4, D5); // I2C for the accelerometer //// Variables for the accelerometercalculus : char addr_accel = 0x4C<<1; // Adress of the device char regAddr[1]; // Registers for the address, char regRead[2]; // to read and to write the registers char regWrite[3]; const int SeuilTrigger = 150; // Match-to-trigger value. const float SeuilTremblement = 0.8; // Arrays of previous registered values : float* xTab = (float*)malloc(100*sizeof(float)); float* yTab = (float*)malloc(100*sizeof(float)); float* zTab = (float*)malloc(100*sizeof(float)); float xGet, yGet, zGet; // Current registered values float distance_ir1; // Current IR distance float distance_ir2; float distance_ir3; float distance_ir4; float distance_ir5; float distance_ir6; float max_distance_ir; char *gps_pos[20]; // Array of recorded positions int gps_index = 0; // Index to navigate the position array bool begin_capture = false; /////////////////////// //// GPS FUNCTIONS //// /////////////////////// bool checkValidityGPS (char* latBuffer,char* lonBuffer) { // Checks if a given GPS position pair is valid/ if (latBuffer[0] == 'N') return false; if (latBuffer[0] == '-') return false; return true; } //////////////////////////// //// INFRARED FUNCTIONS //// //////////////////////////// float voltsIR (float measure) { // Gets the voltage produced by the IR sensor return measure * 5; } float distanceIR (float measure) { // Calculates the distance based on an IR sensor measure(in cm) float a = 127.728; float b = 0.353553; return a * pow(b,voltsIR(measure)); } ///////////////////////////// //// MMA7660FC FUNCTIONS //// ///////////////////////////// void write_reg(char addReg, char value){ // Writes valueinto the register at the address 0x[addReg}. regAddr[0] = addReg; regWrite[0] = regAddr[0]; regWrite[1] = value; i2c.write(addr_accel, regWrite, 2); } int read_reg(char addReg){ // Reads the value of the register 0x[addReg] and returnsit. regAddr[0] = addReg; i2c.write(addr_accel, regAddr, 1, true); // Selection of the register i2c.read(addr_accel, regRead, 2); // Read the value inside. return regRead[0]; } int convert_6bitC2(int ValReg){ // The registers XOUT, YOUT, ZOUT contain the values ofthe accelerations // on 6 bits. These values are between -32 and 31,following // the two's convention. int result = 0; result += (ValReg & 0b00011111); result -= (ValReg & 0b00100000); return result; } void init_i2c(){ // Peripheral Functions. // The device works by stocking its data into differentregisters. The full // documentation can be read at the following address : // In order to understand the code, you can read thefollowing pages : // -> p14 : Addresses of the interesting registers(XOUT, YOUT, ZOUT) // -> p17 : MODE Register Configuration. (Reallyimportant) // -> p22 : Serial and I2C. // Interrupt Setp : Edit write_reg(0x06, 0b00000000); // Disable tous les Interrupt. // Mode Setup : Edit write_reg(0x07, 0b00000001); // Sampling Rate : Edit write_reg(0x08, 0b00000001); // 64 sample per second, so 1 in 0.0156 s. } void mesure_accels(){ // First step : Initialize the data. xGet = 0.0; yGet = 0.0; zGet = 0.0; // Second step : Mesure the accelerations in bothdirections, three times. for (int i = 0; i < 3; i++){ xGet += convert_6bitC2(read_reg(0x00)); yGet += convert_6bitC2(read_reg(0x01)); zGet += convert_6bitC2(read_reg(0x02)); wait(0.01); } // Third step : Calibrate the data in m.s-2 xGet = xGet / (2.14*3); yGet = yGet / (2.14*3); zGet = zGet / (2.14*3); // Fourth step : Shift the whole arrays. for (int i = 0; i < 99; i++){ xTab = xTab[i+1]; yTab = yTab[i+1]; zTab = zTab[i+1]; } // Finally : Put the new data into the arrays. xTab[99] = xGet; yTab[99] = yGet; zTab[99] = zGet; } ///////////////////////// //// PRINT TO SERIAL //// ///////////////////////// void write_serial (bool first, char *lat,char *lon, float ir, float acc) { // If it's not the first object, print a ',' character toseparate them. if (!first) pc.printf(","); // Print the LONG JSON content pc.printf("\r\n\t{\r\n"); pc.printf("\t\t\"lat\": \"%s\",\r\n", lat); pc.printf("\t\t\"lon\": \"%s\",\r\n", lon); pc.printf("\t\t\"infrared\": \"%f\",\r\n", ir); pc.printf("\t\t\"accelerometer\": \"%f\"\r\n\t}", acc); } void write_JSON_object (bool first, FILE*fp, char *lat, char *lon, float ir, float acc) { if (!first) fprintf(fp, ","); fprintf(fp, "\r\n\t{\r\n"); fprintf(fp, "\t\t\"lat\": \"%s\",\r\n", lat); fprintf(fp, "\t\t\"lon\": \"%s\",\r\n", lon); fprintf(fp, "\t\t\"infrared\": \"%f\",\r\n", ir); fprintf(fp, "\t\t\"accelerometer\": \"%f\"\r\n\t}", acc); } //////////////// //// SIGFOX //// //////////////// void sendViaSigfox (char *lat, char *lon) { // Converts char * positions into floats float temp_lat = atof(lat); float temp_lon = atof(lon); // Multiply them by 1e5 and keep the integer part int int_lat = (int) (temp_lat * 1e5); int int_lon = (int) (temp_lon * 1e5); // Sends the Sigfox command (8 hex chars for eachposition element) pc.printf("AT$SF=%08X%08X\n", int_lat, int_lon); } void gpsUpdaterThread () { char latBuffer[GPS_SIZE]; char lonBuffer[GPS_SIZE]; bool measured = false; int capture_cooldown = COOLDOWN; int sd_measure_number = 1; while (1) { // Update the GPS gps.getLatitude(latBuffer); gps.getLongitude(lonBuffer); // If GPS is valid if (checkValidityGPS(latBuffer, lonBuffer)) { // Update the position array sprintf(gps_pos[gps_index], "%s", latBuffer); sprintf(gps_pos[gps_index + 1], "%s", lonBuffer); // Move the pointer in the array gps_index += 2; // If the pointer overflows, move it back if (gps_index>= 20) gps_index = 0; } // Begin capture only if GPS is valid if(strcmp(gps_pos[gps_index - 2], "") != 0) { if (!measured) { line_5V = 1; line_3V = 1; std::stringstream s; // TODO sd_measure_number / 10 s << "/sd/measure_" << sd_measure_number << ".json"; char fo[s.str().length() + 1]; strcpy(fo, s.str().c_str()); // Get the current acceleration mesure_accels(); // Get the current distance measured by the IR sensor distance_ir1 = distanceIR(ir1.read()); distance_ir2 =distanceIR(ir2.read()); distance_ir3 =distanceIR(ir3.read()); distance_ir4 =distanceIR(ir4.read()); distance_ir5 =distanceIR(ir5.read()); distance_ir6 =distanceIR(ir6.read()); max_distance_ir = distance_ir1; if (distance_ir2 > max_distance_ir)max_distance_ir = distance_ir2; if (distance_ir3 > max_distance_ir)max_distance_ir = distance_ir3; if (distance_ir4 > max_distance_ir)max_distance_ir = distance_ir4; if (distance_ir5 > max_distance_ir)max_distance_ir = distance_ir5; if (distance_ir6 > max_distance_ir)max_distance_ir = distance_ir6; // MOYENNE TELEMETRES 1 ET 2 // Les autres ne fonctionnent pas correctement max_distance_ir = (distance_ir1+ distance_ir2) / 2; // If either the IR sensor or the accelerometer get triggered if ((max_distance_ir > NORMAL_DISTANCE +SENSITIVITY) or (zGet > 14)) { // initialize and mount SD card sd.init(); fs.mount(&sd); FILE *fp = fopen(fo, "w"); if (!fp) pc.printf("error handling file %s\r\n", fo); else pc.printf("Writing to %s\r\n", fo); fprintf(fp, "["); write_JSON_object(true, fp,gps_pos[gps_index - 2], gps_pos[gps_index - 1], max_distance_ir, zGet); fprintf(fp, "\n]\n"); fclose(fp); fs.unmount(); sd.deinit(); // Send the position via Sigfox sendViaSigfox(gps_pos[gps_index - 2], gps_pos[gps_index -1]); line_5V = 0; line_3V = 0; measured = true; sd_measure_number++; } } else { if (capture_cooldown > 0) { capture_cooldown--; } else { capture_cooldown =COOLDOWN; measured = false; } } } } } /////////////////////// //// MAIN FUNCTION //// /////////////////////// int main () { // Turn off 5V and 3.3V rails line_5V = 0; line_3V = 0; // Initialize the position array for (int i = 0; i < 20; i++) { gps_pos = (char *) malloc(GPS_SIZE * sizeof(char)); } // Initialize I2C communications init_i2c(); // Start a thread to get updated GPS values gpsThread.start(gpsUpdaterThread); while (1) { // get GPS data if(gpsSerial.readable()) { gps.readCharacter(gpsSerial.getc()); } } return 0; } |
STM32
超强工具——STM32CubeMX 你会用吗?
集结出发! STM32全国研讨会系列之一:ST智能门铃中国首秀
关于STM32启动文件的几个小问题
【银杏科技ARM+FPGA双核心应用】STM32H7系列35——USB_VCP_FS
【银杏科技ARM+FPGA双核心应用】STM32H7系列28——USB_HID
粉丝分享 | 图说CRC原理应用及STM32硬件CRC外设
STM32L151进入低功耗,并由RTC唤醒的故事
[转]stm32控制NFC模块(PN532)源码(P2P,模拟卡,读写卡等
STM32G070RB+LVGL移植
微信公众号
手机版
厉害了我的哥!