Example #1
0
        /// <summary>
        /// 再生する
        /// </summary>
        public void play()
        {
            int count = dataGridView.Rows.Count;
            uint wait = 0;
            for(int ii = 0; ii < count; ii++)
            {
                LogData logData = new LogData();
                logData.SysTick = ConvUtil.toUInt32(dataGridView.Rows[ii].Cells[0].Value);
                logData.MotorCnt1 = ConvUtil.toInt32(dataGridView.Rows[ii].Cells[5].Value);
                logData.MotorCnt2 = ConvUtil.toInt32(dataGridView.Rows[ii].Cells[6].Value);

                gpsUpdateDelegate.Invoke(logData);
                currentRow++;

                // 再生スピード制御(Tickの差分だけWait)
                // 初回は4ms固定とする
                wait = logData.SysTick - saveTick;
                if (wait == logData.SysTick || logData.SysTick == 0)
                {
                    wait = 4;
                }

                saveTick = logData.SysTick;
                System.Threading.Thread.Sleep((int)(wait / speed));
            }
        }
Example #2
0
        /// <summary>
        /// 取得したログをGrid、Chartに出力する
        /// </summary>
        /// <param name="logData"></param>
        private void bufferingLog(LogData logData)
        {
            DataGridViewRow row = new DataGridViewRow();

            row.CreateCells(dataGridView);
            row.Cells[0].Value = logData.RelTick;
            row.Cells[1].Value = logData.DataLeft;
            row.Cells[2].Value = logData.DataRight;
            row.Cells[3].Value = logData.Light;
            row.Cells[4].Value = logData.MotorCnt0;
            row.Cells[5].Value = logData.MotorCnt1;
            row.Cells[6].Value = logData.MotorCnt2;
            row.Cells[7].Value = logData.SensorAdc0;
            row.Cells[8].Value = logData.SensorAdc1;
            row.Cells[9].Value = logData.SensorAdc2;
            row.Cells[10].Value = logData.SensorAdc3;
            row.Cells[11].Value = logData.I2c;

            logBufferList.Add(row);

            if (stopwatch4Grid.ElapsedMilliseconds > 1000 || logBufferList.Count > 100)
            {
                outputGrid();
                stopwatch4Grid.Restart();
                logBufferList.Clear();
            }
        }
        /// <summary>
        /// 1行分のログデータから現在位置を演算し、位置を再表示する
        /// </summary>
        /// <param name="logData"></param>
        private void movePoint(LogData logData)
        {
            Position pos = gps.getPosition(logData.MotorCnt2, logData.MotorCnt1);
            Position currentNxtPoint = convScaleAndMuki(pos.X, pos.Y);

            Graphics graphics = panelCourse.CreateGraphics();
            Rectangle rectangle = new Rectangle(
                 Convert.ToInt32(currentNxtPoint.X),
                 Convert.ToInt32(currentNxtPoint.Y), 1, 1);
            graphics.DrawRectangle(Pens.Red, rectangle);

            redrawStripLine(logData.SysTick);
        }
 /// <summary>
 /// 1行分のログデータから走行位置を演算する
 /// </summary>
 /// <param name="logData"></param>
 private void gpsUpdate(LogData logData)
 {
     MovePointDelegate movePointDelegate = new MovePointDelegate(movePoint);
     this.BeginInvoke(movePointDelegate, logData);
 }
Example #5
0
        /// <summary>
        /// 本体部読み込み
        /// </summary>
        /// <param name="data"></param>
        private void readBody(Byte data)
        {
            packetBody[currentBytePos++ - PACKET_HEADER_LENGTH] = data;

            // 1パケット分に達していない場合は次の受信待ち
            if (currentBytePos != PACKET_LENGTH)
            {
                return;
            }

            LogData logData = new LogData();

            // パケットをフィールドに変換
            logData.SysTick = BitConverter.ToUInt32(packetBody, 0);
            logData.DataLeft = (SByte)packetBody[4];
            logData.DataRight = (SByte)packetBody[5];
            logData.Light = BitConverter.ToUInt16(packetBody, 6);
            logData.MotorCnt0 = BitConverter.ToInt32(packetBody, 8);
            logData.MotorCnt1 = BitConverter.ToInt32(packetBody, 12);
            logData.MotorCnt2 = BitConverter.ToInt32(packetBody, 16);
            logData.SensorAdc0 = BitConverter.ToInt16(packetBody, 20);
            logData.SensorAdc1 = BitConverter.ToInt16(packetBody, 22);
            logData.SensorAdc2 = BitConverter.ToInt16(packetBody, 24);
            logData.SensorAdc3 = BitConverter.ToInt16(packetBody, 26);
            logData.I2c = BitConverter.ToInt32(packetBody, 28);
            logData.RelTick = getTick(logData.SysTick);

            // データ受信を通知
            this.logReceiveDelegate.Invoke(logData);

            // 全部読み終わったので、読み込み位置を先頭に戻す
            currentBytePos = 0;
        }
Example #6
0
 /// <summary>
 /// 取得したログをGrid、Chartに出力する
 /// </summary>
 /// <param name="logData"></param>
 private void receiveLog(LogData logData)
 {
     // SerialからはControl部品の操作はできないので、Formで再度Invoke
     LogReceiveDelegate bufferingLogDelegate = new LogReceiveDelegate(bufferingLog);
     this.BeginInvoke(bufferingLogDelegate, logData);
 }