生活随笔
收集整理的這篇文章主要介紹了
北醒TF-mini激光雷达实现定位
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
激光雷達定位
一、代碼實現(xiàn)
通過兩個TF-mini激光雷達實現(xiàn)區(qū)域定位(arduino實現(xiàn))
代碼如下:
#include <SoftwareSerial.h> typedef struct {int distance
;int strength
;boolean receiveComplete
;
}TFmini
;TFmini TFminiOne
= {0, 0, false
};
TFmini TFminiTwo
= {0, 0, false
};
SoftwareSerial
portOne(2, 2);
SoftwareSerial
portTwo(3, 3); void getTFminiData(SoftwareSerial
* port
, TFmini
* tfmini
) {port
->listen();while(tfmini
->receiveComplete
== false
) { static char i
= 0;char j
= 0;int checksum
= 0; static int rx
[9];if(port
->available()) { rx
[i
] = port
->read();if(rx
[0] != 0x59) {i
= 0;} else if(i
== 1 && rx
[1] != 0x59) {i
= 0;} else if(i
== 8) {for(j
= 0; j
< 8; j
++) {checksum
+= rx
[j
];}if(rx
[8] == (checksum
% 256)) {tfmini
->distance
= rx
[2] + rx
[3] * 256;tfmini
->strength
= rx
[4] + rx
[5] * 256;tfmini
->receiveComplete
= true
;}i
= 0;} else {i
++;} } }
}void setup() {Serial
.begin(115200);portOne
.begin(115200);portTwo
.begin(115200);
}void loop() {static unsigned long lastTime
= millis();static unsigned int count
= 0;static unsigned int frequency
= 0;getTFminiData(&portOne
, &TFminiOne
);getTFminiData(&portTwo
, &TFminiTwo
);if(TFminiOne
.receiveComplete
== true
&& TFminiTwo
.receiveComplete
== true
) {++count
;if(millis() - lastTime
> 999) {lastTime
= millis();frequency
= count
;count
= 0;} Serial
.print("x=");Serial
.print(TFminiOne
.distance
);Serial
.print("cm\t");Serial
.print(",");Serial
.print("y=");Serial
.print(TFminiTwo
.distance
);Serial
.println("cm");TFminiOne
.receiveComplete
= false
;TFminiTwo
.receiveComplete
= false
;}}
二、接線圖
總結
以上是生活随笔為你收集整理的北醒TF-mini激光雷达实现定位的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。