為了模擬雷達物件的動態偵測, 設計了一個簡易的測試環境.
1. 雷達距離偵測物件 1.5米
2. 偵測物件為金屬扇葉風扇
3. Mega2560 + MCP2515 + 4port relay board + one axis motor driver
4. circuit
測試步驟: C#程式GUI 控制Mega2560驅動單軸前進並利用 MCP2515接收CANBus的資料, 當雷達偵測到物件, 傳送資料到CANBus中, GUI顯示雷達傳送的資料判斷是否在設定範圍決定PASS or FAIL.
先利用之前文章製作的CANHacker來驗證Mega2560+MCP2515的功能
ESP32 + MCP2515 use CanHacker on CAN Bus system
Mega2560 SPI pin define
影片//-----------------Mega2560 MCP2515 code --------------------------------------
mcp_can library mcp_can - Arduino Reference
#include <SPI.h>
#include "mcp_can.h"
//------CAN BUS setting ---------------------------------------------------------
#define CAN0_INT 50 // Set INT to pin 50
const int SPI_CS_PIN = 53;
MCP_CAN myCAN(SPI_CS_PIN);
//------CAN BUS setting end ------------------------------------------------------
void setup()
{
Serial.begin(115200);
//can bus : baudrate = 250k
while (CAN_OK != myCAN.begin(MCP_NORMAL, CAN_250KBPS, MCP_8MHZ))
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == myCAN.checkReceive()) // check if data coming
{
myCAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned char canId = myCAN.getCanId();
Serial.println("-----------------------------------------------------------");
Serial.print("Get data from ID: ");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf, HEX);
Serial.print("\t");
}
Serial.println();
}
}
//------------------------------------------------------------
若有問題歡迎留言討論!!!
//------------------------------------------------------------
測試影片
youtube
沒有留言:
張貼留言