summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/qia/qia.cc
blob: 79eba39f608feefa3438347b6d86299ca8a3ad43 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// qia.cc
// buzz - Programme du robot Efrei Robotique I1-I2 2003
// Copyright (C) 2003 Nicolas Schodet
//
#include "qia.h"
#include "config/config.h"

// Constructeur.
QIa::QIa (bool vert)
{
    Config rc ("rc/qia");
    m_pathSize = 0;
    while (!rc.eof ())
      {
	if (rc.isId ("path"))
	  {
	    rc.getId ();
	    while (!rc.eof ())
	      {
		m_path.push_back (rc.getNum ());
		m_pathSize++;
	      }
	  }
	else rc.noId ();
      }
    // Initialisation.
    m_pathNext = 0;
    m_vert = vert;
}

// Lance l'automate.
void
QIa::go (void)
{
    // Reset les cartes.
    m_motor.reset ();
    // Positionne les servos.
    m_motor.setServo (1);
    m_motor.setServo (8);
    // Attend le jack.
    m_motor.waitRound ();
    // D�mare le chrono.
    m_date.startRound ();
    // Lit le chemin.
    int d;
    while (m_pathNext < m_pathSize)
      {
	d = m_path[m_pathNext++];
	if (!d)
	    // Virages.
	    turn ();
	else
	    // Sections droites.
	    ahead (d);
      }
    // Stop, on bouge plus.
    while (1) Date::wait (999);
}

// Tourne.
void
QIa::turn (void)
{
    int a = m_path[m_pathNext++];
    m_motor.turnAngle (a);
    while (!m_motor.finnish ()) Date::wait (50);
}

// Tout droit.
void
QIa::ahead (int d)
{
    while (!m_motor.finnish ())
      {
	// Fait avancer le moteur.
	m_motor.goDistance (d);
	// M�morise la distance parcourue.
	//m_motor.setDone ();
	// Tant que �a roule.
	while (!m_motor.finnish ())
	  {
	    Date::wait (50);
	    // Teste la bari�re
	    if (m_motor.getCapteurs () & 0x20)
	      {
		while (!m_motor.getCapteurs () & 0x20)
		  {
		    Date::wait (10);
		    m_motor.readMsg ();
		  }
// 		// Avance tout doucement.
// 		m_motor.goDistance (150, 25);
// 		// Jusqu'au capteur barri�re ou rien trouv�.
// 		while (!m_motor.finnish () &&
// 		       !(m_busp.getCapteurs ().get () & 0x02))
// 		  {
// 		    m_motor.readMsg ();
// 		    Date::wait (50);
// 		  }
// 		// Arr�te le moteur.
// 		m_motor.stop ();
// 		while (!m_motor.finnish ())
// 		  {
// 		    m_motor.readMsg ();
// 		    Date::wait (50);
// 		  }
 		// Regarde la couleur.
 		if ((m_motor.getCapteurs () & 0x80) && m_vert
 		    || !(m_motor.getCapteurs () & 0x80) && !m_vert)
 		  {
// 		    // Repart dans l'autre sens.
// 		    m_motor.go (-25);
// 		    while (m_busp.getCapteurs ().get () & 0x02)
// 		      {
// 			m_motor.readMsg ();
// 			Date::wait (50);
// 		      }
// 		    // Stop.
// 		    m_motor.stop ();
// 		    while (!m_motor.finnish ())
// 		      {
// 			m_motor.readMsg ();
// 			Date::wait (50);
// 		      }
 		    // Retourne le palet.
 		    m_motor.setServo (7);
// 		    // Recule.
// 		    m_motor.goDistance (-30);
// 		    // R�avance le robot.
// 		    m_motor.goDistance (140, 25);
// 		    while (!m_motor.finnish ())
// 		      {
// 			m_motor.readMsg ();
// 			Date::wait (50);
// 		      }
		    Date::wait (2000);
 		    // Retourne les doigts.
 		    m_motor.setServo (8);
 		  }
	      }
	    // Lit la distance parcourue.
	    //d -= m_motor.getDone ();
	    continue;
	  }
      }
}