Ejemplo n.º 1
0
        /// <summary>
        /// <para>SETOUTPUTSTATE</para>
        /// </summary>
        /// <remarks>
        /// <para>Reference: BDK, Appendix 2, p. 6.</para>
        /// </remarks>
        /// <param name="motorPort">Motor port</param>
        /// <param name="power">Power set point</param>
        /// <param name="mode">Mode</param>
        /// <param name="regulationMode">Regulation mode</param>
        /// <param name="turnRatio">Turn ratio</param>
        /// <param name="runState">Run state</param>
        /// <param name="tachoLimit">Tacho limit, 0: run forever</param>
        public void SetOutputState(NxtMotorPort motorPort, sbyte power, NxtMotorMode mode, NxtMotorRegulationMode regulationMode, sbyte turnRatio, NxtMotorRunState runState, UInt32 tachoLimit)
        {
            if (power < -100)
            {
                power = -100;
            }
            if (power > 100)
            {
                power = 100;
            }

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

            byte[] request = new byte[12];
            request[0] = (byte)(ReplyRequired ? 0x00 : 0x80);
            request[1] = (byte)NxtCommand.SetOutputState;
            request[2] = (byte)motorPort;
            request[3] = (byte)power;
            request[4] = (byte)mode;
            request[5] = (byte)regulationMode;
            request[6] = (byte)turnRatio;
            request[7] = (byte)runState;
            Util.SetUInt32(tachoLimit, request, 8);

            Send(request);
        }
        /// <summary>
        /// <para>SETOUTPUTSTATE</para>
        /// </summary>
        /// <remarks>
        /// <para>Reference: BDK, Appendix 2, p. 6.</para>
        /// </remarks>
        /// <param name="motorPort">Motor port</param>
        /// <param name="power">Power set point</param>
        /// <param name="mode">Mode</param>
        /// <param name="regulationMode">Regulation mode</param>
        /// <param name="turnRatio">Turn ratio</param>
        /// <param name="runState">Run state</param>
        /// <param name="tachoLimit">Tacho limit, 0: run forever</param>
        public void SetOutputState(NxtMotorPort motorPort, sbyte power, NxtMotorMode mode, NxtMotorRegulationMode regulationMode, sbyte turnRatio, NxtMotorRunState runState, UInt32 tachoLimit)
        {
            if (power < -100) power = -100;
            if (power > 100) power = 100;

            if (turnRatio < -100) turnRatio = -100;
            if (turnRatio > 100) turnRatio = 100;

            byte[] request = new byte[12];
            request[0] = (byte)(ReplyRequired ? 0x00 : 0x80);
            request[1] = (byte)NxtCommand.SetOutputState;
            request[2] = (byte)motorPort;
            request[3] = (byte)power;
            request[4] = (byte)mode;
            request[5] = (byte)regulationMode;
            request[6] = (byte)turnRatio;
            request[7] = (byte)runState;
            Util.SetUInt32(tachoLimit, request, 8);

            Send(request);
        }