public void Execute(McNxtBrick brick, SortRail sortRail, BallPosition position)
        {
            int tacho = sortRail.GetTachoToPosition(position);
            MotorDirection motorDirection = MotorDirection.Forward;

            if (tacho < 0)
            {
                motorDirection = MotorDirection.Backward;
            }

            var absTacho = (uint)Math.Abs(tacho);

            if (absTacho != 0)
            {

                Debug.WriteLine("Heading for position {0} with tacho {1}",
                                position,
                                tacho);

                int resultTacho = MotorHelper.RunAndWaitOnCompletion(
                    (McNxtMotor)brick.MotorA,
                    absTacho,
                    motorDirection);

                sortRail.CurrentTacho += resultTacho;
            }
        }
        public void Execute(McNxtBrick brick)
        {
            brick.MotorC.Run(100, 3200);
            Thread.Sleep(6000);

            brick.MotorC.Run(-100, 3200);
            Thread.Sleep(3000);
        }
        public void Execute(McNxtBrick brick)
        {
            brick.MotorB.Run(power: -10, tachoLimit: 25);
            Thread.Sleep(1500);

            brick.MotorB.Run(power: 10, tachoLimit: 25);
            Thread.Sleep(1000);
        }
        public RobotEngineMc()
        {
            _brick = new McNxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo)
            {
                MotorA = new McNxtMotor(),
                MotorB = new McNxtMotor()
            };

            _motorSync = new McNxtMotorSync(_brick.MotorA, _brick.MotorB);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            //var brick = new NxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo)
            //{
            //    MotorA = new NxtMotor(),
            //    MotorB = new NxtMotor(),
            //    MotorC = new NxtMotor()
            //};

            //var motorSync = new NxtMotorSync(brick.MotorA, brick.MotorB);

            //brick.Connect();

            ////const int units = 10;

            ////var realDistance = units / Config.UnitsInMeter;
            ////var tachoLimit = (ushort)(realDistance * Config.RunTacho);

            ////motorSync.Run(Config.RunPower, tachoLimit, 0);

            //const double angle = 90;
            //var tachoLimit = (ushort)(Math.Abs(angle) * Config.TurnTacho);

            //motorSync.Run(Config.TurnPower, tachoLimit, (sbyte)(Math.Sign(angle) * 100));

            var brick = new McNxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo)
            {
                MotorA = new McNxtMotor(),
                MotorB = new McNxtMotor(),
                MotorC = new McNxtMotor()
            };

            var motorSync = new McNxtMotorSync(brick.MotorA, brick.MotorB);

            brick.Connect();

            //const int units = 10;

            //var realDistance = units / Config.UnitsInMeter;
            //var tachoLimit = (ushort)(realDistance * Config.RunTacho);

            //motorSync.Run(Config.RunPower, tachoLimit, 0);

            const double angle = 370;
            var tachoLimit = (ushort)(Math.Abs(angle) * Config.TurnTacho);

            brick.MotorA.Run((sbyte)(Math.Sign(angle) * Config.TurnPower), tachoLimit);
            brick.MotorB.Run((sbyte)(-Math.Sign(angle) * Config.TurnPower), tachoLimit);
        }
Esempio n. 6
0
        public SortRobot()
        {
            _brick = new McNxtBrick(NxtCommLinkType.USB, 0)
                         {
                             MotorA = new McNxtMotor(),
                             MotorB = new McNxtMotor(),
                             MotorC = new McNxtMotor(),
                             Sensor3 = new Nxt2ColorSensor()
                         };

            Brick.Connect();
            Brick.CommLink.KeepAlive();

            if (!Brick.IsMotorControlRunning())
            {
                Brick.StartMotorControl();
            }
        }
        public Nxt2Color Execute(McNxtBrick brick)
        {
            var colorSensor = brick.Sensor3 as Nxt2ColorSensor;
            Nxt2Color? color = null;

            if (colorSensor != null)
            {
                colorSensor.SetColorDetectorMode();
                colorSensor.Poll();
                color = colorSensor.Color;

                Thread.Sleep(500);

                if (color != null)
                    Debug.WriteLine("Color {0}", color.Value);
            }

            return color.Value;
        }
Esempio n. 8
0
 static void SetupUSBConnection()
 {
     brick = new McNxtBrick(NxtCommLinkType.USB, 0);
     Console.WriteLine("\nUSB connection set up.");
 }
Esempio n. 9
0
 static void SetupBluetoothConnection()
 {
     Console.WriteLine("\n\nEnter your Bluetooth COM-Port (Default: 40)");
     byte comport = Convert.ToByte(Console.ReadLine());
     brick = new McNxtBrick(NxtCommLinkType.Bluetooth, comport);
     Console.WriteLine("\nBluetooth connection set up at port " + comport + ".");
 }