Example #1
0
        static void Reverse()
        {
            motorPair.Brake();
            
            // set to reverse
            brick.MotorA = new NxtMotor(true);
            brick.MotorC = new NxtMotor(true);
            motorPair = new NxtMotorSync(brick.MotorA, brick.MotorC);

            motorPair.Run(75, 0, 0);

            Thread.Sleep(1000);

            motorPair.Brake();
        }
Example #2
0
File: Form1.cs Project: cfu1/KiBot
        private void Backward()
        {
            textBox1.Text += "Backward" + Environment.NewLine;

            if (motorPair != null)
                motorPair.Brake();
            nxt.MotorB = new NxtMotor(true);
            nxt.MotorC = new NxtMotor(true);
            nxt.MotorB.ResetMotorPosition(true);
            nxt.MotorC.ResetMotorPosition(true);
            motorPair = new NxtMotorSync(nxt.MotorB, nxt.MotorC);
            motorPair.Run(100, 0, 0);

            nxtStatus[Motion.Forward] = false;
            nxtStatus[Motion.Back] = true;
            nxtStatus[Motion.TurnLeft] = false;
            nxtStatus[Motion.TurnRight] = false;
            nxtStatus[Motion.Brake] = false;
        }
Example #3
0
        static void Main()
        {
            Init();
            
            brick = new NxtBrick(NxtCommLinkType.USB, 0);
            //brick = new NxtBrick(NxtCommLinkType.Bluetooth, 40);

            var sound = new NxtSoundSensor();
            var touch = new NxtTouchSensor();
            var sonar = new NxtUltrasonicSensor();

            brick.MotorA = new NxtMotor();
            brick.MotorC = new NxtMotor();
            motorPair = new NxtMotorSync(brick.MotorA, brick.MotorC);

            brick.Sensor1 = sonar;
            brick.Sensor3 = touch;
            brick.Sensor4 = sound;

            sound.PollInterval = 50;
            sound.OnPolled += sound_OnPolled;

            sonar.PollInterval = 50;
            sonar.ThresholdDistanceCm = 25;
            sonar.OnPolled += sonar_OnPolled;
            sonar.OnWithinThresholdDistanceCm += OnWithinThreshold; 
            sonar.ContinuousMeasurementCommand();

            touch.PollInterval = 50;
            touch.OnPressed += OnCollision;

            brick.Connect();

            motorPair.Run(75, 0, 0); 

            Console.WriteLine("Press any key to stop.");
            Console.ReadKey();

            brick.Disconnect();
        }
Example #4
0
        public Form1()
        {
            InitializeComponent();

            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 = 100;

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

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

            //brick.Disconnect();

            ////_brick = new NxtBrick(NxtCommLinkType.Bluetooth, 3)
            ////{
            ////    MotorA = new NxtMotor(),
            ////    MotorB = new NxtMotor()
            ////};

            ////_motorSync = new NxtMotorSync(_brick.MotorA, _brick.MotorB);

            ////do
            ////{
            ////    _brick.Connect();
            ////    Thread.Sleep(1000);
            ////} while (!_brick.IsConnected);

            ////for (int i = 0; i < 1; ++i)
            ////{
            ////    _motorSync.ResetMotorPosition(true);
            ////    _motorSync.Idle();
            ////    _motorSync.Run(50, 4040, 100);

            ////    Thread.Sleep(10*1000);
            ////}

            //McNxtBrick brick = new McNxtBrick(NxtCommLinkType.Bluetooth, 3);

            //// Attach motors to port B and C on the NXT.
            //brick.MotorA = new McNxtMotor();
            //brick.MotorB = new McNxtMotor();

            //// Syncronize the two motors.
            //McNxtMotorSync motorPair = new McNxtMotorSync(brick.MotorA, brick.MotorB);

            //// Connect to the NXT.
            //brick.Connect();

            //// If not already running, start the MotorControl program.
            //if (brick.IsMotorControlRunning())
            //    brick.StartMotorControl();

            //// Run the motor-pair at 75% power, for a 3600 degree run.
            //motorPair.Run(75, 3600, 100);

            ////for (int i = 0; i < 3; ++i)
            ////{
            ////    uint tacho = 2000;
            ////    brick.MotorA.Run(50, tacho);
            ////    brick.MotorB.Run(-50, tacho);

            ////    Thread.Sleep(10 * 1000);
            ////}

            //// Disconnect from the NXT.
            //brick.Disconnect();
        }