Revision 309 branch/elmansour/Emb_App/programme_principal_etud.c

View differences:

programme_principal_etud.c
123 123
int k=1;
124 124
unsigned agl_roue;
125 125
unsigned distance;
126
//unsigned dishorizontal;
126
unsigned dishorizontalfix;
127
unsigned dishorizontal;
128
unsigned erreur=0;
129
unsigned vits;
127 130

  
128 131

  
129 132
void tourelle(){
130
	CanFrame comm;
131
	CanFrame requete,reponse;
132 133
	while (1) {
133 134
		//lire l angle de torelle
134 135
		/*requete.data.id='R';
......
136 137
		snd_dtq(CanTx,requete.msg);
137 138
		rcv_dtq(CanRx, &reponse.msg);
138 139
		alpha=reponse.data.val;*/
139
		CanFrame req;
140
		CanFrame req,comm;
140 141
	    UINT flag;
141 142
     	req.data.id='R';
142 143
    	req.data.rtr=1;
......
151 152
		comm.data.rtr=0;
152 153
		comm.data.val=k*(450-alpha);
153 154
		snd_dtq(CanTx,comm.msg);
154
		dly_tsk(10);
155
		
156

  
157
		
155
		dly_tsk(20);
158 156
	}
159 157
}
158

  
160 159
void demarrer (){
160
	dly_tsk(5000);
161
	while(1){
161 162
	CanFrame requete;
162 163
	/*do{
163 164
	dly_tsk(50);
164 165
	}while(abs(k*(450-alpha))>2); */
165
	dly_tsk(5000);
166
	
167
	//mis en mouvement la voiture en vitess de 30
168 166
	requete.data.id='V';
169 167
	requete.data.rtr=0;
170
	requete.data.val=46;
168
	vits=45;
169
	if(abs(distance-707)>30) requete.data.val=30;
170
	/*{
171
	do{
172
	if(vits>20) vits=vits-7;
173
	requete.data.val=vits;
174
	dly_tsk(5);
175
	}while(abs(distance-707)>10);
176
	}*/
177
	else requete.data.val=vits;
171 178
	snd_dtq(CanTx, requete.msg);
179
	dly_tsk(5);
180
	}
172 181
}
182

  
173 183
void roues(){
174
	CanFrame comm;
175
	CanFrame req;
176
	UINT flag;
177
	req.data.id='D';
184
	dly_tsk(1000);
185
	/*req.data.id='D';
178 186
	req.data.rtr=1;
179 187
	periph[ADDR('D')].ev=0x02;
180 188
	snd_dtq(CanTx,req.msg);
181 189
	wai_flg(ev_periph, 0x02,TWF_ANDW, &flag);
182
	agl_roue=periph[ADDR('D')].val;
183
	
190
	agl_roue=periph[ADDR('D')].val;*/
184 191
	//commander la rotation des roues
192
	//dishorizontalfix=distance*sin(3.14*alpha/1800);
185 193
	while(1){
194
	CanFrame req,comm;
195
	UINT flag;
196
	//dishorizontal=distance*sin(3.14*alpha/1800);	
197
	//erreur=dishorizontal-dishorizontalfix;
186 198
	comm.data.id='D';
187 199
	comm.data.rtr=0;
188
	comm.data.val=2*(distance-730);
200
	comm.data.val=2*(distance-707);
189 201
	snd_dtq(CanTx, comm.msg);
202
	dly_tsk(10);
190 203
	}
191 204
		
192 205
}
193 206
void distance_mur(){
194 207
	//lire la distance entre la voiture et le mur
208
	while(1){
195 209
	CanFrame req;
196 210
	UINT flag;
197
	while(1){
198 211
	req.data.id='U';
199 212
	req.data.rtr=1;
200
	periph[ADDR('U')].ev=0x01;
213
	periph[ADDR('U')].ev=0x02;
201 214
	snd_dtq(CanTx,req.msg);
202
	wai_flg(ev_periph, 0x01,TWF_ANDW, &flag);
215
	wai_flg(ev_periph, 0x02,TWF_ANDW, &flag);
203 216
	distance=periph[ADDR('U')].val;
204
	//dishorizontal=distance*cos(90-alpha/10);
217
	dly_tsk(10);
205 218
	}
206 219
	
207 220
}
221
void capt(){
222
	while(1){
223
	CanFrame req;
224
	int capteur;
225
	UINT flag;
226
	req.data.id='C';
227
	req.data.rtr=1;
228
	periph[ADDR('R')].ev=0x03;
229
	snd_dtq(CanTx, req.msg);
230
	wai_flg(ev_periph, 0x03, TWF_ANDW, &flag);
231
	capteur=periph[ADDR('C')].val;
232
	dly_tsk(20);
233
	}
234
	}
235
void feurouge(){
236
	while(1){
237
	CanFrame req;
238
	int feu;
239
	UINT flag;
240
	req.data.id='M';
241
	req.data.rtr=1;
242
	periph[ADDR('M')].ev=0x04;
243
	snd_dtq(CanTx, req.msg);
244
	wai_flg(ev_periph, 0x04, TWF_ANDW, &flag);
245
	feu=periph[ADDR('M')].val;
246
	dly_tsk(20);
247
	}
248
	}
249

  
208 250

  
209
void main()
210
{	
211
//	CanFrame comm;
251
void main()
252

  
253
{
254
	CanFrame comm;
255
		comm.data.id='T';
256
		comm.data.rtr=0;
257
		comm.data.val=120;
258
		snd_dtq(CanTx,comm.msg);
259
		dly_tsk(20);	
212 260
	ports_mcu();
213 261
    lcd_init();
214 262
	periph_init();
215 263
	periph_nom("#Mansour*");
216

  
217 264

  
218 265
    can_init();
219 266
    clavier_init(1);
......
221 268

  
222 269
	sta_cyc(ID_acqui);
223 270
	sta_tsk(ID_periph_rx);
224
//	comm.data.id='T';
225
//	comm.data.rtr=0;
226
//	comm.data.val=120;
227
//	snd_dtq(CanTx,comm.msg);
228
//	sta_tsk(ID_tourelle);
229
//	sta_tsk(ID_demarer);
230
//	sta_tsk(ID_roues);
231
//	sta_tsk(ID_distance_mur);
271

  
232 272
		sta_tsk(ID_tourelle);
233 273
    	sta_tsk(ID_demarrer);
234
	    
235 274
	    sta_tsk(ID_distance_mur);	
236 275
		dly_tsk(2000);
237 276
		sta_tsk(ID_roues);
277
		sta_tsk(ID_capt);
278
		sta_tsk(ID_feurouge);
238 279
	
239 280
    while(1)
240 281
    {

Also available in: Unified diff