Ejemplo n.º 1
0
        /// <summary>
        /// <para>Run the motors (in sync).</para>
        /// </summary>
        /// <param name="power">The poser</param>
        /// <param name="tachoLimit">The tacho limit in degrees, 0 means unlimited</param>
        /// <param name="turnRatio">Turn ratio is not upported by MotorControl and is ignored</param>
        public override void Run(sbyte power, ushort tachoLimit, sbyte turnRatio)
        {
            MotorControlMotorPort motorControlPort;

            if (motorX.Port == NxtMotorPort.PortA && motorY.Port == NxtMotorPort.PortB)
            {
                motorControlPort = MotorControlMotorPort.PortsAB;
            }
            else if (motorX.Port == NxtMotorPort.PortA && motorY.Port == NxtMotorPort.PortC)
            {
                motorControlPort = MotorControlMotorPort.PortsAC;
            }
            else if (motorX.Port == NxtMotorPort.PortB && motorY.Port == NxtMotorPort.PortC)
            {
                motorControlPort = MotorControlMotorPort.PortsBC;
            }
            else
            {
                throw new NxtException("Unknown port combination of ports.");
            }

            // Translate power to MotorControl-format.

            if (power > 100)
            {
                power = 100;
            }
            if (power < -100)
            {
                power = -100;
            }

            int powerTmp = power;

            if (powerTmp < 0)
            {
                powerTmp = 100 - powerTmp;
            }

            char mode = '7';

            MotorControlProxy.CONTROLLED_MOTORCMD(
                this.motorX.Brick.CommLink,
                motorControlPort,
                powerTmp.ToString().PadLeft(3, '0'),
                tachoLimit.ToString().PadLeft(6, '0'),
                mode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Run the motor.</para>
        /// </summary>
        /// <param name="power">The power for the motor</param>
        /// <param name="tachoLimit">The duration in degrees, 0 = unlimited</param>
        public override void Run(sbyte power, uint tachoLimit)
        {
            // Translate motor-port to MotorControl-format.

            MotorControlMotorPort portMotorControl;

            switch (Port)
            {
            case NxtMotorPort.PortA:
                portMotorControl = MotorControlMotorPort.PortA;
                break;

            case NxtMotorPort.PortB:
                portMotorControl = MotorControlMotorPort.PortB;
                break;

            case NxtMotorPort.PortC:
                portMotorControl = MotorControlMotorPort.PortC;
                break;

            default:
                throw new NxtException("Unknown port.");
            }

            // Translate power to MotorControl-format.

            if (power > 100)
            {
                power = 100;
            }
            if (power < -100)
            {
                power = -100;
            }

            int powerTemp = power;

            if (powerTemp < 0)
            {
                powerTemp = 100 - powerTemp;
            }

            string powerMotorControl = powerTemp.ToString().PadLeft(3, '0');

            // Translate tachoLimit to MotorControl-format.

            string tachoLimitMotorControl = tachoLimit.ToString().PadLeft(6, '0');

            // Call MotorControl.

            if (tachoLimit != 0)
            {
                char mode = '7';
                MotorControlProxy.CONTROLLED_MOTORCMD(this.Brick.CommLink, portMotorControl, powerMotorControl, tachoLimitMotorControl, mode);
            }
            else
            {
                char speedRegulation = '1';
                MotorControlProxy.CLASSIC_MOTORCMD(this.Brick.CommLink, portMotorControl, powerMotorControl, tachoLimitMotorControl, speedRegulation);
            }
        }