Exemple #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);
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Copy state to generic state.
        /// </summary>
        /// <param name="genericState"></param>
        public pxdrive.DriveDifferentialTwoWheelState CopyToGenericState(pxdrive.DriveDifferentialTwoWheelState genericState)
        {
            genericState.DistanceBetweenWheels = this.DistanceBetweenWheels;
            genericState.IsEnabled             = this.LeftWheel.MotorPort != NxtMotorPort.NotConnected && this.RightWheel.MotorPort != NxtMotorPort.NotConnected;
            genericState.TimeStamp             = this.TimeStamp;

            if (genericState.LeftWheel == null)
            {
                genericState.LeftWheel = new pxmotor.WheeledMotorState();
            }
            if (genericState.LeftWheel.MotorState == null)
            {
                genericState.LeftWheel.MotorState = new pxmotor.MotorState();
            }
            genericState.LeftWheel.MotorState.CurrentPower       = this.RuntimeStatistics.LeftPowerCurrent;
            genericState.LeftWheel.MotorState.HardwareIdentifier = NxtDrive.MotorPortToHardwareIdentifier(this.LeftWheel.MotorPort);
            genericState.LeftWheel.MotorState.PowerScalingFactor = 100.0;
            genericState.LeftWheel.MotorState.ReversePolarity    = this.LeftWheel.ReversePolarity;
            genericState.LeftWheel.Radius = this.LeftWheel.WheelDiameter / 2.0;

            if (genericState.RightWheel == null)
            {
                genericState.RightWheel = new pxmotor.WheeledMotorState();
            }
            if (genericState.RightWheel.MotorState == null)
            {
                genericState.RightWheel.MotorState = new pxmotor.MotorState();
            }
            genericState.RightWheel.MotorState.CurrentPower       = this.RuntimeStatistics.RightPowerCurrent;
            genericState.RightWheel.MotorState.HardwareIdentifier = NxtDrive.MotorPortToHardwareIdentifier(this.RightWheel.MotorPort);
            genericState.RightWheel.MotorState.PowerScalingFactor = 100.0;
            genericState.RightWheel.MotorState.ReversePolarity    = this.RightWheel.ReversePolarity;
            genericState.RightWheel.Radius = this.RightWheel.WheelDiameter / 2.0;

            return(genericState);
        }