|
@@ -20,9 +20,14 @@ namespace Test
|
|
|
{
|
|
|
private SickTimEnc laserLeft;
|
|
|
private SickTimEnc laserRight;
|
|
|
- private int max_axis_Y = 4000;//2250;//画图时Y轴最大量程
|
|
|
+ private int max_axis_Y = 2600;//2250;//画图时Y轴最大量程
|
|
|
private List<DispMsg> dataDispList;
|
|
|
private List<string> colors;//雷达数据颜色
|
|
|
+ private bool obstacleDetected;
|
|
|
+ private const string leftTrue = "left: True ";
|
|
|
+ private const string leftFalse = "left: False ";
|
|
|
+ private const string rightTrue = "right: True ";
|
|
|
+ private const string rightFalse = "right: False ";
|
|
|
//************** plc相关参数 *************
|
|
|
/// <summary>
|
|
|
/// PLC 连接状态flag
|
|
@@ -31,7 +36,7 @@ namespace Test
|
|
|
/// <summary>
|
|
|
/// plc中cpu类型
|
|
|
/// </summary>
|
|
|
- private const CpuType cpu = CpuType.S71200;
|
|
|
+ private const CpuType cpu = CpuType.S71500;
|
|
|
/// <summary>
|
|
|
/// PLC的IP地址
|
|
|
/// </summary>
|
|
@@ -63,7 +68,7 @@ namespace Test
|
|
|
/// <summary>
|
|
|
/// 读写锁
|
|
|
/// </summary>
|
|
|
- private object readWriteLock = new object();
|
|
|
+ private static object readWriteLock = new object();
|
|
|
//写入频率
|
|
|
private const int writeFreq = 25;
|
|
|
private const short DB = 30;
|
|
@@ -82,15 +87,17 @@ namespace Test
|
|
|
//流程控制
|
|
|
private void Start()
|
|
|
{
|
|
|
+ obstacleDetected = false;
|
|
|
colors = new List<string>();
|
|
|
colors.Add(Color.Red.Name);
|
|
|
colors.Add(Color.Yellow.Name);
|
|
|
colors.Add(Color.Cyan.Name);
|
|
|
colors.Add(Color.Blue.Name);
|
|
|
dataDispList = new List<DispMsg>();
|
|
|
+ //初始化雷达与数据显示
|
|
|
Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- laserLeft = new SickTimEnc("192.168.0.77", 2111);
|
|
|
+ //laserLeft = new SickTimEnc("192.168.0.77", 2111);
|
|
|
laserRight = new SickTimEnc("192.168.0.88", 2111);
|
|
|
while (!IsHandleCreated)
|
|
|
{
|
|
@@ -103,13 +110,13 @@ namespace Test
|
|
|
if (laserLeft != null)
|
|
|
{
|
|
|
Pause();
|
|
|
- laserLeft.SetLeftRange(75);
|
|
|
- laserLeft.SetRightRange(105);
|
|
|
- laserLeft.ground_truth_height = 2600;
|
|
|
+ laserLeft.SetLeftRange(65);
|
|
|
+ laserLeft.SetRightRange(115);
|
|
|
+ laserLeft.ground_truth_height = 4050;
|
|
|
laserLeft.min_num_point_of_hinder = 20;
|
|
|
laserLeft.min_obstacle_height = 100;
|
|
|
- tb_angleLeft.Text = "75";
|
|
|
- tb_angleRight.Text = "105";
|
|
|
+ tb_angleLeft.Text = "65";
|
|
|
+ tb_angleRight.Text = "115";
|
|
|
Pause();
|
|
|
List<List<double>> temp = new List<List<double>>();
|
|
|
temp.Add(laserLeft.yFiltered);
|
|
@@ -121,11 +128,11 @@ namespace Test
|
|
|
Pause();
|
|
|
laserRight.SetLeftRange(75);
|
|
|
laserRight.SetRightRange(105);
|
|
|
- laserRight.ground_truth_height = 2600;
|
|
|
+ laserRight.ground_truth_height = 2200;
|
|
|
laserRight.min_num_point_of_hinder = 20;
|
|
|
laserRight.min_obstacle_height = 100;
|
|
|
tb_angleLeft.Text = "75";
|
|
|
- tb_angleRight.Text = "105";
|
|
|
+ tb_angleRight.Text = "125";
|
|
|
Pause();
|
|
|
List<List<double>> temp = new List<List<double>>();
|
|
|
temp.Add(laserRight.yFiltered);
|
|
@@ -133,24 +140,10 @@ namespace Test
|
|
|
chartAddData(laserRight.listx, temp, 2);
|
|
|
}
|
|
|
}));
|
|
|
- //Task.Factory.StartNew(()=>
|
|
|
- //{
|
|
|
- // int height = 2600;
|
|
|
- // Thread.Sleep(5000);
|
|
|
- // while (height >= 200)
|
|
|
- // {
|
|
|
- // height--;
|
|
|
- // if (laserLeft != null)
|
|
|
- // laserLeft.ground_truth_height = height;
|
|
|
- // if (laserRight != null)
|
|
|
- // laserRight.ground_truth_height = height;
|
|
|
- // Console.WriteLine(height);
|
|
|
- // Thread.Sleep(3);
|
|
|
- // }
|
|
|
- //});
|
|
|
while (!closed)
|
|
|
{
|
|
|
- //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
|
|
+ System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
|
|
+ sw.Start();
|
|
|
try
|
|
|
{
|
|
|
this.Invoke(new Action(() =>
|
|
@@ -165,70 +158,52 @@ namespace Test
|
|
|
{
|
|
|
updateChartData(laserLeft.listx, laserLeft.yFiltered, 0);
|
|
|
updateChartData(laserLeft.listx, laserLeft.yFilteredKalman, 1);
|
|
|
- lb_obstacle.Text = " left:" + laserLeft.obstacleDetected+" ";
|
|
|
+ //lb_obstacle.Text = " left:" + laserLeft.obstacleDetected + " ";
|
|
|
+ lb_obstacle.Text = laserLeft.obstacleDetected ? leftTrue : leftFalse;
|
|
|
+ //lb_obstacle.Text = " left:" + laserLeft.dataCount + " ";
|
|
|
+ obstacleDetected = false || laserLeft.obstacleDetected;
|
|
|
}
|
|
|
- if (dataDispList.Count >= 4 && laserRight != null)
|
|
|
+ if (laserRight != null)
|
|
|
{
|
|
|
- updateChartData(laserRight.listx, laserRight.yFiltered, 2);
|
|
|
- updateChartData(laserRight.listx, laserRight.yFilteredKalman, 3);
|
|
|
- lb_obstacle.Text += "right:" + laserRight.obstacleDetected + " ";
|
|
|
+ updateChartData(laserRight.listx, laserRight.yFiltered, dataDispList.Count >=4 ?2:0);
|
|
|
+ updateChartData(laserRight.listx, laserRight.yFilteredKalman, dataDispList.Count >= 4 ?3:1);
|
|
|
+ //lb_obstacle.Text = (dataDispList.Count >= 4?lb_obstacle.Text:String.Empty)+"right:" + laserRight.obstacleDetected + " ";
|
|
|
+ if (dataDispList.Count >= 4)
|
|
|
+ lb_obstacle.Text += laserRight.obstacleDetected ? rightTrue : rightFalse;
|
|
|
+ else
|
|
|
+ lb_obstacle.Text = laserRight.obstacleDetected ? rightTrue : rightFalse;
|
|
|
+ //lb_obstacle.Text += "right:" + laserRight.dataCount + " ";
|
|
|
+ obstacleDetected = obstacleDetected || laserRight.obstacleDetected;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
catch { Stop(); }
|
|
|
- //sw.Stop();
|
|
|
- //Console.WriteLine(sw.ElapsedMilliseconds + "ms");
|
|
|
+ sw.Stop();
|
|
|
+ Console.WriteLine("laser: " + sw.ElapsedMilliseconds + "ms");
|
|
|
Thread.Sleep(30);
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 暂停雷达数据处理线程
|
|
|
- /// </summary>
|
|
|
- private void Pause()
|
|
|
- {
|
|
|
- if (laserLeft != null)
|
|
|
- {
|
|
|
- laserLeft.Pause();
|
|
|
- }
|
|
|
- if (laserRight != null)
|
|
|
- {
|
|
|
- laserRight.Pause();
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 停止获取雷达数据,断开连接
|
|
|
- /// </summary>
|
|
|
- private void Stop()
|
|
|
- {
|
|
|
- if (laserLeft != null)
|
|
|
- {
|
|
|
- laserLeft.Stop();
|
|
|
- }
|
|
|
- if (laserRight != null)
|
|
|
- {
|
|
|
- laserRight.Stop();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- public obstacleDetectionForm()
|
|
|
- {
|
|
|
- InitializeComponent();
|
|
|
- Start();
|
|
|
- //************* PLC 相关逻辑 *************
|
|
|
+ ////************* PLC 相关逻辑 *************
|
|
|
//bool result = PLCConnect();
|
|
|
//if (!result)
|
|
|
+ //{
|
|
|
+ // Console.WriteLine("PLC连接失败");
|
|
|
// Environment.Exit(0);
|
|
|
+ //}
|
|
|
//else
|
|
|
//{
|
|
|
// MsgNode msg = new MsgNode();
|
|
|
// msg.db = DB;
|
|
|
// msg.length = 2;
|
|
|
- // Task.Factory.StartNew(() => {
|
|
|
+ // Task.Factory.StartNew(() =>
|
|
|
+ // {
|
|
|
// while (!closed)
|
|
|
// {
|
|
|
+ // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
|
|
+ // sw.Start();
|
|
|
// if (plc == null)
|
|
|
// {
|
|
|
// Thread.Sleep(1000);
|
|
@@ -249,29 +224,29 @@ namespace Test
|
|
|
// msg.start = ZPause;
|
|
|
// ReadFromPLC(ref msg);
|
|
|
// ZPauseValue = BitConverter.ToInt16(msg.value.ToArray(), 0);
|
|
|
- // Console.WriteLine("position, start, stop, pause: "+ZPositionValue+", "+ZStartValue+", "+ZStopValue+", "+ZPauseValue);
|
|
|
+ // //Console.WriteLine("position, start, stop, pause: " + ZPositionValue + ", " + ZStartValue + ", " + ZStopValue + ", " + ZPauseValue);
|
|
|
|
|
|
// if (ZPauseValue == 1)
|
|
|
// {
|
|
|
- // Pause(true);
|
|
|
- // Console.WriteLine("暂停");
|
|
|
+ // Pause();
|
|
|
+ // //Console.WriteLine("暂停");
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
- // Pause(false);
|
|
|
+ // Pause();
|
|
|
// //Console.WriteLine("恢复");
|
|
|
// }
|
|
|
|
|
|
// //收到开始下降信号
|
|
|
- // if (ZStartValue == 1 && ZStopValue!=1)
|
|
|
+ // if (ZStartValue == 1 && ZStopValue != 1)
|
|
|
// {
|
|
|
// startGoingDown = true;
|
|
|
- // Console.WriteLine("下降过程");
|
|
|
+ // //Console.WriteLine("下降过程");
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// startGoingDown = false;
|
|
|
- // Console.WriteLine("非下降过程");
|
|
|
+ // //Console.WriteLine("非下降过程");
|
|
|
// }
|
|
|
|
|
|
// //进入下降阶段
|
|
@@ -285,17 +260,64 @@ namespace Test
|
|
|
// }
|
|
|
// }
|
|
|
// //下降结束复位工作状态
|
|
|
- // if(laserWorking && ZStopValue == 1)
|
|
|
+ // if (laserWorking && ZStopValue == 1)
|
|
|
// {
|
|
|
// Console.WriteLine("雷达工作结束");
|
|
|
// laserWorking = false;
|
|
|
// }
|
|
|
|
|
|
- // Thread.Sleep(50);
|
|
|
+ // if (laserWorking)
|
|
|
+ // {
|
|
|
+ // MsgNode writeMsg = new MsgNode();
|
|
|
+ // writeMsg.db = 41;
|
|
|
+ // writeMsg.length = 2;
|
|
|
+ // writeMsg.start = 60;
|
|
|
+ // byte[] temp = { 0, 0 };
|
|
|
+ // if (obstacleDetected)
|
|
|
+ // temp[1] = 1;
|
|
|
+ // WriteToPLC(writeMsg);
|
|
|
+ // }
|
|
|
+ // sw.Stop();
|
|
|
+ // Console.WriteLine("PLC: " + sw.ElapsedMilliseconds + "ms");
|
|
|
+ // Thread.Sleep(1000);
|
|
|
// }
|
|
|
// });
|
|
|
//}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 暂停雷达数据处理线程
|
|
|
+ /// </summary>
|
|
|
+ private void Pause()
|
|
|
+ {
|
|
|
+ if (laserLeft != null)
|
|
|
+ {
|
|
|
+ laserLeft.Pause();
|
|
|
+ }
|
|
|
+ if (laserRight != null)
|
|
|
+ {
|
|
|
+ laserRight.Pause();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 停止获取雷达数据,断开连接
|
|
|
+ /// </summary>
|
|
|
+ private void Stop()
|
|
|
+ {
|
|
|
+ if (laserLeft != null)
|
|
|
+ {
|
|
|
+ laserLeft.Stop();
|
|
|
+ }
|
|
|
+ if (laserRight != null)
|
|
|
+ {
|
|
|
+ laserRight.Stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public obstacleDetectionForm()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Start();
|
|
|
+ }
|
|
|
//界面按钮
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
{
|
|
@@ -350,9 +372,9 @@ namespace Test
|
|
|
this.laserDataChart.ChartAreas[0].AxisY.IsReversed = true;
|
|
|
this.laserDataChart.ChartAreas[0].AxisY.Minimum = 0;
|
|
|
this.laserDataChart.ChartAreas[0].AxisY.Maximum = max_axis_Y;
|
|
|
- this.laserDataChart.ChartAreas[0].AxisY.Interval = 100;
|
|
|
- this.laserDataChart.ChartAreas[0].AxisX.Minimum = -2300;// -200;
|
|
|
- this.laserDataChart.ChartAreas[0].AxisX.Maximum = 2300;// 200;
|
|
|
+ this.laserDataChart.ChartAreas[0].AxisY.Interval = 50;
|
|
|
+ this.laserDataChart.ChartAreas[0].AxisX.Minimum = -2500;// -200;
|
|
|
+ this.laserDataChart.ChartAreas[0].AxisX.Maximum = 2500;// 200;
|
|
|
this.laserDataChart.ChartAreas[0].AxisX.Interval = 100;// 100;
|
|
|
this.laserDataChart.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
|
|
|
this.laserDataChart.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
|