//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; } }
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 McNxtMotor(); Ymotor = new McNxtMotor(); Zmotor = new McNxtMotor(); switch (MotorXaxis) { case 'a': brick.MotorA = Xmotor; XmotorPort = NxtMotorPort.PortA; break; case 'b': brick.MotorB = Xmotor; XmotorPort = NxtMotorPort.PortB; break; case 'c': brick.MotorC = Xmotor; XmotorPort = NxtMotorPort.PortC; break; } switch (MotorYaxis) { case 'a': brick.MotorA = Ymotor; YmotorPort = NxtMotorPort.PortA; break; case 'b': brick.MotorB = Ymotor; YmotorPort = NxtMotorPort.PortB; break; case 'c': brick.MotorC = Ymotor; YmotorPort = NxtMotorPort.PortC; break; } switch (MotorZaxis) { case 'a': brick.MotorA = Zmotor; ZmotorPort = NxtMotorPort.PortA; break; case 'b': brick.MotorB = Zmotor; ZmotorPort = NxtMotorPort.PortB; break; case 'c': brick.MotorC = Zmotor; ZmotorPort = NxtMotorPort.PortC; break; } }