Example #1
0
        protected H.OutputPort _enablePort = null; // if enabled, then IsNeutral = false


        public HBridgeMotor(H.Cpu.PWMChannel a1Pin, H.Cpu.PWMChannel a2Pin, H.Cpu.Pin enablePin, float pwmFrequency = 1600)
        {
            this._pwmFrequency = pwmFrequency;
            // create our PWM outputs
            this._motorLeftPwm = new H.PWM(a1Pin, _pwmFrequency, 0, false);
            this._motorRighPwm = new H.PWM(a2Pin, _pwmFrequency, 0, false);
            this._enablePort   = new H.OutputPort(enablePin, false);
        }
Example #2
0
        public static HBridgeMotor CreateForNetduino(Microsoft.SPOT.Hardware.Cpu.PWMChannel enable, Microsoft.SPOT.Hardware.Cpu.Pin a1, Microsoft.SPOT.Hardware.Cpu.Pin a2)
        {
            var leftPwm   = new Robotics.Micro.Devices.PwmOutputPin(enable);
            var leftMotor = new HBridgeMotor(leftPwm);

            leftMotor.A1Output.ConnectTo(new Robotics.Micro.Devices.DigitalOutputPin(a1).Input);
            leftMotor.A2Output.ConnectTo(new Robotics.Micro.Devices.DigitalOutputPin(a2).Input);
            return(leftMotor);
        }
Example #3
0
        /// <summary>
        /// Creates a new PwmLed on the specified PWM pin and limited to the appropriate
        /// voltage based on the passed `forwardVoltage`. Typical LED forward voltages
        /// can be found in the `TypicalForwardVoltage` class.
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="forwardVoltage"></param>
        public PwmLed(H.Cpu.PWMChannel pin, float forwardVoltage)
        {
            // validate and persist forward voltage
            if (forwardVoltage < 0 || forwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("forwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            this.ForwardVoltage = forwardVoltage;

            this._maximumPwmDuty = Helpers.CalculateMaximumDutyCycle(forwardVoltage);

            this._pwm = new H.PWM(pin, 100, this._maximumPwmDuty, false);
        }
        public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Hardware.Cpu.PWMChannel channel)
        {
            if (channel == Hardware.Cpu.PWMChannel.PWM_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM");
            }

            _channel = channel;
            _socket  = socket;
            _invert  = invert;
        }
Example #5
0
        public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Hardware.Cpu.PWMChannel channel)
        {
            if (channel == Hardware.Cpu.PWMChannel.PWM_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM");
            }

            _channel = channel;
            _socket = socket;
            _invert = invert;
        }
        public PwmOutputPin(Microsoft.SPOT.Hardware.Cpu.PWMChannel channel, double frequencyHz = 1000, double dutyCycle = 0)
        {
            pwm = new PWM(channel, frequencyHz, dutyCycle, false);

            DutyCycleInput = AddInput("DutyCycleInput", Units.Ratio, dutyCycle);
            FrequencyInput = AddInput("FrequencyInput", Units.Frequency, frequencyHz);

            DutyCycleInput.ValueChanged += (s, e) => {
                pwm.DutyCycle = DutyCycleInput.Value;
            };

            FrequencyInput.ValueChanged += (s, e) => {
                pwm.Frequency = FrequencyInput.Value;
            };

            pwm.Start();
        }
        /// <summary>
        ///
        /// Implementation notes: Architecturally, it would be much cleaner to construct this class
        /// as three PwmLeds. Then each one's implementation would be self-contained. However, that
        /// would require three additional threads during ON; one contained by each PwmLed. For this
        /// reason, I'm basically duplicating the functionality for all three in here.
        /// </summary>
        /// <param name="redPin"></param>
        /// <param name="greenPin"></param>
        /// <param name="bluePin"></param>
        /// <param name="isCommonCathode"></param>
        public RgbPwmLed(
            H.Cpu.PWMChannel redPin, H.Cpu.PWMChannel greenPin, H.Cpu.PWMChannel bluePin,
            float redLedForwardVoltage   = TypicalForwardVoltage.ResistorLimited,
            float greenLedForwardVoltage = TypicalForwardVoltage.ResistorLimited,
            float blueLedForwardVoltage  = TypicalForwardVoltage.ResistorLimited,
            bool isCommonCathode         = true)
        {
            // validate and persist forward voltages
            if (redLedForwardVoltage < 0 || redLedForwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("redLedForwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            RedForwardVoltage = redLedForwardVoltage;
            if (greenLedForwardVoltage < 0 || greenLedForwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("greenLedForwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            GreenForwardVoltage = greenLedForwardVoltage;
            if (blueLedForwardVoltage < 0 || blueLedForwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("blueLedForwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            BlueForwardVoltage = blueLedForwardVoltage;
            // calculate and set maximum PWM duty cycles
            _maximumRedPwmDuty   = Helpers.CalculateMaximumDutyCycle(RedForwardVoltage);
            _maximumGreenPwmDuty = Helpers.CalculateMaximumDutyCycle(GreenForwardVoltage);
            _maximumBluePwmDuty  = Helpers.CalculateMaximumDutyCycle(BlueForwardVoltage);

            IsCommonCathode = isCommonCathode;
            RedPin          = redPin;
            GreenPin        = greenPin;
            BluePin         = bluePin;

            RedPwm   = new H.PWM(RedPin, 100, 0, false);
            GreenPwm = new H.PWM(GreenPin, 100, 0, false);
            BluePwm  = new H.PWM(BluePin, 100, 0, false);
        }
Example #8
0
 /// <summary>
 /// Instantiates a new Servo on the specified PWM Pin with the specified config.
 /// </summary>
 /// <param name="pin"></param>
 /// <param name="config"></param>
 public ServoBase(H.Cpu.PWMChannel pin, ServoConfig config)
 {
     _config = config;
     _pwm    = new H.PWM(pin, config.Frequency, 0, false);
 }
        public StepperMotorController(CTRE.Phoenix.CANifier CANifier, CTRE.Phoenix.CANifier.GeneralPin directionPin, Microsoft.SPOT.Hardware.Cpu.PWMChannel movePin, uint maxSpeed,
                                      CTRE.Phoenix.CANifier.GeneralPin forwardLimitSwitchPin, CTRE.Phoenix.CANifier.GeneralPin reverseLimitSwitchPin)
        {
            lastDirection = Direction.STOPPED;

            this.maxSpeed = maxSpeed;

            this.directionPort      = directionPin;
            this.forwardLimitSwitch = forwardLimitSwitchPin;
            this.reverseLimitSwitch = reverseLimitSwitchPin;
            this.CANifier           = CANifier;

            movePort = new PWM(movePin, maxSpeed, maxSpeed / 2, PWM.ScaleFactor.Microseconds, false);
        }
 /// <summary>
 /// Instantiates a new continuous rotation servo on the specified pin, with the specified configuration.
 /// </summary>
 /// <param name="pin"></param>
 /// <param name="config"></param>
 public ContinuousRotationServo(H.Cpu.PWMChannel pin, ServoConfig config) : base(pin, config)
 {
 }