?
?1.所述產(chǎn)品 產(chǎn)品型號:TFmini Plus
相關(guān)資料下載地址:http://www.benewake.com/download
產(chǎn)品名稱:TFmini Plus激光雷達模組
制造商
公司:北醒(北京)光子科技有限公司?
2.產(chǎn)品功能:TFmini Plus是基于TFmini的升級項目,它是一款小型化,單點測距的產(chǎn)品,基于TOF(飛行 時間)原理,配合獨特的光學、電學、算法設(shè)計,主要實現(xiàn)穩(wěn)定、精準、高靈敏度和高速的距離測 量的功能。產(chǎn)品本身除了具有TFmini的低成本、小體積、測距遠等特點外,還增加了IP65等級防 護,測距精度更高,對于室外強光、不同溫度、不同反射率等不同環(huán)境下適應(yīng)性更強,更低功耗, 探測頻率也更加靈活。產(chǎn)品同時兼容UART和I2C通信接口,可通過指令進行切換
3. 串口數(shù)據(jù)通信 TFmini Plus串口數(shù)據(jù)通信,詳見表 66。
? ? ? ? ? ? ? ? ? ? ? 表 6 TFmini Plus數(shù)據(jù)通信協(xié)議——UART?
通信接口 UART 默認波特率 115200 數(shù)據(jù)位 8 停止位 1 奇偶校驗 None
4. 串口數(shù)據(jù)輸出格式及編碼?
TFmini Plus 有兩種數(shù)據(jù)輸出格式,標準數(shù)據(jù)輸出格式和字符串數(shù)據(jù)格式,兩種格式可通過指 令代碼相互切換。??
-。標準數(shù)據(jù)輸出格式(默認) :? 數(shù)據(jù)結(jié)構(gòu):數(shù)據(jù)幀長度為9字節(jié)。包含距離信息(Distance)、信號強度信息(Strength)、溫度 (Temp)、數(shù)據(jù)校驗字節(jié)(Checksum)等。數(shù)據(jù)格式為16進制(HEX)。具體數(shù)據(jù)編碼詳見下表:
?-。字符串數(shù)據(jù)格式(Pix Mode) 以字符串形式輸出,單位為m,比如測距為1.21m,則輸出字符串1.21,后跟轉(zhuǎn)義字符\r\n。此數(shù)據(jù)格式針對Ardupilot固件版本v3.6.2以下。如果您的Ardupilot固件版本大于或等于v3.6.2 可以直接使用標準數(shù)據(jù)格式。
5 輸出數(shù)據(jù)說明
?Dist(Distance):
代表TFmini Plus測量輸出的距離值,默認單位為cm,解析為十進制的值范圍 為0-1200。實際使用過程中,當信號強度值Strength<100或等于65535時,Dist的測量值被認為不 可信,默認輸出0。?
Strength:
指信號強度,默認輸出值會在0-65535之間。當測距檔位一定時,測距越遠,信號 強度越低;目標物反射率越低,信號強度越低。當Strength大于100且不等于65535時,認為Dist 的測量值可信,客戶可以根據(jù)使用場景自行調(diào)整。?
Temp(Temperature):
表征芯片內(nèi)部溫度值。攝氏度 = Temp / 8 - 256
實例說明:開啟四個線程分別接收四路激光測距雷達的數(shù)據(jù)并生成chart波形圖
實例代碼:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace lidarTest
{
public partial class mainForm : DevComponents.DotNetBar.Office2007Form
{
public mainForm()
{
this.DoubleBuffered = true;//設(shè)置本窗體
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 雙緩沖
this.EnableGlass = false;
InitializeComponent();
InitChart();
}
private Queue<double>[] dataQueue = new Queue<double>[4];//把Queue<double>看成一個類型 int[] a=new int [8]
bool isStart = false;
private void mainForm_Load(object sender, EventArgs e)
{
dataQueue[0] = new Queue<double>(100);
dataQueue[1] = new Queue<double>(100);
dataQueue[2] = new Queue<double>(100);
dataQueue[3] = new Queue<double>(100);
//this.WindowState = FormWindowState.Normal;
//this.FormBorderStyle = FormBorderStyle.Sizable;
//this.Top = 0;
//this.Left = 0;
//this.Width = Screen.PrimaryScreen.WorkingArea.Width;
//this.Height = Screen.PrimaryScreen.WorkingArea.Height;
Start();
}
// 防止閃屏
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
public void Start()
{
Thread t1 = new Thread(StartDataRevThread1);
t1.Start();
t1.IsBackground = true;
Thread t2 = new Thread(StartDataRevThread2);
t2.Start();
t2.IsBackground = true;
Thread t3 = new Thread(StartDataRevThread3);
t3.Start();
t3.IsBackground = true;
Thread t4 = new Thread(StartDataRevThread4);
t4.Start();
t4.IsBackground = true;
}
private void StartDataRevThread1()
{
try
{
UdpClient client = new UdpClient(8021);
//IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);//
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.30"), 8008);
//client.Client.ReceiveBufferSize = 40960;//40960 默認值是8192
while (true)
{
Byte[] recv = client.Receive(ref endpoint);
string stringData = "0x" + BitConverter.ToString(recv).Replace("-", " 0x").ToLower();
this.Invoke((EventHandler)delegate
{
//richTextBoxEx1.Text += stringData + "\r\n";
chartShow( recv[2] + (recv[3]<<8),1);
}
);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace) ;
}
}
private void StartDataRevThread2()
{
try
{
UdpClient client = new UdpClient(8022);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.40"), 8008);
while (true)
{
Byte[] recv = client.Receive(ref endpoint);
string stringData = "0x" + BitConverter.ToString(recv).Replace("-", " 0x").ToLower();
this.Invoke((EventHandler)delegate
{
//richTextBoxEx2.Text += stringData + "\r\n";
chartShow(recv[2] + (recv[3] << 8),2);
}
);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
}
}
private void StartDataRevThread3()
{
try
{
UdpClient client = new UdpClient(8023);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.100"), 8008);
while (true)
{
Byte[] recv = client.Receive(ref endpoint);
string stringData = "0x" + BitConverter.ToString(recv).Replace("-", " 0x").ToLower();
this.Invoke((EventHandler)delegate
{
//richTextBoxEx3.Text += stringData + "\r\n";
chartShow( recv[2] + (recv[3] << 8),3);
}
);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
}
}
private void StartDataRevThread4()
{
try
{
UdpClient client = new UdpClient(8024);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.200"), 8008);
while (true)
{
Byte[] recv = client.Receive(ref endpoint);
string stringData = "0x" + BitConverter.ToString(recv).Replace("-", " 0x").ToLower();
this.Invoke((EventHandler)delegate
{
//richTextBoxEx4.Text += stringData + "\r\n";
chartShow( recv[2] + (recv[3] << 8),4);
}
);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
}
}
private void InitChart()
{
Chart[] ch = new Chart[4] { chart1, chart2, chart3, chart4};
for (int i = 0; i < 4; i++)
{
ch[i].ChartAreas.Clear();
ChartArea chartArea1 = new ChartArea("C1");
ch[i].ChartAreas.Add(chartArea1);
//定義存儲和顯示點的容器
ch[i].Series.Clear();
Series series1 = new Series("S1");
series1.ChartArea = "C1";
ch[i].Series.Add(series1);
ch[i].ChartAreas[0].AxisY.IsStartedFromZero = false;
ch[i].Legends[0].Enabled = false;
ch[i].ChartAreas[0].AxisX.Interval = 5;
ch[i].ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
ch[i].ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
//設(shè)置標題
ch[i].Titles.Clear();
ch[i].Titles.Add("S01");
ch[i].Titles[0].Text = "通道" + (i + 1) + " 折線圖顯示";
ch[i].Titles[0].ForeColor = Color.RoyalBlue;
ch[i].Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
//設(shè)置圖表顯示樣式
ch[i].Series[0].Color = Color.Red;
//this.chart1.Titles[0].Text = string.Format("{0}折線圖顯示", );
ch[i].Series[0].ChartType = SeriesChartType.Line;
ch[i].Series[0].Points.Clear();
}
}
public void chartShow(Double y, int ch)
{
Chart[] chNum = new Chart[4] { chart1, chart2, chart3, chart4 };
if (ch <= 8)
chartDisplay(chNum[ch - 1], ch, y);
}
delegate void ChartDelegate(Chart chart, int ch, Double y);
private void chartDisplay(Chart chart, int ch, Double y)
{
if (chart.InvokeRequired)
{
ChartDelegate chartDelegate = chartDisplay;
chart.Invoke(chartDelegate, new object[] { chart, ch, y });
}
else
{
if (isStart == true)
UpdateQueueValue(ch, y);
chart.Series[0].Points.Clear();
for (int i = 0; i < dataQueue[ch - 1].Count; i++)
chart.Series[0].Points.AddXY((i + 1), dataQueue[ch - 1].ElementAt(i));
}
}
private void UpdateQueueValue(int ch, Double y)
{
if (dataQueue[ch - 1].Count > 100)
//先出列
dataQueue[ch - 1].Dequeue();
dataQueue[ch - 1].Enqueue(y);
}
private void btnStart_Click(object sender, EventArgs e)
{
if (!isStart)
{
btnStart.Text = @"停止采集";
btnStart.DisabledImage = btnStart.Image;
btnStart.Image = (Image)btnStart.PressedImage.Clone();
isStart = !isStart;
}
else
{
btnStart.Text = @"開始采集";
btnStart.Image = btnStart.DisabledImage;
isStart = !isStart;
}
}
}
}
運行結(jié)果:
源代碼和激光雷達相關(guān)說明文檔百度網(wǎng)盤下載地址:
鏈接:https://pan.baidu.com/s/1KmIbP1I9Eq90bcFOiYSI6w?
提取碼:ska8?
------------------------------------------------------------------------
文章來源:http://www.zghlxwxcb.cn/news/detail-826055.html
如果這篇文章對你有幫助,就請多多點擊在看,讓更多朋友看到,需要進文章來源地址http://www.zghlxwxcb.cn/news/detail-826055.html
到了這里,關(guān)于C# winfrom實例:四路激光測距雷達數(shù)據(jù)采集和波形圖繪制的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!