Exemplo n.º 1
0
        /// <summary> Sends a command to run the motor at a given <c>Power</c> in a given <c>Direction</c>.
        ///   The minimum speed is 0 and the maximum speed is 100. </summary>
        /// <param name="Direction"> The direction to run the motor. </param>
        /// <param name="Power"> The power to run the motor with. </param>
        /// <returns> If the method completed with success the returning value is
        ///   <see cref="wclErrors.WCL_E_SUCCESS" />. If the method failed the returning value is
        ///   one of the Bluetooth Framework error code. </returns>
        /// <seealso cref="wclWeDoMotorDirection"/>
        public Int32 Run(wclWeDoMotorDirection Direction, Byte Power)
        {
            if (Direction == wclWeDoMotorDirection.mdUnknown || Power > 100)
            {
                return(wclErrors.WCL_E_INVALID_ARGUMENT);
            }

            if (!Attached)
            {
                return(wclBluetoothErrors.WCL_E_BLUETOOTH_DEVICE_NOT_INSTALLED);
            }

            if (Direction == wclWeDoMotorDirection.mdDrifting || Power == 0)
            {
                return(Drift());
            }
            if (Direction == wclWeDoMotorDirection.mdBraking)
            {
                return(Brake());
            }

            Int32 Res = SendPower(ConvertUnsignedMotorPowerToSigned(Direction, Power));

            if (Res == wclErrors.WCL_E_SUCCESS)
            {
                FDirection = Direction;
            }
            return(Res);
        }
Exemplo n.º 2
0
        private SByte ConvertUnsignedMotorPowerToSigned(wclWeDoMotorDirection Direction, Byte Power)
        {
            SByte Res = (SByte)Math.Min(Math.Max(Power, MOTOR_MIN_SPEED), MOTOR_MAX_SPEED);

            if (Direction == wclWeDoMotorDirection.mdLeft)
            {
                Res = (SByte)(-Res);
            }
            return(Res);
        }
Exemplo n.º 3
0
        /// <summary> Sends a command to stop (drift/float) the motor. </summary>
        /// <returns> If the method completed with success the returning value is
        ///   <see cref="wclErrors.WCL_E_SUCCESS" />. If the method failed the returning value is
        ///   one of the Bluetooth Framework error code. </returns>
        public Int32 Drift()
        {
            if (!Attached)
            {
                return(wclBluetoothErrors.WCL_E_BLUETOOTH_DEVICE_NOT_INSTALLED);
            }

            Int32 Res = SendPower(MOTOR_POWER_DRIFT);

            if (Res == wclErrors.WCL_E_SUCCESS)
            {
                FDirection = wclWeDoMotorDirection.mdDrifting;
            }
            return(Res);
        }
Exemplo n.º 4
0
 /// <summary> Creates new motor class object. </summary>
 /// <param name="Hub"> The Hub object that owns the device. If this parameter is <c>null</c>
 ///   the <seealso cref="wclEInvalidArgument"/> exception raises. </param>
 /// <param name="ConnectionId"> The device's Connection ID. </param>
 /// <seealso cref="wclWeDoHub"/>
 /// <exception cref="wclEInvalidArgument"> The exception raises when the <c>Hub</c>
 ///   parameter is <c>null</c>. </exception>
 public wclWeDoMotor(wclWeDoHub Hub, Byte ConnectionId)
     : base(Hub, ConnectionId)
 {
     FDirection = wclWeDoMotorDirection.mdBraking;
     FPower     = 0;
 }