public MeadowApp() { var led = new RgbLed( Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue); led.SetColor(RgbLed.Colors.Red); up = new PwmLed(Device, Device.Pins.D13, TypicalForwardVoltage.Red); down = new PwmLed(Device, Device.Pins.D10, TypicalForwardVoltage.Red); left = new PwmLed(Device, Device.Pins.D11, TypicalForwardVoltage.Red); right = new PwmLed(Device, Device.Pins.D12, TypicalForwardVoltage.Red); up.IsOn = down.IsOn = left.IsOn = right.IsOn = false; var motorLeft = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D05), a2Pin: Device.CreatePwmPort(Device.Pins.D06), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D07) ); var motorRight = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D02), a2Pin: Device.CreatePwmPort(Device.Pins.D03), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D04) ); carController = new CarController(motorLeft, motorRight); led.SetColor(RgbLed.Colors.Green); TestCar(); }
public static void Run() { var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); var robot = new TwoWheeledRobot(leftMotor, rightMotor); new SineWave(0.1, 0.5, 0.5, updateFrequency: 9).Output.ConnectTo(robot.SpeedInput); new SineWave(0.5, 0.333, 0, updateFrequency: 11).Output.ConnectTo(robot.DirectionInput); }
public TachometerApp() { this._motor = new HBridgeMotor(N.PWMChannels.PWM_PIN_D3, N.PWMChannels.PWM_PIN_D5, N.Pins.GPIO_PIN_D4, 50); this._tach = new LinearHallEffectTachometer(N.Pins.GPIO_PIN_D2); this._lcd = new SerialLCD(new TextDisplayConfig() { Width = 16, Height = 2 }); this._tach.RPMsChanged += RPMsChanged; }
void InitializePeripherals() { ledRed = new Led(N.Pins.GPIO_PIN_D13); ledGreen = new Led(N.Pins.GPIO_PIN_D12); ledBlue = new Led(N.Pins.GPIO_PIN_D11); motorLeft = new HBridgeMotor(N.PWMChannels.PWM_PIN_D3, N.PWMChannels.PWM_PIN_D5, N.Pins.GPIO_PIN_D4); motorRight = new HBridgeMotor(N.PWMChannels.PWM_PIN_D6, N.PWMChannels.PWM_PIN_D10, N.Pins.GPIO_PIN_D7); carController = new CarController(motorLeft, motorRight); ledRed.StartBlink(); }
public MeadowApp() { Console.WriteLine("Initializing..."); motor1 = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D07), a2Pin: Device.CreatePwmPort(Device.Pins.D08), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D09) ); TestMotor(); }
public static void Main() { // // Controls server // // initialize the serial port for COM1 (using D0 & D1) // initialize the serial port for COM3 (using D7 & D8) var serialPort = new SerialPort(SerialPorts.COM3, 57600, Parity.None, 8, StopBits.One); serialPort.Open(); var server = new ControlServer(serialPort); // // Just some diagnostic stuff // var uptimeVar = server.RegisterVariable("Uptime (s)", 0); var lv = false; var led = new Microsoft.SPOT.Hardware.OutputPort(Pins.ONBOARD_LED, lv); // // Make the robot // var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); var robot = new TwoWheeledRobot(leftMotor, rightMotor); // // Expose some variables to control it // robot.SpeedInput.ConnectTo(server, writeable: true, name: "Speed"); robot.DirectionInput.ConnectTo(server, writeable: true, name: "Turn"); leftMotor.SpeedInput.ConnectTo(server); rightMotor.SpeedInput.ConnectTo(server); // // Show diagnostics // for (var i = 0; true; i++) { uptimeVar.Value = i; led.Write(lv); lv = !lv; Thread.Sleep(1000); } }
void Initialize() { led = new RgbLed( Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue); led.SetColor(RgbLed.Colors.Red); ledUp = new PwmLed(Device, Device.Pins.D13, TypicalForwardVoltage.Red); ledDown = new PwmLed(Device, Device.Pins.D10, TypicalForwardVoltage.Red); ledLeft = new PwmLed(Device, Device.Pins.D11, TypicalForwardVoltage.Red); ledRight = new PwmLed(Device, Device.Pins.D12, TypicalForwardVoltage.Red); ledUp.IsOn = ledDown.IsOn = ledLeft.IsOn = ledRight.IsOn = true; var motorLeft = new HBridgeMotor ( device: Device, a1Pin: Device.Pins.D05, a2Pin: Device.Pins.D06, enablePin: Device.Pins.D07 ); var motorRight = new HBridgeMotor ( device: Device, a1Pin: Device.Pins.D02, a2Pin: Device.Pins.D03, enablePin: Device.Pins.D04 ); carController = new CarController(motorLeft, motorRight); led.SetColor(RgbLed.Colors.Blue); bleTreeDefinition = GetDefinition(); Device.BluetoothAdapter.StartBluetoothServer(bleTreeDefinition); up.ValueSet += UpValueSet; down.ValueSet += DownValueSet; left.ValueSet += LeftValueSet; right.ValueSet += RightValueSet; led.SetColor(RgbLed.Colors.Green); }
public static void Main() { var motor1 = new HBridgeMotor(N.PWMChannels.PWM_PIN_D3, N.PWMChannels.PWM_PIN_D5, N.Pins.GPIO_PIN_D4); var motor2 = new HBridgeMotor(N.PWMChannels.PWM_PIN_D6, N.PWMChannels.PWM_PIN_D10, N.Pins.GPIO_PIN_D7); while (true) { // set the speed on both motors to 100% forward motor1.Speed = 1f; motor2.Speed = 1f; Thread.Sleep(1000); motor1.Speed = 0f; motor2.Speed = 0f; Thread.Sleep(500); // 100% reverse motor1.Speed = -1f; motor2.Speed = -1f; Thread.Sleep(1000); } }
public static void Main6() { //Create our "Blocks" var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); leftMotor.CalibrationInput.Value = 1; rightMotor.CalibrationInput.Value = 1; var awesomeBlock = new AwesomeBlock(Pins.ONBOARD_BTN, Pins.ONBOARD_LED, leftMotor, rightMotor); int i = 0; while (true) { Thread.Sleep(1000); // sleep for 1000ms Debug.Print("Looping" + i); i++; } }
public MeadowApp() { //this.commandButton = new PushButton(Device, Device.Pins.D10, debounceDuration: 50); //this.commandButton.Clicked += this.CommandButton_Button_Clicked; ////this.commandButton.PressEnded += CommandButton_PressEnded; //this.debounceTimer.Elapsed += DebounceTimer_Elapsed; var motorLeft = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D05), a2Pin: Device.CreatePwmPort(Device.Pins.D06), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D07) ); var motorRight = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D02), a2Pin: Device.CreatePwmPort(Device.Pins.D03), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D04) ); carController = new CarController(motorLeft, motorRight); this.commands[0] = this.Back; this.commands[1] = this.Right; this.commands[2] = this.Forward; this.commands[3] = this.Left; this.commands[4] = this.Stop; this.serialPort = Device.CreateSerialMessagePort(Device.SerialPortNames.Com1, suffixDelimiter: Encoding.UTF8.GetBytes("\r\n"), preserveDelimiter: true, baudRate: 115200); this.serialPort.Open(); this.serialPort.MessageReceived += SerialPort_MessageReceived; //Console.WriteLine("Serial port " + this.serialPort.PortName + " is " + (this.serialPort.IsOpen ? "open" : "closed")); this.serialPort.Write(Encoding.UTF8.GetBytes("serial port is open\r\n")); this.UpdateOnboardLed("red"); Thread.Sleep(Timeout.Infinite); }
public static void Main6() { //Create our "Blocks" var button = new DigitalInputPin(Pins.ONBOARD_BTN); var led = new DigitalOutputPin(Pins.ONBOARD_LED); var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); leftMotor.CalibrationInput.Value = 1; var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); rightMotor.CalibrationInput.Value = 1; button.Output.ConnectTo(led.Input); button.Output.ConnectTo(rightMotor.SpeedInput); button.Output.ConnectTo(leftMotor.SpeedInput); Thread.Sleep(Timeout.Infinite); }
void Initialize() { var onboardLed = new RgbPwmLed( device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue); onboardLed.SetColor(Color.Red); motor = new HBridgeMotor ( device: Device, a1Pin: Device.Pins.D05, a2Pin: Device.Pins.D06, enablePin: Device.Pins.D09 ); motor.Power = 0f; rotary = new RotaryEncoder(Device, Device.Pins.D02, Device.Pins.D03); rotary.Rotated += RotaryRotated; onboardLed.SetColor(Color.Green); }
public CarController(HBridgeMotor motorLeft, HBridgeMotor motorRight) { _motorLeft = motorLeft; _motorRight = motorRight; }
public CarController(HBridgeMotor motorLeft, HBridgeMotor motorRight) { this.motorLeft = motorLeft; this.motorRight = motorRight; }
public static void Run() { // // Start with the basic robot // var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); var robot = new TwoWheeledRobot(leftMotor, rightMotor); // // Create a range finder and scope it // var scope = new DebugScope(); var a0 = new AnalogInputPin(AnalogChannels.ANALOG_PIN_A0, 10); scope.ConnectTo(a0.Analog); var sharp = new SharpGP2D12(); a0.Analog.ConnectTo(sharp.AnalogInput); scope.ConnectTo(sharp.DistanceOutput); scope.ConnectTo(robot.SpeedInput); // // This is the cruising (unobstructed) speed // var distanceToSpeed = new Transform(distance => { const double min = 0.1; const double max = 0.5; if (distance > max) { return(1.0); } else if (distance < min) { return(0.0); } return((distance - min) / (max - min)); }); distanceToSpeed.Input.ConnectTo(sharp.DistanceOutput); // // Take different actions depending on our environment: // 0: cruising // 1: collided // var sw = new Switch( new [] { new Connection(distanceToSpeed.Output, robot.SpeedInput), new Connection(new SineWave(0.5, 0.333, 0, updateFrequency: 10).Output, robot.DirectionInput), new Connection(new Constant(0).Output, robot.SpinInput), }, new[] { new Connection(new Constant(0.6).Output, robot.SpinInput), new Connection(new Constant(0).Output, robot.DirectionInput), new Connection(new Constant(0).Output, robot.SpeedInput), }); var collided = new Transform(distance => distance < 0.2 ? 1 : 0); collided.Input.ConnectTo(sharp.DistanceOutput); collided.Output.ConnectTo(sw.Input); // // Loop to keep us alive // for (; ;) { //Debug.Print ("TwoWheeled Tick"); Thread.Sleep(1000); } }
public static void Run() { var scope = new DebugScope(); // // Create the robot // var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); leftMotor.CalibrationInput.Value = 1; var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); rightMotor.CalibrationInput.Value = 1; // // Create his eyes // var leftRange = new SharpGP2D12 { Name = "LeftRange" }; var rightRange = new SharpGP2D12 { Name = "RightRange" }; leftRange.AnalogInput.ConnectTo(new AnalogInputPin(AnalogChannels.ANALOG_PIN_A0, 10).Analog); rightRange.AnalogInput.ConnectTo(new AnalogInputPin(AnalogChannels.ANALOG_PIN_A1, 10).Analog); scope.ConnectTo(leftRange.DistanceOutput); scope.ConnectTo(rightRange.DistanceOutput); // // Now some intelligence // Each motor is driven by the distance sensor's reading // var nearDist = 0.1; var farDist = 0.5; var minSpeed = 0.4; TransformFunction distanceToSpeed = d => { if (d < nearDist) { return(-minSpeed); } if (d > farDist) { return(1); } var a = (d - nearDist) / (farDist - nearDist); return(a * (1 - minSpeed) + minSpeed); }; var leftSpeed = new Transform(distanceToSpeed); leftSpeed.Input.ConnectTo(leftRange.DistanceOutput); leftSpeed.Output.ConnectTo(leftMotor.SpeedInput); var rightSpeed = new Transform(distanceToSpeed); rightSpeed.Input.ConnectTo(rightRange.DistanceOutput); rightSpeed.Output.ConnectTo(rightMotor.SpeedInput); }