コード例 #1
0
        /// <summary>
        /// Transform generic state to this instance.
        /// </summary>
        /// <param name="genericState"></param>
        public void CopyFromGenericState(pxdrive.DriveDifferentialTwoWheelState genericState)
        {
            if (genericState.DistanceBetweenWheels > 0.0)
            {
                this.DistanceBetweenWheels = genericState.DistanceBetweenWheels;
            }

            this.TimeStamp = genericState.TimeStamp;

            if (genericState.LeftWheel != null)
            {
                if (genericState.LeftWheel.Radius > 0.0)
                {
                    this.LeftWheel.WheelDiameter = genericState.LeftWheel.Radius * 2.0;
                }

                if (genericState.LeftWheel.MotorState != null)
                {
                    if (this.RuntimeStatistics == null)
                    {
                        this.RuntimeStatistics = new RuntimeStatistics();
                    }
                    this.RuntimeStatistics.LeftPowerCurrent = genericState.LeftWheel.MotorState.CurrentPower;
                    this.LeftWheel.ReversePolarity          = genericState.LeftWheel.MotorState.ReversePolarity;
                    if (genericState.LeftWheel.MotorState.HardwareIdentifier > 0 && genericState.LeftWheel.MotorState.HardwareIdentifier <= 3)
                    {
                        if (genericState.LeftWheel.MotorState.HardwareIdentifier > 0 && genericState.LeftWheel.MotorState.HardwareIdentifier <= 3)
                        {
                            this.LeftWheel.MotorPort = NxtDrive.HardwareIdentifierToMotorPort(genericState.LeftWheel.MotorState.HardwareIdentifier, this.LeftWheel.MotorPort);
                        }
                    }
                }
            }

            if (genericState.RightWheel != null)
            {
                if (genericState.RightWheel.Radius > 0.0)
                {
                    this.RightWheel.WheelDiameter = genericState.RightWheel.Radius * 2.0;
                }

                if (genericState.RightWheel.MotorState != null)
                {
                    if (this.RuntimeStatistics == null)
                    {
                        this.RuntimeStatistics = new RuntimeStatistics();
                    }
                    this.RuntimeStatistics.RightPowerCurrent = genericState.RightWheel.MotorState.CurrentPower;
                    this.RightWheel.ReversePolarity          = genericState.RightWheel.MotorState.ReversePolarity;
                    if (genericState.RightWheel.MotorState.HardwareIdentifier > 0)
                    {
                        if (genericState.RightWheel.MotorState.HardwareIdentifier > 0 && genericState.RightWheel.MotorState.HardwareIdentifier <= 3)
                        {
                            this.RightWheel.MotorPort = NxtDrive.HardwareIdentifierToMotorPort(genericState.RightWheel.MotorState.HardwareIdentifier, this.RightWheel.MotorPort);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Clone RuntimeStatistics
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            RuntimeStatistics clone = new RuntimeStatistics();

            clone.LeftPowerCurrent      = this.LeftPowerCurrent;
            clone.RightPowerCurrent     = this.RightPowerCurrent;
            clone.LeftEncoderCurrent    = this.LeftEncoderCurrent;
            clone.RightEncoderCurrent   = this.RightEncoderCurrent;
            clone.LeftEncoderTimeStamp  = this.LeftEncoderTimeStamp;
            clone.RightEncoderTimeStamp = this.RightEncoderTimeStamp;
            clone.LeftEncoderTarget     = this.LeftEncoderTarget;
            clone.RightEncoderTarget    = this.RightEncoderTarget;
            clone.LeftPowerTarget       = this.LeftPowerTarget;
            clone.RightPowerTarget      = this.RightPowerTarget;
            clone.LeftMotorRpm          = this.LeftMotorRpm;
            clone.RightMotorRpm         = this.RightMotorRpm;
            clone.TargetStopState       = this.TargetStopState;
            return(clone);
        }