コード例 #1
0
        public void PlotSpeed()
        {
            int cnt = 0;

            foreach (var it in speedChart.Series)
            {
                it.Points.Clear();
            }
            SpeedPackage[] buf;

            Thread.BeginCriticalRegion();
            buf = new SpeedPackage[packMgr.SpeedBuf.Count];
            packMgr.SpeedBuf.CopyTo(buf);
            Thread.EndCriticalRegion();

            foreach (SpeedPackage it in buf)
            {
                //if (it.SpeedL > -128 && it.SpeedL < 128)
                speedChart.Series[0].Points.AddXY(cnt, it.SpeedL);
                //if (it.SpeedR > -128 && it.SpeedR < 128)
                speedChart.Series[1].Points.AddXY(cnt, it.SpeedR);
                speedChart.Series[2].Points.AddXY(cnt, it.DutyL);
                speedChart.Series[3].Points.AddXY(cnt, it.DutyR);
                ++cnt;
            }
        }
コード例 #2
0
        private void AnalysePackages(MainForm owner)
        { // 解析当前帧,判定是那个数据包
            SpeedPackage speed    = new SpeedPackage();
            SteerPackage steering = new SteerPackage();
            DeepPackage  deep     = new DeepPackage();

            switch (rxBuffer[0])
            {
            case 0x8a:     // 方向
                steering.DecodePayload(rxBuffer);
                SteerBuf.Add(steering);
                break;

            case 0x8b:     // 速度
                speed.DecodePayload(rxBuffer);
                if (SpeedBuf.Count > 999)
                {
                    SpeedBuf.RemoveAt(0);
                }
                SpeedBuf.Add(speed);
                owner.BeginInvoke(new MethodInvoker(() =>
                {
                    owner.lblSpeedL.Text = "左轮速度:" + speed.SpeedL.ToString() + " cm/s";
                    owner.lblSpeedR.Text = "右轮速度:" + speed.SpeedR.ToString() + " cm/s";
                }));
                break;

            case 0x8c:     // AI
                deep.DecodePayload(rxBuffer);
                MagBuf.Add(deep);
                break;

            case 0x8d:     // 开关
                owner.BeginInvoke(new MethodInvoker(() =>
                {
                    for (int i = 0; i < 8; ++i)
                    {
                        owner.checkedListBox.SetItemChecked(i, (rxBuffer[1] & (1 << i)) > 0);
                    }
                }));
                break;

            case 0x8e:     // 电磁
                break;

            case 0x8f:     // 日志
                string str   = Encoding.UTF8.GetString(rxBuffer, 2, bufTop - 3);
                Color  color = Color.Black;
                switch (rxBuffer[1])
                {
                case 1: color = Color.Red; break;

                case 2: color = Color.Green; break;

                case 3: color = Color.Blue; break;
                }
                owner.BeginInvoke(new MethodInvoker(() =>
                {
                    owner.richLogBox.SelectionColor = color;
                    owner.richLogBox.AppendText(str);
                }));
                break;

            default: break;
            }
        }