void USS_Direct(USSDirection dir) { if (!nxt.IsMotorControlRunning()) { nxt.StartMotorControl(); } switch (dir) { case USSDirection.Straight: if (currentDir == USSDirection.Right) { nxt.MotorA = new McNxtMotor(); nxt.MotorA.Run(-100, 90); } if (currentDir == USSDirection.Left) { nxt.MotorA = new McNxtMotor(); nxt.MotorA.Run(100, 90); } currentDir = USSDirection.Straight; break; case USSDirection.Right: if (currentDir == USSDirection.Straight) { nxt.MotorA = new McNxtMotor(); nxt.MotorA.Run(100, 90); } if (currentDir == USSDirection.Left) { nxt.MotorA = new McNxtMotor(); nxt.MotorA.Run(100, 180); } currentDir = USSDirection.Right; break; case USSDirection.Left: if (currentDir == USSDirection.Straight) { nxt.MotorA = new McNxtMotor(); nxt.MotorA.Run(-100, 90); } if (currentDir == USSDirection.Right) { nxt.MotorA = new McNxtMotor(); nxt.MotorA.Run(-100, 180); } currentDir = USSDirection.Left; break; } System.Threading.Thread.Sleep(900); }
//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; } }