/// <summary> /// Sets the frequency and duty cycle of the <see cref="PWMOutput"/> interface and starts the PWM signal. /// </summary> /// <param name="frequency">Required frequency in Hertz.</param> /// <param name="dutyCycle">Duty cycle from 0-1.</param> public void Set(int frequency, double dutyCycle) { if (frequency < 0) { throw new ArgumentException("frequency"); } if (dutyCycle < 0 || dutyCycle > 1) { throw new ArgumentException("dutyCycle"); } if (pwm == null) { pwm = new PWM(pwmChannel, frequency, dutyCycle, invert); pwm.Start(); started = true; } else { if (started) { pwm.Stop(); } pwm.Frequency = frequency; pwm.DutyCycle = dutyCycle; pwm.Start(); started = true; } }
public bool Set(float percentVBus) { if (controller != null) { if (percentVBus > 1) { percentVBus = 1; } else if (percentVBus < -1) { percentVBus = -1; } //Centers duration around the neutral setpoint (1500) with a range +/- 500. //Also inverts the direction if necessary. duration = (uint)((m_isInverted * percentVBus * 500) + 1500); controller.Duration = duration; if (CTRE.Watchdog.IsEnabled()) { controller.Start(); //attempt to re-enable if back-end has disabled it } return(true); } return(false); }
private void SetSpeed(PWM motor, OutputPort direction, int speed, bool isLeft) { motor.Stop(); motor.Frequency = MOTOR_BASE_FREQUENCY; if (speed == 0) { direction.Write(false); motor.DutyCycle = 0.01; } else if (speed < 0) { direction.Write(isLeft ? true : false); motor.DutyCycle = speed / -100.0; motor.Start(); } else { direction.Write(isLeft ? false : true); motor.DutyCycle = speed / 100.0; motor.Start(); } }
/// <summary> /// Plays a Note. /// </summary> /// <param name="note"></param> public static void PlayNote(Note note) { Stop(); _pwm.Frequency = (double)note; _pwm.Start(); _started = true; }
public void go_clockwise_one_tick() { servo.Duration = (uint)1300; servo.Start(); Thread.Sleep(20); servo.Stop(); Thread.Sleep(200); _rightTicksTaken++; // Debug.Print("Right ticks taken " + _rightTicksTaken); // Debug.Print("Total Tick count: " + get_ticks()); }
/// <summary> /// Play a frequency for a specified duration /// </summary> /// <param name="frequency">The frequency in hertz of the tone to be played</param> /// <param name="duration">How long the note is played in milliseconds, if durration is 0, tone plays indefinitely</param> public void PlayTone(float frequency, int duration = 0) { if (frequency <= 0) { throw new System.Exception("frequency must be greater than 0"); } if (!_isPlaying) { _isPlaying = true; var period = (uint)(1000000 / frequency); _pwm.Period = period; _pwm.Duration = period / 2; _pwm.Start(); if (duration > 0) { Thread.Sleep(duration); _pwm.Stop(); } _isPlaying = false; } }
public static void Main() { SLH.AnalogInput pot = new SLH.AnalogInput(Pins.GPIO_PIN_A1); PWM redLed = new PWM(PWMChannels.PWM_PIN_D11, 100, 0, false); PWM greenLed = new PWM(PWMChannels.PWM_PIN_D10, 100, 0, false); PWM blueLed = new PWM(PWMChannels.PWM_PIN_D9, 100, 0, false); double dutyCycleMax = .3; // RGB Led doesn't seem to get much brighter than at 30% int hue = 0; // set our range to be the range of possible hues pot.SetRange(0, 360); redLed.Start(); greenLed.Start(); blueLed.Start(); while (true) { double r, g, b; hue = pot.Read(); Debug.Print("Hue: " + hue.ToString()); HsvToRgb(hue, 1, 1, out r, out g, out b); redLed.DutyCycle = (r * dutyCycleMax); greenLed.DutyCycle = (g * dutyCycleMax); blueLed.DutyCycle = (b * dutyCycleMax); } }
public static void Rick() { PWM myPWM = new PWM(FEZSpiderII.Socket11.Pwm9, frequence, 0.5, false); myPWM.Start(); myPWM.Frequency = Fa; Thread.Sleep(750); myPWM.Frequency = Sol; Thread.Sleep(750); myPWM.Frequency = Do; Thread.Sleep(500); myPWM.Frequency = Sol; Thread.Sleep(750); myPWM.Frequency = La; Thread.Sleep(750); myPWM.Frequency = Do1; Thread.Sleep(180); myPWM.Frequency = Sib; Thread.Sleep(180); myPWM.Frequency = La; Thread.Sleep(300); myPWM.Frequency = Fa; Thread.Sleep(750); myPWM.Frequency = Sol; Thread.Sleep(750); myPWM.Frequency = Do; Thread.Sleep(1000); myPWM.Stop(); }
public static void Main() { PWM redLed = new PWM(PWMChannels.PWM_PIN_D11, 100, 0, false); PWM greenLed = new PWM(PWMChannels.PWM_PIN_D10, 100, 0, false); PWM blueLed = new PWM(PWMChannels.PWM_PIN_D9, 100, 0, false); double dutyCycleMax = .3; // RGB Led doesn't seem to get much brighter than at 30% while (true) { redLed.Start(); greenLed.Start(); blueLed.Start(); double r, g, b; for (int i = 0; i < 360; i++) { HsvToRgb(i, 1, 1, out r, out g, out b); redLed.DutyCycle = (r * dutyCycleMax); greenLed.DutyCycle = (g * dutyCycleMax); blueLed.DutyCycle = (b * dutyCycleMax); // for a fun, fast rotation through the hue spectrum: //Thread.Sleep (1); // for a gentle walk through the forest of colors; Thread.Sleep(18); } } }
/// <summary> /// Piezo speaker driver and notes and playback manager /// </summary> /// <param name="pin">From the SecretLabs.NETMF.Hardware.NetduinoPlus.PWMChannels namespace</param> /// <param name="name">Unique identifying name for command and control</param> public Piezo(Cpu.PWMChannel pin, string name) : base(name, "piezo") { //_piezo = new PWM(pin, 2048, 0, PWM.ScaleFactor.Milliseconds, false); _piezo = new PWM(pin, 2048, 0, false); _piezo.Start(); }
public PwmSpeaker(PWM pwm) { _pwm = pwm; _pwm.Frequency = 50; _pwm.DutyCycle = 0; _pwm.Start(); }
/// <summary> /// Sets the speed at which the DC Motor rotates. /// </summary> /// <param name="speed">A value between -1 and 1.</param> public static void SetSpeed(double speed) { if ((speed > 1 | speed < -1)) { throw new ArgumentOutOfRangeException("speed", "speed must be between -1 and 1."); } if ((speed == 1.0)) { speed = 0.99; } if ((speed == -1.0)) { speed = -0.99; } if ((_started)) { _pwm.Stop(); } _pwm.DutyCycle = speed; _pwm.Start(); _started = true; }
public static void Main() { const uint period = 20000; //20ms in us const uint minDuration = 530; //0.53ms in us const uint maxDuration = 2350; //2.35ms in us var servo = new PWM(Cpu.PWMChannel.PWM_0, period, minDuration, PWM.ScaleFactor.Microseconds, false); servo.Start(); uint step = 30; for (uint angle = 0;; angle += step) { if (angle > 180) { step = (uint)-step; continue; } servo.Duration = Map(angle, 0, 180, minDuration, maxDuration); Thread.Sleep(2000); } }
public void Motors(double left, double right) { leftFrontMotor.DutyCycle = left; leftBackMotor.DutyCycle = left; rightFrontMotor.DutyCycle = right; rightBackMotor.DutyCycle = right; //if (button.Read()) //{ // if (check == false) // { leftFrontMotor.Start(); leftBackMotor.Start(); rightFrontMotor.Start(); rightBackMotor.Start(); // check = true; //} // else // { // leftFrontMotor.Stop(); // leftBackMotor.Stop(); // rightFrontMotor.Stop(); // rightBackMotor.Stop(); // check = false; // } // } }
public static void Main() { // write your code here flex.Start(); serial.DataReceived += serial_DataReceived; serial.Open(); Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Starts the Sero Motor. /// </summary> public static void Reactivate() { if (!_started) { _pwm.Start(); _started = true; } }
public static void Forward(int s, bool r) { if (r == true && (s <= 255))// || (s > 0)) { leftDir.Write(true); rightDir.Write(true); leftPWM.DutyCycle = (s / 255); rightPWM.DutyCycle = (s / 255); leftPWM.Start(); rightPWM.Start(); } else { Halt(); } }
public static void Main() { while (true) { myPWM.Start(); myPWM2.Start(); Thread.Sleep(-1); } }
void UpdateMotors(float motorLeftValue, float motorRightValue) { motorPwmLeft.Stop(); motorPwmRight.Stop(); motorPwmLeft.DutyCycle = motorLeftValue; motorPwmRight.DutyCycle = motorRightValue; motorPwmLeft.Start(); motorPwmRight.Start(); }
public static void Main() { #region debug debugLed = new OutputPort(device.DebugLed, false); debugBtn = new InputPort(device.Socket6.Pin3, false, Port.ResistorMode.Disabled); ifDebug = false; currentDebugBtnValue = false; oldDebugBtnValue = false; #endregion // Initialisation des entrées capteurFrontal = new AnalogInput(device.Socket9.AnalogInput3); capteurGauche = new AnalogInput(device.Socket9.AnalogInput4); capteurDroite = new AnalogInput(device.Socket9.AnalogInput5); // Initialisation des sorties roueDroite = new PWM(device.Socket11.Pwm7, 2500, (int)VITESSE_MAX_D, PWM.ScaleFactor.Microseconds, false); roueGauche = new PWM(device.Socket11.Pwm8, 2500, (int)VITESSE_MAX_G, PWM.ScaleFactor.Microseconds, false); // Démarrage des roues roueGauche.Start(); roueDroite.Start(); while (true) { #region debug /* * currentDebugBtnValue = debugBtn.Read(); * if (currentDebugBtnValue == false && oldDebugBtnValue == true) * { * roueGauche.Duration++; * } * * oldDebugBtnValue = currentDebugBtnValue; */ #endregion // Calcul de la vitesse en fonction des données des capteurs //double vitesseG = -((((capteurFrontal.Read() - 0.5) * 2.0) -0.5)- (capteurGauche.Read() - capteurDroite.Read())) / 2 * VMAX; //double vitesseD = ((((capteurFrontal.Read() - 0.5) * 2.0) -0.5)+ (capteurGauche.Read() - capteurDroite.Read())) / 2 * VMAX; double vitesseG = -(((capteurFrontal.Read() - 0.5) * 2.0) - 0.5) * VMAX; double vitesseD = (((capteurFrontal.Read() - 0.5) * 2.0) - 0.5) * VMAX; // Régulation des vitesses des roues roueGauche.Duration = (uint)(VITESSE_MAX_G + vitesseG); roueDroite.Duration = (uint)(VITESSE_MAX_D + vitesseD); #region debug (affichage des données) //Debug.Print("Capteurs : " + capteurDroite.Read() + " || " + capteurFrontal.Read() + " || " + capteurGauche.Read()); Debug.Print("Moteurs : " + roueDroite.Duration.ToString() + " || " + roueGauche.Duration.ToString()); #endregion } }
public void Forward(int s) { if (RobotState.IsEnabled() && (s <= 255))// || (s > 0)) { _leftDir.Write(true); _rightDir.Write(true); _leftPWM.DutyCycle = (s / 255); _rightPWM.DutyCycle = (s / 255); _leftPWM.Start(); _rightPWM.Start(); } else { Halt(); } }
void InitializeOutputs() { // base duty will start at 0.0, i.e. magnitude 0, polarity true (forwards) speedControl.DutyCycle = 0.5; speedControl.Frequency = pwmFrequency; speedControl.DutyCycle = 0.0; speedControl.Start(); outputShiftRegister.WriteTransaction(forwardTransaction); }
/// <summary> /// Moves the motor in the specified direction. /// </summary> /// <param name="direction">The direction : forward or backward.</param> /// <param name="speed">The speed, from 0.0 to 1.0 (100%)</param> /// <param name="rampTime">The ramp time if needed, in milliseconds. It's the time that will be taken to start from speed 0.0 to "Speed".</param> /// <example> /// <code language="C#"> /// // Moves the motor forward with a ramptime to full speed of 2 sec /// _motor.Move(DCMotorClick.Directions.Forward, 1.0, 2000); /// </code> /// </example> public void Move(Directions direction, Double speed = 1.0, Int32 rampTime = 0) { if (IsMoving) { _pwmOut.Stop(); Thread.Sleep(200); } _select2.Write(direction == Directions.Backward); if (rampTime == 0) { _pwmOut.DutyCycle = speed; IsMoving = true; _pwmOut.Start(); } else { _rampIncrement = (Int32)(speed / 0.05); _rampWaitTime = (Int32)(rampTime * 0.05 / speed); IsMoving = true; new Thread(RampUp).Start(); } }
static void TestPWM2() { // PWM.ScaleFactor.Microseconds(1000000)/10=100kHz var pwm0 = new PWM(Cpu.PWMChannel.PWM_0, 10, 5, PWM.ScaleFactor.Microseconds, false); var pwm1 = new PWM(Cpu.PWMChannel.PWM_3, 20, 10, PWM.ScaleFactor.Microseconds, false); pwm0.Start(); pwm1.Start(); //while (true) Thread.Sleep(100); }
/// <summary> /// To be called after setting the properties of the object. /// If not called explicitly, it is automatically called when /// the actuator is used for the first time. /// Preconditions /// Actuator is not open /// Channel is set /// Period is set /// if MinValue or MaxValue is set: MinValue lessThan MaxValue /// Postconditions /// Actuator is open /// </summary> public void Open() { Contract.Requires(port == null); // actuator is not open Contract.Requires(Channel >= 0); Contract.Requires(Period > 0); Contract.Requires(MinValue < MaxValue); minValue = MinValue; maxValue = MaxValue; port = new PWM((Cpu.PWMChannel)Channel, (uint)Period, 0, PWM.ScaleFactor.Microseconds, false); port.Start(); }
private void SetTone(Tone tone) { _buzzPwm.Stop(); if (Math.Abs(tone.Freq) < Double.Epsilon) { return; } _buzzPwm.Frequency = ((int)tone.Freq); _buzzPwm.DutyCycle = 0.5; _buzzPwm.Start(); }
private void Initialise() { _range = _maxPosition - _minPosition; degreesRatio = (float)_range / (float)_maxDegrees; _servoMotor = new PWM(_pin, 100, 0.5, false); _servoMotor.DutyCycle = 0; _servoMotor.Duration = _minPosition; _servoMotor.Start(); //give the servo enough time to swing to _minPosition Util.Delay(250); }
void ConfigurePwm(Cpu.PWMChannel channel) { var frequencyHz = 1000 / refreshCycleMilliseconds; var periodMicroseconds = refreshCycleMilliseconds * 1000; var durationMicroseconds = midpoint; var pwm = new PWM(channel, frequencyHz, 0.0, false); pwm.Period = periodMicroseconds; pwm.Duration = durationMicroseconds; pwm.Start(); this.pwm = pwm; }
public void Play(int freq_Hz, int duration_mSec) { myPWM.Stop(); if (freq_Hz != 0) { myPWM.Frequency = freq_Hz; myPWM.Start(); } Thread.Sleep(duration_mSec); myPWM.Stop(); Thread.Sleep(tempo / 2); }
private void ThrowAllarm() { camera.StopStreaming(); throw_allarm = true; StopAllarm = false; timer_getimage.Stop(); Thread.Sleep(500); camera.StopStreaming(); buzzer.Start(); timer_allarm = new GT.Timer(300); timer_allarm.Tick += allarm_Tick; timer_allarm.Start(); }