Example #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();
            }
        }
Example #2
0
 public Arm(string name, NxtMotor shoulderAlong, NxtMotor shoulderOut, NxtMotor elbowAlong, NxtMotor elbowOut)
 {
     ShoulderAlong = new Joint(shoulderAlong, name+"ShoulderAlong") {DegreeScaleFactor = 24, MinAngle = -270, MaxAngle = 270};
     ShoulderOut = new Joint(shoulderOut, name + "ShoulderOut") { DegreeScaleFactor = 24, MinAngle = 0, MaxAngle = 200 };
     ElbowAlong = new Joint(elbowAlong, name + "ElbowAlong") { Power = 10, MinAngle = 0, MaxAngle = 115 };
     ElbowOut = new Joint(elbowOut, name + "ElbowOut") { Power = 10, MinAngle = -100, MaxAngle = 100 };
 }
        /// <summary>
        /// <para>Constructor.</para>
        /// </summary>
        /// <param name="motorX">The 1. motor of the synchronized pair</param>
        /// <param name="motorY">The 2. motor of the synchronized pair</param>
        public NxtMotorSync(NxtMotor motorX, NxtMotor motorY)
        {
            if (motorX == null || motorY == null)
                throw new ArgumentException("One of the motors was null.");

            this.motorX = motorX;
            this.motorY = motorY;
        }
 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);
 }
        public Robot()
        {
            m_brick      = new NxtBrick(NxtCommLinkType.Bluetooth, 3);
            m_leftMotor  = new NxtMotor();
            m_rightMotor = new NxtMotor();

            m_brick.MotorB = m_leftMotor;
            m_brick.MotorC = m_rightMotor;

            m_motors = new NxtMotorSync(m_leftMotor, m_rightMotor);
        }
        public RobotEngine()
        {
            _brick = new NxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo)
            {
                MotorA = new NxtMotor(),
                MotorB = new NxtMotor(),
                MotorC = new NxtMotor()
            };

            _motorCam = _brick.MotorC;
            _motorSync = new NxtMotorSync(_brick.MotorA, _brick.MotorB);
        }
Example #7
0
        public Joint(NxtMotor motor, string name = "Joint")
        {
            Name = name;

            if (motor != null) {
                Motor = motor;
                motor.ResetMotorPosition(true);

                motor.PollInterval = 5;

                // Poll so tacho is not null
                motor.Poll();
                initialTacho = motor.GetNormalisedTacho();

                // Turn the joint on
                Active = true;
            }

            DegreeScaleFactor = 1;

            MinAngle = null;
            MaxAngle = null;
        }
Example #8
0
        static void LinkMotorAxis()
        {
            Console.WriteLine("\nYou now have to specify which Motor represents which 3-dimensional Axis.");
            Console.WriteLine("Enter ('A'/'B'/'C') the Motor controlling X-Axis (left-right) movement:");
            MotorXaxis = Console.ReadKey().KeyChar;

            Console.WriteLine("\nEnter ('A'/'B'/'C') the Motor controlling Y-Axis (foward-backward) movement: (This should be the axis that pushes the drill foward)");
            MotorYaxis = Console.ReadKey().KeyChar;

            Console.WriteLine("\nEnter ('A'/'B'/'C') the Motor controlling Z-Axis (up-down) movement:");
            MotorZaxis = Console.ReadKey().KeyChar;

            Xmotor = new NxtMotor();
            Ymotor = new NxtMotor();
            Zmotor = new NxtMotor();

            switch (MotorXaxis)
            {
            case 'a':
                brick.MotorA = Xmotor;
                break;

            case 'b':
                brick.MotorB = Xmotor;
                break;

            case 'c':
                brick.MotorC = Xmotor;
                break;
            }

            switch (MotorYaxis)
            {
            case 'a':
                brick.MotorA = Ymotor;
                break;

            case 'b':
                brick.MotorB = Ymotor;
                break;

            case 'c':
                brick.MotorC = Ymotor;
                break;
            }

            switch (MotorZaxis)
            {
            case 'a':
                brick.MotorA = Zmotor;
                break;

            case 'b':
                brick.MotorB = Zmotor;
                break;

            case 'c':
                brick.MotorC = Zmotor;
                break;
            }
        }
Example #9
0
        static void LinkMotorAxis()
        {
            Console.WriteLine("\nYou now have to specify which Motor represents which 3-dimensional Axis.");
            Console.WriteLine("Enter ('A'/'B'/'C') the Motor controlling X-Axis (left-right) movement:");
            MotorXaxis = Console.ReadKey().KeyChar;

            Console.WriteLine("\nEnter ('A'/'B'/'C') the Motor controlling Y-Axis (foward-backward) movement: (This should be the axis that pushes the drill foward)");
            MotorYaxis = Console.ReadKey().KeyChar;

            Console.WriteLine("\nEnter ('A'/'B'/'C') the Motor controlling Z-Axis (up-down) movement:");
            MotorZaxis = Console.ReadKey().KeyChar;

            Xmotor = new NxtMotor();
            Ymotor = new NxtMotor();
            Zmotor = new NxtMotor();

            switch (MotorXaxis)
            {
                case 'a':
                    brick.MotorA = Xmotor;
                    break;
                case 'b':
                    brick.MotorB = Xmotor;
                    break;
                case 'c':
                    brick.MotorC = Xmotor;
                    break;
            }

            switch (MotorYaxis)
            {
                case 'a':
                    brick.MotorA = Ymotor;
                    break;
                case 'b':
                    brick.MotorB = Ymotor;
                    break;
                case 'c':
                    brick.MotorC = Ymotor;
                    break;
            }

            switch (MotorZaxis)
            {
                case 'a':
                    brick.MotorA = Zmotor;
                    break;
                case 'b':
                    brick.MotorB = Zmotor;
                    break;
                case 'c':
                    brick.MotorC = Zmotor;
                    break;
            }
        }
Example #10
0
 /// <summary>
 /// <para>Constructor.</para>
 /// </summary>
 /// <param name="motorX">The 1. motor of the synchronized pair</param>
 /// <param name="motorY">The 2. motor of the synchronized pair</param>
 public McNxtMotorSync(NxtMotor motorX, NxtMotor motorY)
     : base(motorX, motorY)
 {
 }
Example #11
0
        private NxtMotor AddMotorToNxt(MotorPort mp)
        {
            var motor = new NxtMotor();
            var brick = nxtBricks[mp.Brick];

            if (brick == null)
                return null;

            switch(mp.Motor) {
                case NxtMotorPort.PortA: brick.MotorA = motor; break;
                case NxtMotorPort.PortB: brick.MotorB = motor; break;
                case NxtMotorPort.PortC: brick.MotorC = motor; break;
            }

            return motor;
        }
 /// <summary>
 /// <para>Constructor.</para>
 /// </summary>
 /// <param name="motorX">The 1. motor of the synchronized pair</param>
 /// <param name="motorY">The 2. motor of the synchronized pair</param>
 public McNxtMotorSync(NxtMotor motorX, NxtMotor motorY)
     : base(motorX, motorY)
 {
 }
Example #13
0
        //Brick connection procedure logic
        private void button_connect_Click(object sender, EventArgs e)
        {
            if (!isConnectedToBrick)
            {
                byte COMport = byte.Parse(COMportInput.Text);

                if (RB_McRXE.Checked)
                {
                    //Create Motor Control NXT Brick and Bluetooth use USB to communicate with it.
                    if (RB_Bluetooth.Checked)
                    {
                        McBrick = new McNxtBrick(NxtCommLinkType.Bluetooth, COMport);
                    }
                    //Create Motor Control NXT Brick, and use USB to communicate with it.
                    if (RB_USB.Checked)
                    {
                        brick = new McNxtBrick(NxtCommLinkType.USB, COMport);
                    }
                    // Create a Motor Control motor.
                    McMotorA = new McNxtMotor();
                    McMotorB = new McNxtMotor();
                    McMotorC = new McNxtMotor();

                    //Synched motors
                    McMotorPair = new McNxtMotorSync(McMotorB, McMotorC);

                    // Attach it to port A of the NXT brick.
                    McBrick.MotorA = McMotorA;
                    McBrick.MotorB = McMotorB;
                    McBrick.MotorC = McMotorC;


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

                    if (!McBrick.IsMotorControlRunning())
                    {
                        McBrick.StartMotorControl();
                    }
                    motorControlActive = true;
                }
                else
                {
                    //Create NXT Brick and Bluetooth use USB to communicate with it.
                    if (RB_Bluetooth.Checked)
                    {
                        NxtBrick brick = new NxtBrick(NxtCommLinkType.Bluetooth, COMport);
                    }
                    // Create a NXT brick, and use USB to communicate with it.
                    if (RB_USB.Checked)
                    {
                        NxtBrick brick = new NxtBrick(NxtCommLinkType.USB, COMport);
                    }
                    // Create a motor.
                    motorA = new NxtMotor();
                    motorB = new NxtMotor();
                    motorC = new NxtMotor();

                    // Attach it to port A of the NXT brick.
                    brick.MotorA = motorA;
                    brick.MotorB = motorB;
                    brick.MotorC = motorC;

                    // Connect to the NXT.
                    brick.Connect();
                }
                ConnectedText.Visible = true;
                isConnectedToBrick    = true;
            }
        }
Example #14
0
 /// <summary>
 /// <para>Attaches a motor to the NXT brick.</para>
 /// </summary>
 /// <param name="motor">The motor</param>
 /// <param name="port">The port to attach the motor to</param>
 private void AttachMotor(NxtMotor motor, NxtMotorPort port)
 {
     if (motor != null)
     {
         motorArr[port] = motor;
         motor.Brick = this;
         motor.Port = port;
     }
 }