public static void KeyboardThreadLoop() { ConsoleKeyInfo keyinfo; do { keyinfo = Console.ReadKey(); Console.WriteLine(keyinfo.Key + " was pressed"); if ((keyinfo.KeyChar == 'a') || (keyinfo.KeyChar == 'A')) { // demander un nouveau coeff translation Console.WriteLine("donne le nouveau coeff de translation stp (entre 0 et 1.0, il vaut actuellement " + coeffTrans + "):"); string s = Console.ReadLine(); try { double newCoeff = Double.Parse(s); coeffTrans = newCoeff; Console.WriteLine("le nouveau coeff de translation vaut: " + coeffTrans); } catch (FormatException e) { Console.WriteLine("FormatException occured while trying to parse your data"); } } else if ((keyinfo.KeyChar == 'z') || (keyinfo.KeyChar == 'Z')) // demander un nouveau coeff rotation { // demander une nouvelle vitesse Console.WriteLine("donne le nouveau coeff de rotation stp (entre 0 et 1.0, il vaut actuellement " + coeffRot + "):"); string s = Console.ReadLine(); try { double newCoeff = Double.Parse(s); coeffRot = newCoeff; Console.WriteLine("le nouveau coeff de rotation vaut: " + coeffRot); } catch (FormatException e) { Console.WriteLine("FormatException occured while trying to parse your data"); } } else if ((keyinfo.KeyChar == 'e') || (keyinfo.KeyChar == 'E')) // enregistrer la position current du robot { // demander une nouvelle vitesse Console.WriteLine("enregistre la position current du robot"); NLX.Robot.Kuka.Controller.CartesianPosition currentPos = theRobot.GetCurrentPosition(); Console.WriteLine("current position:"); Console.WriteLine("x: " + currentPos.X); Console.WriteLine("y: " + currentPos.Y); Console.WriteLine("z: " + currentPos.Z); Console.WriteLine("a: " + currentPos.A); Console.WriteLine("b: " + currentPos.B); Console.WriteLine("c: " + currentPos.C); if (modeCapture == true) { //a finir , convertir double en string mais attention ! virgule ou point?! sh.addInstruction(currentPos.X.ToString()); sh.addInstruction(currentPos.Y.ToString()); sh.addInstruction(currentPos.Z.ToString()); sh.addInstruction(currentPos.A.ToString()); sh.addInstruction(currentPos.B.ToString()); sh.addInstruction(currentPos.C.ToString()); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'd') || (keyinfo.KeyChar == 'D')) // enregistrer la position current du robot en tant que p0, p1, p2, et p3 { // demander une nouvelle vitesse string point="p"; if (pointAEnregistrer == 0) { point = "p0"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 1) { point = "p1"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 2) { point = "p0"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 3) { point = "p2"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 4) { point = "p3"; pointAEnregistrer += 1; } Console.WriteLine("enregistre la position current du robot"); NLX.Robot.Kuka.Controller.CartesianPosition currentPos = theRobot.GetCurrentPosition(); if (modeCapture == true) { //a finir , convertir double en string mais attention ! virgule ou point?! sh.addInstruction(point); sh.addInstruction(currentPos.X.ToString()); sh.addInstruction(currentPos.Y.ToString()); sh.addInstruction(currentPos.Z.ToString()); sh.addInstruction(currentPos.A.ToString()); sh.addInstruction(currentPos.B.ToString()); sh.addInstruction(currentPos.C.ToString()); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'r') || (keyinfo.KeyChar == 'R')) // incr coeff trans { // demander une nouvelle vitesse coeffTrans += 0.1; if(coeffTrans > 1.0) { coeffTrans = 1.0; } Console.WriteLine("coeffTrans: " + coeffTrans); } else if ((keyinfo.KeyChar == 't') || (keyinfo.KeyChar == 'T')) // desincr coeff trans { // demander une nouvelle vitesse coeffTrans -= 0.1; if (coeffTrans < 0.0) { coeffTrans = 0.0; } Console.WriteLine("coeffTrans: " + coeffTrans); } else if ((keyinfo.KeyChar == 'y') || (keyinfo.KeyChar == 'Y')) // incr coeff rot { // demander une nouvelle vitesse coeffRot += 0.1; if (coeffRot > 1.0) { coeffRot = 1.0; } Console.WriteLine("coeffRot: " + coeffRot); } else if ((keyinfo.KeyChar == 'u') || (keyinfo.KeyChar == 'U')) // desincr coeff rot { // demander une nouvelle vitesse coeffRot -= 0.1; if (coeffRot < 0.0) { coeffRot = 0.0; } Console.WriteLine("coeffRot: " + coeffRot); } else if ((keyinfo.KeyChar == 'i') || (keyinfo.KeyChar == 'I')) // open grip { // demander une nouvelle vitesse theRobot.OpenGripper(); Console.WriteLine("open grip"); if (modeCapture == true) { sh.addInstruction("open"); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'o') || (keyinfo.KeyChar == 'O')) // close grip { // demander une nouvelle vitesse theRobot.CloseGripper(); Console.WriteLine("close grip"); if (modeCapture == true) { sh.addInstruction("close"); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'p') || (keyinfo.KeyChar == 'P')) // changer mode { modeDefaut = !modeDefaut; Console.WriteLine(modeDefaut); } else if ((keyinfo.KeyChar == 'q') || (keyinfo.KeyChar == 'Q')) // lancer scenario { if (modeDefaut == true) { Console.WriteLine("in Q default"); ScenarioHandler sh = new ScenarioHandler(); sh.readAndInterpretFile2(scenarioDefaut, theRobot); } else { Console.WriteLine("in Q genered"); ScenarioHandler sh = new ScenarioHandler(); sh.readAndInterpretFile2(scenarioGenere, theRobot); } } else if ((keyinfo.KeyChar == 's') || (keyinfo.KeyChar == 'S')) // changer Capture / terminer capture { if (modeCapture==false) { modeCapture = true; sh.openFile(scenarioGenere); Console.WriteLine("Lancement capture"); Thread myThreadCapture; myThreadCapture = new Thread(new ThreadStart(lancerModeCapture)); myThreadCapture.Start(); } else { //terminer capture Console.WriteLine("testArretcapture"); modeCapture = false; sh.closeFile(scenarioGenere); Console.WriteLine("Arretcapture"); } } } while (Thread.CurrentThread.IsAlive); }
static void Main(string[] args) { started = false; Program prog = new Program(); Console.WriteLine("Start of programm...."); coeffTrans = 1.0; coeffRot = 0.4; Thread myThreadKeyboard; myThreadKeyboard = new Thread(new ThreadStart(KeyboardThreadLoop)); myThreadKeyboard.Start(); device = new TDx.TDxInput.Device(); //keyboard = new TDx.TDxInput.Keyboard(); var keyboard = device.Keyboard; Console.WriteLine(device.Sensor); Console.WriteLine(device.Sensor.Translation); //System.Threading.Thread.Sleep(2500); //translation = device.Sensor.Translation; //rotation = device.Sensor.Rotation; Console.WriteLine(device.IsConnected); device.Connect(); Console.WriteLine(device.IsConnected); //System.Threading.Thread.Sleep(2500); // la souris est connecte /*Console.WriteLine("nombre de touches : "); * Console.WriteLine(keyboard.Keys); * * Console.WriteLine("nombre de touches programmable : "); * Console.WriteLine(keyboard.ProgrammableKeys);*/ //keyboard.KeyDown += new System.EventHandler(prog.onKeyDown); //double xMax = 0, yMax = 0, zMax = 0; theRobot = new NLX.Robot.Kuka.Controller.RobotController(); theRobot.Connect("192.168.1.1"); Console.WriteLine("Connection avec le robot OK !"); sh = new ScenarioHandler(); //sh.readAndInterpretFile(@"C:\Users\IMERIR14\Desktop\Novalinxproject\trunk\darkproject\scenario.sck", theRobot); Console.WriteLine("File interpretation finished"); Console.WriteLine("On entre dans le while sleep"); while (true) { System.Threading.Thread.Sleep(100); } }
static void Main(string[] args) { started = false; Program prog = new Program(); Console.WriteLine("Start of programm...."); coeffTrans = 1.0; coeffRot = 0.4; Thread myThreadKeyboard; myThreadKeyboard = new Thread(new ThreadStart(KeyboardThreadLoop)); myThreadKeyboard.Start(); device = new TDx.TDxInput.Device(); //keyboard = new TDx.TDxInput.Keyboard(); var keyboard = device.Keyboard; Console.WriteLine(device.Sensor); Console.WriteLine(device.Sensor.Translation); //System.Threading.Thread.Sleep(2500); //translation = device.Sensor.Translation; //rotation = device.Sensor.Rotation; Console.WriteLine(device.IsConnected); device.Connect(); Console.WriteLine(device.IsConnected); //System.Threading.Thread.Sleep(2500); // la souris est connecte /*Console.WriteLine("nombre de touches : "); Console.WriteLine(keyboard.Keys); Console.WriteLine("nombre de touches programmable : "); Console.WriteLine(keyboard.ProgrammableKeys);*/ //keyboard.KeyDown += new System.EventHandler(prog.onKeyDown); //double xMax = 0, yMax = 0, zMax = 0; theRobot = new NLX.Robot.Kuka.Controller.RobotController(); theRobot.Connect("192.168.1.1"); Console.WriteLine("Connection avec le robot OK !"); sh = new ScenarioHandler(); //sh.readAndInterpretFile(@"C:\Users\IMERIR14\Desktop\Novalinxproject\trunk\darkproject\scenario.sck", theRobot); Console.WriteLine("File interpretation finished"); Console.WriteLine("On entre dans le while sleep"); while (true) { System.Threading.Thread.Sleep(100); } }
public static void KeyboardThreadLoop() { ConsoleKeyInfo keyinfo; do { keyinfo = Console.ReadKey(); Console.WriteLine(keyinfo.Key + " was pressed"); if ((keyinfo.KeyChar == 'a') || (keyinfo.KeyChar == 'A')) // demander un nouveau coeff translation { Console.WriteLine("donne le nouveau coeff de translation stp (entre 0 et 1.0, il vaut actuellement " + coeffTrans + "):"); string s = Console.ReadLine(); try { double newCoeff = Double.Parse(s); coeffTrans = newCoeff; Console.WriteLine("le nouveau coeff de translation vaut: " + coeffTrans); } catch (FormatException e) { Console.WriteLine("FormatException occured while trying to parse your data"); } } else if ((keyinfo.KeyChar == 'z') || (keyinfo.KeyChar == 'Z')) // demander un nouveau coeff rotation { // demander une nouvelle vitesse Console.WriteLine("donne le nouveau coeff de rotation stp (entre 0 et 1.0, il vaut actuellement " + coeffRot + "):"); string s = Console.ReadLine(); try { double newCoeff = Double.Parse(s); coeffRot = newCoeff; Console.WriteLine("le nouveau coeff de rotation vaut: " + coeffRot); } catch (FormatException e) { Console.WriteLine("FormatException occured while trying to parse your data"); } } else if ((keyinfo.KeyChar == 'e') || (keyinfo.KeyChar == 'E')) // enregistrer la position current du robot { // demander une nouvelle vitesse Console.WriteLine("enregistre la position current du robot"); NLX.Robot.Kuka.Controller.CartesianPosition currentPos = theRobot.GetCurrentPosition(); Console.WriteLine("current position:"); Console.WriteLine("x: " + currentPos.X); Console.WriteLine("y: " + currentPos.Y); Console.WriteLine("z: " + currentPos.Z); Console.WriteLine("a: " + currentPos.A); Console.WriteLine("b: " + currentPos.B); Console.WriteLine("c: " + currentPos.C); if (modeCapture == true) { //a finir , convertir double en string mais attention ! virgule ou point?! sh.addInstruction(currentPos.X.ToString()); sh.addInstruction(currentPos.Y.ToString()); sh.addInstruction(currentPos.Z.ToString()); sh.addInstruction(currentPos.A.ToString()); sh.addInstruction(currentPos.B.ToString()); sh.addInstruction(currentPos.C.ToString()); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'd') || (keyinfo.KeyChar == 'D')) // enregistrer la position current du robot en tant que p0, p1, p2, et p3 { // demander une nouvelle vitesse string point = "p"; if (pointAEnregistrer == 0) { point = "p0"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 1) { point = "p1"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 2) { point = "p0"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 3) { point = "p2"; pointAEnregistrer += 1; } else if (pointAEnregistrer == 4) { point = "p3"; pointAEnregistrer += 1; } Console.WriteLine("enregistre la position current du robot"); NLX.Robot.Kuka.Controller.CartesianPosition currentPos = theRobot.GetCurrentPosition(); if (modeCapture == true) { //a finir , convertir double en string mais attention ! virgule ou point?! sh.addInstruction(point); sh.addInstruction(currentPos.X.ToString()); sh.addInstruction(currentPos.Y.ToString()); sh.addInstruction(currentPos.Z.ToString()); sh.addInstruction(currentPos.A.ToString()); sh.addInstruction(currentPos.B.ToString()); sh.addInstruction(currentPos.C.ToString()); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'r') || (keyinfo.KeyChar == 'R')) // incr coeff trans { // demander une nouvelle vitesse coeffTrans += 0.1; if (coeffTrans > 1.0) { coeffTrans = 1.0; } Console.WriteLine("coeffTrans: " + coeffTrans); } else if ((keyinfo.KeyChar == 't') || (keyinfo.KeyChar == 'T')) // desincr coeff trans { // demander une nouvelle vitesse coeffTrans -= 0.1; if (coeffTrans < 0.0) { coeffTrans = 0.0; } Console.WriteLine("coeffTrans: " + coeffTrans); } else if ((keyinfo.KeyChar == 'y') || (keyinfo.KeyChar == 'Y')) // incr coeff rot { // demander une nouvelle vitesse coeffRot += 0.1; if (coeffRot > 1.0) { coeffRot = 1.0; } Console.WriteLine("coeffRot: " + coeffRot); } else if ((keyinfo.KeyChar == 'u') || (keyinfo.KeyChar == 'U')) // desincr coeff rot { // demander une nouvelle vitesse coeffRot -= 0.1; if (coeffRot < 0.0) { coeffRot = 0.0; } Console.WriteLine("coeffRot: " + coeffRot); } else if ((keyinfo.KeyChar == 'i') || (keyinfo.KeyChar == 'I')) // open grip { // demander une nouvelle vitesse theRobot.OpenGripper(); Console.WriteLine("open grip"); if (modeCapture == true) { sh.addInstruction("open"); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'o') || (keyinfo.KeyChar == 'O')) // close grip { // demander une nouvelle vitesse theRobot.CloseGripper(); Console.WriteLine("close grip"); if (modeCapture == true) { sh.addInstruction("close"); sh.addInstruction(""); } } else if ((keyinfo.KeyChar == 'p') || (keyinfo.KeyChar == 'P')) // changer mode { modeDefaut = !modeDefaut; Console.WriteLine(modeDefaut); } else if ((keyinfo.KeyChar == 'q') || (keyinfo.KeyChar == 'Q')) // lancer scenario { if (modeDefaut == true) { Console.WriteLine("in Q default"); ScenarioHandler sh = new ScenarioHandler(); sh.readAndInterpretFile2(scenarioDefaut, theRobot); } else { Console.WriteLine("in Q genered"); ScenarioHandler sh = new ScenarioHandler(); sh.readAndInterpretFile2(scenarioGenere, theRobot); } } else if ((keyinfo.KeyChar == 's') || (keyinfo.KeyChar == 'S')) // changer Capture / terminer capture { if (modeCapture == false) { modeCapture = true; sh.openFile(scenarioGenere); Console.WriteLine("Lancement capture"); Thread myThreadCapture; myThreadCapture = new Thread(new ThreadStart(lancerModeCapture)); myThreadCapture.Start(); } else { //terminer capture Console.WriteLine("testArretcapture"); modeCapture = false; sh.closeFile(scenarioGenere); Console.WriteLine("Arretcapture"); } } }while (Thread.CurrentThread.IsAlive); }