1赞

回答

收藏

《2024 DigiKey 汽车应用创意挑战赛》避障车提交

#竞赛 #竞赛 1096 人阅读 | 0 人回复 | 2025-01-15

一、项目名称:
避障巡线车
二、项目概述:
本系统是基于双核NXP-MCXN947为主控芯片的智能巡线车,采用超声波传感器捕捉周围障碍物信息,ADI-TMC5272系列驱动步进电机,实现位置感知,通过MKR-1010进行驱动控制。同时采用MCXN947的AI功能识别周围人的存在,发现时及时停止。
三、作品实物图
正面采用超声波传感器和摄像头视觉识别
连接在移动车体内的布置
采用的FRDM-MCXN947开发板
配套的步进电机
配置的皮带轮和连接器

四、演示视频
视频压缩见附件
Video.zip (1.28 MB, 下载次数: 3)
五、项目文档
5.1 使用的硬件
FRDM-MCXN947 开发板
12V双极步进电机及皮带轮套件
11.7V电池
MKR WIFI 1010 开发板
TMC5272 步进电机驱动板
HCSR-04 超声波距离传感器
OV2640摄像头
5.2 使用的软件
Arduino IDE
MCUXpresso IDE
TMCL-IDE for TMC5272
5.3 硬件连接
5.4 软件流程图
5.5 Aruduino代码和视觉识别代码见附件
避障车.zip (14.66 MB, 下载次数: 11)
其中arduino代码如下
  1. /*******************************************************************************
  2. * Copyright ? 2023 Analog Devices Inc. All Rights Reserved.
  3. * This software is proprietary to Analog Devices, Inc. and its licensors.
  4. *******************************************************************************/

  5. #include "Arduino.h"
  6. #include <60ghzbreathheart.h>
  7. #include <SPI.h>
  8. #include <afstandssensor.h>
  9. #include <Servo.h>

  10. extern "C" {
  11. #include "TMC5272_HW_Abstraction.h"
  12. #include "TMC5272.h"
  13. #include "TMC5272_Simple_Rotation.h"
  14. }

  15. /*
  16. * Arduino Pins   Eval Board Pins
  17. * 51 MOSI        32 SPI1_SDI
  18. * 50 MISO        33 SPI1_SDO
  19. * 52 SCK         31 SPI1_SCK
  20. * 53 SS          30 SPI1_CSN
  21. * 14 USART3_TX   22 UART_RX
  22. * 15 USART3_RX   21 UART_TX
  23. * GND            23 CLK16 -> use internal
  24. * 23 DIO         19 nSleep
  25. * GND            2 GND
  26. * +5V            5 +5V_USB
  27. * 27 iRefR2      35 IREF_R2
  28. * 29 iRefR3      36 IRREF_R3
  29. * 31 uartMode    20 USEL
  30. */

  31. //AfstandsSensor afstandssensor(7, 6);  
  32. AfstandsSensor afstandssensor1(A2, A3);
  33. AfstandsSensor afstandssensor2(A4, A5);  

  34. BreathHeart_60GHz radar = BreathHeart_60GHz(&Serial1);
  35. Servo directservo;

  36. #define AVGVELOCITY  0x00002710
  37. #define SLOWVELOCITY 0x00001000
  38. #define STOPVELOCITY 0x00000000

  39. #define LEFTDIRECT   15
  40. #define RIGHTDIRECT -15

  41. #define IC_ID 0
  42. static TMC5272BusType activeBus = IC_BUS_SPI;
  43. static uint8_t nodeAddress = 0;

  44. const uint8_t tmcCRCTable_Poly7Reflected[256] = {
  45.     0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B,
  46.     0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67,
  47.     0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43,
  48.     0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51, 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F,
  49.     0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, 0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B,
  50.     0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19, 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17,
  51.     0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, 0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33,
  52.     0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21, 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F,
  53.     0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95, 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B,
  54.     0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89, 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87,
  55.     0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD, 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3,
  56.     0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1, 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF,
  57.     0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5, 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB,
  58.     0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7,
  59.     0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3,
  60.     0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF,
  61. };

  62. int pos = 0;
  63. //int nSleep = 23;
  64. //int iRefR2 = 27;
  65. //int iRefR3 = 29;
  66. //int uartMode = 31;
  67. int nSleep = 6;
  68. int iRefR2 = 7;
  69. int iRefR3 = 7;
  70. int uartMode = 6;

  71. float leftSonic  = 0;
  72. float rightSonic = 0;
  73. float humanDist  = 0;
  74. int leftVelocity = 0;
  75. int rightVelocity= 0;
  76. int Velocity= 0;

  77. uint8_t tmc5272_getNodeAddress(uint16_t icID) {
  78.   return nodeAddress;
  79. }

  80. TMC5272BusType tmc5272_getBusType(uint16_t icID) {
  81.   return activeBus;
  82. }

  83. void tmc5272_readWriteSPI(uint16_t icID, uint8_t *data, size_t dataLength) {
  84.   digitalWrite(PIN_SPI_SS, LOW);
  85.   delayMicroseconds(10);

  86.   for (uint32_t i = 0; i < dataLength; i++) {
  87.     data[i] = SPI.transfer(data[i]);
  88.     Serial.println(data[i]);
  89.   }

  90.   delayMicroseconds(10);
  91.   digitalWrite(PIN_SPI_SS, HIGH);
  92. }

  93. void radarRead(void)
  94. {
  95.   
  96.   radar.HumanExis_Func();           //Human existence information output
  97.   if(radar.sensor_report != 0x00){
  98.     switch(radar.sensor_report){
  99.       case NOONE:
  100.         Serial.println("Nobody here.");
  101.         Serial.println("----------------------------");
  102.         break;
  103.       case SOMEONE:
  104.         Serial.println("Someone is here.");
  105.         Serial.println("----------------------------");
  106.         break;
  107.       case NONEPSE:
  108.         Serial.println("No human activity messages.");
  109.         Serial.println("----------------------------");
  110.         break;
  111.       case STATION:
  112.         Serial.println("Someone stop");
  113.         Serial.println("----------------------------");
  114.         break;
  115.       case MOVE:
  116.         Serial.println("Someone moving");
  117.         Serial.println("----------------------------");
  118.         break;
  119.       case BODYVAL:
  120.         Serial.print("The parameters of human body signs are: ");
  121.         Serial.println(radar.bodysign_val, DEC);
  122.         Serial.println("----------------------------");
  123.         break;
  124.       case DISVAL:
  125.         Serial.print("The sensor judges the distance to the human body to be: ");
  126.         Serial.print(radar.distance, DEC);
  127.         Serial.println(" m");
  128.         Serial.println("----------------------------");
  129.         break;
  130.       case DIREVAL:
  131.         Serial.print("The sensor judges the orientation data with the human body as -- x: ");
  132.         Serial.print(radar.Dir_x);
  133.         Serial.print(" m, y: ");
  134.         Serial.print(radar.Dir_y);
  135.         Serial.print(" m, z: ");
  136.         Serial.print(radar.Dir_z);
  137.         Serial.println(" m");
  138.         Serial.println("----------------------------");
  139.         break;
  140.     }
  141.   }
  142. }

  143. void randomRoving(void){
  144.   leftSonic  = afstandssensor1.afstandCM();
  145.   rightSonic = afstandssensor2.afstandCM();
  146.   Velocity = SLOWVELOCITY;  

  147.   if (leftSonic+ rightSonic < 10 ){
  148.     leftVelocity  = STOPVELOCITY;
  149.     rightVelocity = STOPVELOCITY;
  150.     Velocity = AVGVELOCITY;
  151.     pos=0;
  152.     //directservo.write(pos);
  153.   } // Stop rover

  154.    /****************** Quick Reaction
  155.   if (leftSonic < 20 and  rightSonic < 20){
  156.     leftVelocity  = AVGVELOCITY;
  157.     rightVelocity = STOPVELOCITY;  
  158.     Velocity = SLOWVELOCITY;  
  159.     pos=0;
  160.     //directservo.write(pos);
  161.   } // Turn around rover
  162.   **********************/

  163.     if (leftSonic > 20 and  rightSonic < 20){
  164.     leftVelocity  = STOPVELOCITY;
  165.     rightVelocity = SLOWVELOCITY;
  166.     Velocity = SLOWVELOCITY;  
  167.     pos=LEFTDIRECT;
  168.     //directservo.write(pos);
  169.   } // Turn  rover left

  170.     if (leftSonic < 20 and  rightSonic > 20){
  171.     leftVelocity  = SLOWVELOCITY;
  172.     rightVelocity = STOPVELOCITY;
  173.     Velocity = SLOWVELOCITY;  
  174.     pos=RIGHTDIRECT;
  175.     //directservo.write(pos);
  176.   } // Turn  rover right

  177.   directservo.write(pos);
  178.   delay(1000);  
  179.   tmc5272_rotateMotor(IC_ID, 0, Velocity);
  180.   //tmc5272_rotateMotor(IC_ID, 1, rightVelocity);

  181. }

  182. void humanFollowing(void){
  183.   float radarDirection= 0;
  184.   leftSonic  = afstandssensor1.afstandCM();
  185.   rightSonic = afstandssensor2.afstandCM();
  186.   radar.HumanExis_Func();           //Human existence information output
  187.   if(radar.sensor_report != 0x00){
  188.     switch(radar.sensor_report){
  189.       case NOONE:
  190.         humanDist=0;      
  191.         break;
  192.       case DISVAL:
  193.         Serial.print("The sensor judges the distance to the human body to be: ");
  194.         Serial.print(radar.distance, DEC);        
  195.         humanDist=radar.distance;     
  196.         break;      
  197.         case DIREVAL:
  198.         Serial.print("The sensor judges the orientation data with the human body as -- x: ");
  199.         Serial.print(radar.Dir_x);
  200.         Serial.print(" m, y: ");
  201.         Serial.print(radar.Dir_y);
  202.         Serial.print(" m, z: ");
  203.         Serial.print(radar.Dir_z);
  204.         Serial.println(" m");
  205.         Serial.println("----------------------------");
  206.         radarDirection= radar.Dir_y;
  207.         break;
  208.     }
  209.   }
  210.   if (leftSonic+ rightSonic < 10 ){
  211.     leftVelocity  = STOPVELOCITY;
  212.     rightVelocity = STOPVELOCITY;
  213.   } // Stop rover

  214.   if (leftSonic < 20 and  rightSonic < 20){
  215.     leftVelocity  = AVGVELOCITY;
  216.     rightVelocity = STOPVELOCITY;
  217.   } // Turn around rover

  218.     if (leftSonic > 20 and  rightSonic < 20){
  219.     leftVelocity  = STOPVELOCITY;
  220.     rightVelocity = SLOWVELOCITY;
  221.   } // Turn  rover left

  222.     if (leftSonic < 20 and  rightSonic > 20){
  223.     leftVelocity  = SLOWVELOCITY;
  224.     rightVelocity = STOPVELOCITY;
  225.   } // Turn  rover right

  226.   if (leftSonic > 20 and  rightSonic > 20){   
  227.     leftVelocity  = AVGVELOCITY;
  228.     rightVelocity = AVGVELOCITY;
  229.     if (radarDirection > 0.5 ){
  230.       leftVelocity = leftVelocity + SLOWVELOCITY;
  231.     }
  232.     if (radarDirection < - 0.5 ){
  233.       rightVelocity = rightVelocity + SLOWVELOCITY;
  234.     }
  235.   } // Turn  rover right

  236.   tmc5272_rotateMotor(IC_ID, 0, Velocity);
  237.   tmc5272_rotateMotor(IC_ID, 1, rightVelocity);
  238.   delay(1000);
  239.   
  240. }

  241. void setup() {
  242.   Serial.begin(115200);
  243.   
  244.   Serial1.begin(115200);

  245.   // put your setup code here, to run once:
  246.   pinMode(PIN_SPI_SS, OUTPUT);
  247.   pinMode(nSleep, OUTPUT);
  248.   pinMode(iRefR2, OUTPUT);
  249.   pinMode(iRefR3, OUTPUT);
  250.   pinMode(uartMode, OUTPUT);

  251.   digitalWrite(PIN_SPI_SS, HIGH);
  252.   digitalWrite(nSleep, LOW); // Disabling standby
  253.   digitalWrite(iRefR2, LOW);
  254.   digitalWrite(iRefR3, LOW);

  255.   if (activeBus == IC_BUS_SPI) {
  256.     digitalWrite(uartMode, LOW);

  257.     SPI.begin();
  258.     SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE3));
  259.   } else if (activeBus == IC_BUS_UART) {
  260.     digitalWrite(uartMode, HIGH);
  261.     //Serial3.begin(115200);
  262.     pinMode(PIN_SPI_MOSI, OUTPUT);
  263.     pinMode(PIN_SPI_SCK, OUTPUT);
  264.     digitalWrite(PIN_SPI_MOSI, LOW);
  265.     digitalWrite(PIN_SPI_SS, LOW);
  266.     digitalWrite(PIN_SPI_SCK, LOW);
  267.   }

  268.   pinMode(2, INPUT_PULLUP); //Get Human Detection from MCXN947
  269.   directservo.attach(3);
  270.   delay(10);

  271.   //digitalWrite(iRefR2, HIGH);
  272.   //digitalWrite(iRefR3, HIGH);
  273.   Serial.println(afstandssensor1.afstandCM());
  274.   Serial.println(afstandssensor2.afstandCM());

  275.   initAllMotors(IC_ID);
  276.   tmc5272_rotateMotor(IC_ID, 0, AVGVELOCITY);
  277.   //tmc5272_rotateMotor(IC_ID, 1, AVGVELOCITY);
  278. }

  279. void loop() {
  280.   int32_t value = tmc5272_readRegister(IC_ID, TMC5272_VMAX(0));
  281.   Serial.print("Received Data: ");  Serial.println(value);
  282.   delay(200);
  283.   randomRoving();
  284.   //humanFollowing();
  285.   //STOP if HUMAN detected
  286.   if ( digitalRead(2)==HIGH ) {
  287.     tmc5272_rotateMotor(IC_ID, 0, 0x00000000);
  288.   }

  289.   
  290. }
复制代码

5.6 示范运行效果见视频。编译通过截图

分享到:
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条