public static void Run()
        {
            var shield = new AdafruitMotorShield();
            var robot = new TwoWheeledRobot(shield.GetMotor(1), shield.GetMotor(2));

            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);
        }
Exemple #2
0
        public static void Run()
        {
            var shield = new AdafruitMotorShield();
            var robot  = new TwoWheeledRobot(shield.GetMotor(1), shield.GetMotor(2));

            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 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 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);
        }
Exemple #5
0
        public static void Run()
        {
            //
            // 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);
            }
        }
        public static void Run ()
        {
            //
            // 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);
            }
        }
        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()
        {
            //
            // 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);
            }
        }