Exemple #1
0
        void CameraVehicle_MotorSpeedChanged(object sender, MotorSpeedChangedEventArgs e)
        {
            backgroundImage = null;

            Dispatcher.Invoke(() =>
            {
                currentTimeTextBlock.Text     = e.Tick.ToString();
                leftWheelSpeedTextBlock.Text  = e.LeftSpeed.ToString("f2");
                rightWheelSpeedTextBlock.Text = e.RightSpeed.ToString("f2");
            });

            if (saveToFileCheckBox.IsChecked.GetValueOrDefault(false) && saveToFileCheckBox.IsEnabled)
            {
                actionList.Add(e);
            }

            if (e.LeftSpeed == 0 && e.RightSpeed == 0 && lastMotorEvent != null)
            {
                if (lastMotorEvent.LeftSpeed == lastMotorEvent.RightSpeed)
                {
                    double distance = (e.Tick - lastMotorEvent.Tick) / 1000 * lastMotorEvent.LeftSpeed;
                    //vehicle.Forward(distance);

                    MapWindow w = GetMapWindow();
                    w.startingVehicleState = vehicle.State;
                    w.Draw();
                }
            }

            lastMotorEvent = e;
        }
        protected virtual void OnMotorSpeedChanged(MotorSpeedChangedEventArgs e)
        {
            var handler = MotorSpeedChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #3
0
        private void MoveStateChanged()
        {
            double leftSpeed, rightSpeed;

            GetRearWheelSpeeds(SteeringAngle, MidSpeed, out leftSpeed, out rightSpeed);

            MotorSpeedChangedEventArgs e = new MotorSpeedChangedEventArgs
            {
                Tick       = DateTime.UtcNow.GetUnixTimestamp(),
                LeftSpeed  = leftSpeed,
                RightSpeed = rightSpeed
            };


            Debug.WriteLine("调用线程:" + System.Threading.Thread.CurrentThread.GetHashCode());

            leftMotor.On((sbyte)-CalculateMotorPower(leftSpeed));
            rightMotor.On((sbyte)-CalculateMotorPower(rightSpeed));

            base.OnMotorSpeedChanged(e);
        }