Exemple #1
0
        public Robot()
        {
            _controller = new MotorHat2348();

            _leftMotor = _controller.CreateDCMotor(1);
            _leftMotor.SetSpeed(60);

            _rightMotor = _controller.CreateDCMotor(2);
            _rightMotor.SetSpeed(60);
        }
Exemple #2
0
        /// <summary>
        /// Creates a <see cref="PwmDCMotor"/>  object for the specified channel and adds it to the list of Motors.
        /// </summary>
        /// <param name="driverChannel">A motor driver channel from 1 to 4.</param>
        /// <returns>The created DCMotor object.</returns>
        /// <remarks>
        /// The driverChannel parameter refers to the motor driver channels M1, M2, M3 or M4.
        /// </remarks>
        public PwmDCMotor CreateDCMotor(byte driverChannel)
        {
            PwmDCMotor value;
            var        actualDriverChannel = driverChannel - 1;

            if ((driverChannel < 1) || (driverChannel > 4))
            {
                throw new InvalidOperationException("CreateDCMotor parameter 'driverChannel' must be between 1 and 4.");
            }
            if (motorChannelsUsed[actualDriverChannel] == true)
            {
                throw new MotorHatException(string.Format("Channel {0} aleady in assigned.", driverChannel));
            }
            EnsureInitialized();

            value = new PwmDCMotor(this._pwm, (byte)actualDriverChannel);
            motorChannelsUsed[actualDriverChannel] = true;
            motors.Add(value);

            return(value);
        }