// test_busp.cc // buzz - Programme du robot Efrei Robotique I1-I2 2003 // Copyright (C) 2003 Nicolas Schodet // #include "busp.h" #include "erreur/erreur.h" #include #include #include #include // Mode de controle des servos. void testServos (void); // Mode capteurs. void testCapteurs (void); int main (int argc, char **argv) { try { Busp busp; int addr, data; switch (argc) { case 3: // Ecriture. addr = strtol (argv[1], 0, 0); data = strtol (argv[2], 0, 0); busp.cli (); busp.write (addr, data); busp.sti (); break; case 2: if (strcmp (argv[1], "irq") == 0) { // Attend des interuptions. cout << "irq" << endl; char c; cin >> c; } else if (strcmp (argv[1], "servo") == 0) { // Passe en mode contrôle servos. testServos (); } else if (strcmp (argv[1], "capteurs") == 0) { // Passe en mode capteurs. testCapteurs (); } else if (strcmp (argv[1], "reset") == 0) { // Ne fait rien, juste reset. busp.reset (); cout << "reset" << endl; } else if (strcmp (argv[1], "gps") == 0) { // Lit une trame sur le GPS. busp.getGPS ().read (); busp.getGPS ().dump (); } else { // Lecture. addr = strtol (argv[1], 0, 0); busp.cli (); busp.read (addr); busp.sti (); } break; default: if (argc >= 4 && strcmp (argv[1], "servo") == 0 && argc % 2 == 0) { for (int i = 2; i < argc; i += 2) { busp.getServo ().moveTo (atoi (argv[i]), atoi (argv[i + 1])); } } if (argc >= 4 && strcmp (argv[1], "actionneurs") == 0 && argc % 2 == 0) { if (strcmp (argv[2], "all") == 0) { busp.getActionneurs ().setAll (atoi (argv[3]), atoi (argv[4])); } else { for (int i = 2; i < argc; i += 2) { busp.getActionneurs ().set (atoi (argv[i]), atoi (argv[i + 1])); } } } else { cerr << argv[0] << ": teste le bus parallèle." << endl << "\t" << argv[0] << " []" << endl << "\t" << argv[0] << " reset" << endl << "\t" << argv[0] << " irq" << endl << "\t" << argv[0] << " capteurs" << endl << "\t" << argv[0] << " gps" << endl << "\t" << argv[0] << " actionneurs [ ...]" << endl << "\t" << argv[0] << " actionneurs all " << endl << "\t" << argv[0] << " servo [ ...]" << endl; } return 1; } } catch (const std::exception &e) { cerr << e.what (); return 1; } return 0; } // Mode de controle des servos. void testServos (void) { char c; int diff, servo = 0; cout << "Mode servos\n" "0-9 : choix du servo.\n" "y : -1, h : +1, u : -5, j : +5, i : -20, k : +20\n" "r : reset, g : goto \n" "p : position préprogrammée\n"; while (!cin.eof ()) { cin >> c; diff = 0; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': servo = c - '0'; break; case 'y': diff = -1; break; case 'h': diff = 1; break; case 'u': diff = -5; break; case 'j': diff = 5; break; case 'i': diff = -20; break; case 'k': diff = 20; break; } if (diff) { Busp::getInstance ().getServo ().move (servo, diff); } else if (c == 'g') { int pos; cin >> pos; Busp::getInstance ().getServo ().moveTo (servo, pos); } else if (c == 'p') { int pos; cin >> pos; Busp::getInstance ().getServo ().position (pos); } else if (c == 'r') { Busp::getInstance ().reset (); } } } // Mode capteurs. void testCapteurs (void) { while (1) { Busp::getInstance ().getCapteurs ().dump (); cout << '\r'; cout.flush (); sleep (1); } }