summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/motor/test_motor.cc
blob: b9e506633b42b6bd1e63774035dec7a71008efcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// test_motor.cc
// buzz - Programme du robot Efrei Robotique I1-I2 2003
// Copyright (C) 2003 Nicolas Schodet
//
#include "motor.h"
#include "erreur/erreur.h"
#include "date/date.h"

#include <iostream>
#include <unistd.h>
#include <stdlib.h>

int
main (int argc, char **argv)
{
    cout << "hello" << endl;
    try
      {
	Motor m;
	cout << "world" << endl;
	int i = 1;
	int c;
	while (i < argc)
	  {
	    switch (argv[i][0])
	      {
	      case 'j':
		cout << "jack" << endl;
		i++;
		m.waitRound ();
		break;
	      case 'h':
		i++;
		cout << "capteurs ";
		c = m.getCapteurs ();
		for (int j = 1; j < 0x100; j <<= 1)
		  {
		    cout << (c & j ? '#' : '_') << ' ';
		  }
		cout << endl;
		break;
	      case 't':
		cout << "turn" << endl;
		i++;
		if (i >= argc) return 1;
		m.turnAngle (atoi (argv[i++]));
		break;
	      case 'z':
		cout << "rezet" << endl;
		i++;
		m.reset ();
		break;
	      case 'H':
		i++;
		if (i >= argc) return 1;
		cout << "servo " << atoi (argv[i]);
		m.setServo (atoi (argv[i++]));
		break;
	      default:
		cout << "go" << endl;
		m.goDistance (atoi (argv[i++]));
		break;
	      }
	    while (!m.finnish ()) Date::wait (50);
	  }
	return 0;
      }
    catch (Erreur &e)
      {
	cerr << e.what () << endl;
	return 1;
      }
}