コード例 #1
0
ファイル: Program.cs プロジェクト: yuri1312/Monkey.Robotics
        public static void Main()
        {
            // A debug scope allows us to listen to a block (in this case the
            // accelerometer), and automatically write its output to the console.
            DebugScope scope = new DebugScope();

            scope.UpdatePeriod.Value = .5;             // update 2x/second

            // create a new instance of the Memsic2125 class
            Memsic2125 accelerometer = new Memsic2125();

            // connect the acceleromter outputs to the output through pins 11 and 12
            accelerometer.XPwmInput.ConnectTo(new DigitalInputPin(Pins.GPIO_PIN_D11).Output);
            accelerometer.YPwmInput.ConnectTo(new DigitalInputPin(Pins.GPIO_PIN_D12).Output);
            // connect our scope the acceleromter output
            scope.ConnectTo(accelerometer.XAccelerationOutput);
            scope.ConnectTo(accelerometer.YAccelerationOutput);

            // keep the program alive
            while (true)
            {
                Thread.Sleep(1000);
                Debug.Print("Waiting a second.");
            }
        }
コード例 #2
0
        public static void Run()
        {
            var scope = new DebugScope();
            //scope.UpdatePeriod.Value = 1;

            var accel = new Memsic2125();

            accel.XPwmInput.ConnectTo(new DigitalInputPin(Pins.GPIO_PIN_D6).Output);
            accel.YPwmInput.ConnectTo(new DigitalInputPin(Pins.GPIO_PIN_D7).Output);
            scope.ConnectTo(accel.XAccelerationOutput);
            scope.ConnectTo(accel.YAccelerationOutput);

            var compass = new Grove3AxisDigitalCompass();

            scope.ConnectTo(compass.XGaussOutput);
            scope.ConnectTo(compass.YGaussOutput);
            scope.ConnectTo(compass.ZGaussOutput);

            var a0 = new AnalogInputPin(AnalogChannels.ANALOG_PIN_A0);

            scope.ConnectTo(a0.Analog);

            var sharp = new SharpGP2D12();

            a0.Analog.ConnectTo(sharp.AnalogInput);
            scope.ConnectTo(sharp.DistanceOutput);

            var therm = new Thermistor();

            therm.AnalogInput.ConnectTo(a0.Analog);
            scope.ConnectTo(therm.Temperature);

            var b = new CelsiusToFahrenheit();

            therm.Temperature.ConnectTo(b.Celsius);
            scope.ConnectTo(b.Fahrenheit);


            var bmp = new Bmp085();

            scope.ConnectTo(bmp.Temperature);

            var b2 = new CelsiusToFahrenheit();

            bmp.Temperature.ConnectTo(b2.Celsius);
            scope.ConnectTo(b2.Fahrenheit);


            for (; ;)
            {
                Debug.Print("Tick");
                Thread.Sleep(1000);
            }
        }
コード例 #3
0
 private static void AssertScope(DebugScope actual, DebugScopeType expectedType, params string[] expectedBindingNames)
 {
     Assert.Equal(expectedType, actual.ScopeType);
     // Global scope will have a number of intrinsic bindings that are outside the scope [no pun] of these tests
     if (actual.ScopeType != DebugScopeType.Global)
     {
         Assert.Equal(expectedBindingNames.Length, actual.BindingNames.Count);
     }
     foreach (string expectedName in expectedBindingNames)
     {
         Assert.Contains(expectedName, actual.BindingNames);
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        public static void Run ()
        {
            var scope = new DebugScope ();
            //scope.UpdatePeriod.Value = 1;

            var accel = new Memsic2125 ();
            accel.XPwmInput.ConnectTo (new DigitalInputPin (Pins.GPIO_PIN_D6).Output);
            accel.YPwmInput.ConnectTo (new DigitalInputPin (Pins.GPIO_PIN_D7).Output);
            scope.ConnectTo (accel.XAccelerationOutput);
            scope.ConnectTo (accel.YAccelerationOutput);

            var compass = new Grove3AxisDigitalCompass ();
            scope.ConnectTo (compass.XGaussOutput);
            scope.ConnectTo (compass.YGaussOutput);
            scope.ConnectTo (compass.ZGaussOutput);

            var a0 = new AnalogInputPin (AnalogChannels.ANALOG_PIN_A0);
            scope.ConnectTo (a0.Analog);

            var sharp = new SharpGP2D12 ();
            a0.Analog.ConnectTo (sharp.AnalogInput);
            scope.ConnectTo (sharp.DistanceOutput);

            var therm = new Thermistor ();
            therm.AnalogInput.ConnectTo (a0.Analog);
            scope.ConnectTo (therm.Temperature);

            var b = new CelsiusToFahrenheit ();
            therm.Temperature.ConnectTo (b.Celsius);
            scope.ConnectTo (b.Fahrenheit);


            var bmp = new Bmp085 ();
            scope.ConnectTo (bmp.Temperature);

            var b2 = new CelsiusToFahrenheit ();
            bmp.Temperature.ConnectTo (b2.Celsius);
            scope.ConnectTo (b2.Fahrenheit);


            for (; ; ) {
                Debug.Print ("Tick");
                Thread.Sleep (1000);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
ファイル: DebugDisplayRegistry.cs プロジェクト: touky/Prateek
 ///---------------------------------------------------------------------
 internal static void Remove(DebugScope scope)
 {
     scopes.Remove(scope);
 }
コード例 #8
0
ファイル: DebugDisplayRegistry.cs プロジェクト: touky/Prateek
 ///---------------------------------------------------------------------
 internal static void Add(DebugScope scope)
 {
     scopes.Add(scope);
 }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
        }