private void goAlongMap()//小车行进执行函数 { List <Line> map = route.map.listLine; double todayTime = (DateTime.Today.ToUniversalTime().Ticks - 621355968000000000) / 10000000; //Unix时间戳计算(基准时间) DateTime file_time = DateTime.Now; string year = file_time.Year.ToString(), month = "", day = "", hour = "", minute = ""; if (file_time.Month < 10) { month = "0" + file_time.Month.ToString(); } if (file_time.Day < 10) { day = "0" + file_time.Day.ToString(); } if (file_time.Hour < 10) { hour = "0" + file_time.Hour.ToString(); } if (file_time.Minute < 10) { minute = "0" + file_time.Minute.ToString(); } string file_name = "../../road_sign/" + year + month + day + hour + minute + ".txt"; /////摄像头//// //new CameraControl().cameraLeading(dr_port, con_port); dr_port.clearData(); for (int i = 0; i < map.Count; ++i) { //showPosition(); string str = ""; if (map[i].num != 0)//开始时间 { if (map[i].num < 10) { str += '0'; } str += map[i].num.ToString(); str += ' '; double epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 - todayTime; str += epoch.ToString(); } c_point = map[i].startpoint; Redraw_Panel(route.map); if (!map[i].startpoint.direc || !map[i].endpoint.direc) { if (i == 0) { dr_port.clearData(); } if (map[i].startpoint.direc && map[i].endpoint.direc) { DrPort.distance.Sx = map[i].startpoint.x; DrPort.distance.Sy = map[i].startpoint.y; DrPort.distance.Sw = map[i].startpoint.w; } goWithPP2(map[i].startpoint, map[i].endpoint, con_port, dr_port, urg_port); //goWithPP(map[i].startpoint, map[i].endpoint, con_port, dr_port, urg_port); } else { // setSpeed int setSpeed = 50; goWithRadar(map[i].startpoint, map[i].endpoint, con_port, dr_port, urg_port, setSpeed); } if (map[i].num != 0)//结束时间 { str += ' '; double epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 - todayTime; str += epoch.ToString(); FileStream syxstream = new FileStream(file_name, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(syxstream); sw.WriteLine(str); sw.Close(); } // showPosition(); } }
private void Collect_Route1_Click(object sender, EventArgs e) { if (Collect_Route1.Text == "获取路径信息") { Urg_Point.Visible = true; Com_Point.Visible = true; Delete_Point.Visible = true; groupBox1.Visible = true; xml_con.read(); string portName = ""; string portBaudrate = ""; switch (xml_con.data[4]) { case 0: portName = "COM1"; break; case 1: portName = "COM2"; break; case 2: portName = "COM3"; break; case 3: portName = "COM4"; break; case 4: portName = "COM5"; break; case 5: portName = "COM6"; break; case 6: portName = "COM7"; break; case 7: portName = "COM8"; break; case 8: portName = "COM9"; break; case 9: portName = "COM10"; break; } switch (xml_con.data[5]) { case 0: portBaudrate = "9600"; break; case 1: portBaudrate = "115200"; break; } if (dr_port.OpenPort(portName, portBaudrate) == false) { MessageBox.Show("编码器串口未能打开,请配置串口!"); return; } Collect_Route1.Text = "初始位置校准"; route.map.listLine.Clear(); route.map.listPoint.Clear(); route.map.listFixedRect.Clear(); dr_port.clearData(); } else if (Collect_Route1.Text == "初始位置校准") { string portName = ""; string portBaudrate = ""; switch (xml_con.data[2]) { case 0: portName = "COM1"; break; case 1: portName = "COM2"; break; case 2: portName = "COM3"; break; case 3: portName = "COM4"; break; case 4: portName = "COM5"; break; case 5: portName = "COM6"; break; case 6: portName = "COM7"; break; case 7: portName = "COM8"; break; case 8: portName = "COM9"; break; case 9: portName = "COM10"; break; } switch (xml_con.data[3]) { case 0: portBaudrate = "9600"; break; case 1: portBaudrate = "115200"; break; } if (con_port.OpenPort(portName, portBaudrate) == false) { MessageBox.Show("控制串口未能打开,请配置串口!"); return; } //new CameraControl().cameraLeading(dr_port, con_port); Collect_Route1.Text = "结束路径信息"; route.map.listLine.Clear(); route.map.listPoint.Clear(); route.map.listFixedRect.Clear(); dr_port.clearData(); } else { route.map.listLine.Clear(); for (int i = 0; i < route.map.listPoint.Count() - 1; i++) { Line r_line = new Line(); r_line.startpoint = route.map.listPoint[i]; r_line.endpoint = route.map.listPoint[i + 1]; route.map.listLine.Add(r_line); } dr_port.ClosePort(); con_port.ClosePort(); Collect_Route1.Text = "获取路径信息"; Redraw_Panel1(route.map); } }