private void button_right_Click(object sender, EventArgs e) { //Run left motor if (isConnectedToBrick) { if (RB_McRXE.Checked) { McMotorC.Run(50, 180); } else { motorC.Run(50, 90); } } }
private void button_GO_Click(object sender, EventArgs e) { sbyte sbPower = 0; int iPower = 0; uint uigrader = 0; long lgrader = 0; string message = ""; string caption_sbyte = "Fejl i power indtastningen"; bool KraftReady = false; bool GradReady = false; DialogResult result; // Læs http://www.mindsqualls.net/QuickStart_2_0.aspx for mere... if (!sbyte.TryParse(textBox1.Text, out sbPower)) { if (int.TryParse(textBox1.Text, out iPower)) { if (iPower < 0) { message = "Motor kraft tallet er for lille! Tallet skal være mellem -128 og 127!"; } else { message = "Motor kraft tallet er for stort! Tallet skal være mellem -128 og 127!"; } } else { message = "Der skal stå et heltal i 'Motor kraft' feltet! Tallet skal være mellem -128 og 127!"; } MessageBoxButtons buttons = MessageBoxButtons.OK; // Displays the MessageBox. result = MessageBox.Show(message, caption_sbyte, buttons); KraftReady = false; } else { KraftReady = true; } if (!uint.TryParse(textBox2.Text, out uigrader)) { if (long.TryParse(textBox2.Text, out lgrader)) { if (lgrader < 0) { message = "Motor grad tallet er for lille! Tallet skal være mellem 0 og 4,294,967,295!"; } else { message = "Motor grad tallet er for stort! Tallet skal være mellem 0 og 4,294,967,295!"; } } else { message = "Der skal stå et heltal i 'Motor grad' feltet! Tallet skal være mellem 0 og 4,294,967,295!"; } MessageBoxButtons buttons = MessageBoxButtons.OK; // Displays the MessageBox. result = MessageBox.Show(message, caption_sbyte, buttons); GradReady = false; } else { GradReady = true; } // Power står i textbox1 og degrees står i textbox2 // if (sbyte.Parse(textBox1.Text) < 0 || sbyte.Parse(textBox1.Text) < 0) if (KraftReady && GradReady) { if (motorControlActive) { McMotorA.Run(sbyte.Parse(textBox1.Text), uint.Parse(textBox2.Text)); } else { motorA.Run(sbyte.Parse(textBox1.Text), uint.Parse(textBox2.Text)); } } }
static void Calibrate() { Console.WriteLine("\nProjectX now needs to know from where to where it can navigate on each axis."); //X Console.WriteLine("Motor " + MotorXaxis + ", controlling the X-Axis, will now drive to one end of its movement range. Be prepared to press any Key when the end is reached. Press any Key to start."); Console.ReadKey(); Xmotor.Run(-20, 0); Console.ReadKey(); Xmotor.Brake(); System.Threading.Thread.Sleep(20); Xmotor.Poll(); XRange1 = Xmotor.TachoCount.Value; Console.WriteLine("\nDo you wish this to be the positive or the negative end? ('p'/'n')"); if (Console.ReadKey().KeyChar == 'p') { Xinverted = true; } Console.WriteLine("Motor " + MotorXaxis + " will now move to the opposite and. Press any key if you're ready."); Console.ReadKey(); Xmotor.Run(20, 0); Console.ReadKey(); Xmotor.Brake(); System.Threading.Thread.Sleep(20); Xmotor.Poll(); XRange2 = Xmotor.TachoCount.Value; //Y Console.WriteLine("\nMotor " + MotorYaxis + ", controlling the Y-Axis, will now drive to one end of its movement range. Be prepared to press any Key when the end is reached. Press any Key to start."); Console.ReadKey(); Ymotor.Run(-20, 0); Console.ReadKey(); Ymotor.Brake(); System.Threading.Thread.Sleep(20); Ymotor.Poll(); YRange1 = Ymotor.TachoCount.Value; Console.WriteLine("\nDo you wish this to be the positive or the negative end? ('p'/'n')"); if (Console.ReadKey().KeyChar == 'p') { Yinverted = true; } Console.WriteLine("Motor " + MotorYaxis + " will now move to the opposite and. Press any key if you're ready."); Console.ReadKey(); Ymotor.Run(20, 0); Console.ReadKey(); Ymotor.Brake(); System.Threading.Thread.Sleep(20); Ymotor.Poll(); YRange2 = Ymotor.TachoCount.Value; //Z Console.WriteLine("\nMotor " + MotorZaxis + ", controlling the Z-Axis, will now drive to one end of its movement range. Be prepared to press any Key when the end is reached. Press any Key to start."); Console.ReadKey(); Zmotor.Run(-20, 0); Console.ReadKey(); Zmotor.Brake(); Zmotor.Poll(); ZRange1 = Zmotor.TachoCount.Value; Console.WriteLine("\nDo you wish this to be the positive or the negative end? ('p'/'n')"); if (Console.ReadKey().KeyChar == 'p') { Zinverted = true; } Console.WriteLine("Motor " + MotorZaxis + " will now move to the opposite and. Press any key if you're ready."); Console.ReadKey(); Zmotor.Run(20, 0); Console.ReadKey(); Zmotor.Brake(); System.Threading.Thread.Sleep(20); Zmotor.Poll(); ZRange2 = Zmotor.TachoCount.Value; if (Xinverted) { int i = XRange1; XRange1 = XRange2; XRange2 = i; } if (Yinverted) { int i = YRange1; YRange1 = YRange2; YRange2 = i; } if (Zinverted) { int i = ZRange1; ZRange1 = ZRange2; ZRange2 = i; } }