Ejemplo n.º 1
0
        /// <summary>
        /// Connect to the NXT
        /// </summary>
        /// <param name="ComPort">The COM Port to connect. ex. 4</param>
        public static void ConnectNXT(string ComPort)
        {
            try
            {
                comPort = byte.Parse(ComPort);

                Brick = new NxtBrick(NxtCommLinkType.Bluetooth, comPort);
                NxtMotor motorB = new NxtMotor();
                Brick.MotorB = motorB;
                NxtMotor motorC = new NxtMotor();
                Brick.MotorC = motorC;
                MotorPair = new NxtMotorSync(Brick.MotorB, Brick.MotorC);


                if (!isConnected)
                {
                    Brick.Connect();
                    isConnected = true;
                    Brick.PlaySoundfile("! Attention.rso");
                }
            }
            catch
            {
                isConnected = false;
                DisconnectNXT();
            }
        }
Ejemplo n.º 2
0
        public void Disconnect()
        {
            if (_brick != null && _brick.IsConnected)
                _brick.Disconnect();

            _brick = null;
            _motorPair = null;
        }
 public RobotMovement(NxtBrick nxtBrick, NameValueCollection config)
 {
     _speed = sbyte.Parse(config["Speed"]);
     _nxtBrick = nxtBrick;
     var motorB = new NxtMotor();
     var motorC = new NxtMotor();
     _nxtBrick.MotorB = motorB;
     _nxtBrick.MotorC = motorC;
     _motorPair = new NxtMotorSync(motorB, motorC);
 }
Ejemplo n.º 4
0
        public RobotEngine()
        {
            _brick = new NxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo)
            {
                MotorA = new NxtMotor(),
                MotorB = new NxtMotor(),
                MotorC = new NxtMotor()
            };

            _motorSync = new NxtMotorSync(_brick.MotorA, _brick.MotorB);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Disconnect the NXT
        /// </summary>
        public static void DisconnectNXT()
        {
            Idle();
            Brick.PlaySoundfile("! Attention.rso");
            Brick.CommLink.StopProgram();

            if (Brick != null && Brick.IsConnected)
                isConnected = false;
                Brick.Disconnect();

            Brick = null;
            MotorPair = null;            
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
Archivo: Form1.cs Proyecto: 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;
        }
Ejemplo n.º 8
0
        /*
         * Connects to the NXTBrick with the given comport using the given connectiontype
         */
        public bool ConnectToDevice(NxtCommLinkType connectionType, byte comPort)
        {
            brick = new NxtBrick(connectionType, comPort);

            brick.MotorA = new NxtMotor();
            brick.MotorC = new NxtMotor();

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

            try
            {
                brick.Connect();
                return true;
            }
            catch
            {
                return false;
            }
        }
Ejemplo n.º 9
0
 public NxtRobot(byte port)
 {
     try
     {
         Position = new NXTRobotPosition();
         OnPositionChanged();
         _brick = new NxtBrick(NxtCommLinkType.Bluetooth, port)
         {
             MotorA = new NxtMotor(),
             MotorB = new NxtMotor(),
             MotorC = new NxtMotor()
         };
         _motorPair = new NxtMotorSync(_brick.MotorA, _brick.MotorB);
         _brick.Connect();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Disconnect();
     }
 }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
0
Archivo: Form1.cs Proyecto: cfu1/KiBot
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                myKinect = KinectSensor.KinectSensors[0];
                myKinect.SkeletonStream.Enable();
                myKinect.Start();
            }
            catch
            {
                MessageBox.Show("Kinect initialise failed", "camera view");
                Application.Exit();
            }

            leftInitialPosition = new List<SkeletonPoint>();
            rightInitialPosition = new List<SkeletonPoint>();
            initialPositions = new Dictionary<string, SkeletonPoint>();
            //cmds = new List<Motion>();
            cmds = new Dictionary<Motion, bool>();
            cmds[Motion.Back] = false;
            cmds[Motion.Brake] = false;
            cmds[Motion.Forward] = false;
            cmds[Motion.TurnRight] = false;
            cmds[Motion.TurnLeft] = false;

            nxtStatus = new Dictionary<Motion, bool>();
            nxtStatus[Motion.Brake] = false;
            nxtStatus[Motion.Back] = false;
            nxtStatus[Motion.Forward] = false;
            nxtStatus[Motion.TurnLeft] = false;
            nxtStatus[Motion.TurnRight] = false;

            nxt = new NxtBrick(NxtCommLinkType.Bluetooth, 3);
            nxt.MotorB = new NxtMotor();
            nxt.MotorC = new NxtMotor();
            motorPair = new NxtMotorSync(nxt.MotorB, nxt.MotorC);

            nxt.Connect();

            NXTLabel.Text = "NXT is connected.";

            myKinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(myKinect_SkeletonFrameReady);
        }
Ejemplo n.º 12
0
        /**
         * Stops the car and disconnects from the device.
         */
        public bool Disconnect()
        {
            Yield();

            if (brick != null && brick.IsConnected)
            {
                brick.Disconnect();
            }

            brick = null;
            motorPair = null;

            return true;
        }
Ejemplo n.º 13
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();
        }