Index: branch/najib_idzim/tp_info6/Emb_App.tws
===================================================================
--- branch/najib_idzim/tp_info6/Emb_App.tws	(revision 260)
+++ branch/najib_idzim/tp_info6/Emb_App.tws	(revision 261)
@@ -9,11 +9,15 @@
 [OPEN_WORKSPACE_FILES]
 "E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\conf_noyau.cfg" 
 "E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\crt0mr.a30" 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\Debug\mr308.inc" 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\Debug\mrtable.a30" 
 "E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\programme_principal_etud.c" 
 [WORKSPACE_FILE_STATES]
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\Debug\mr308.inc" 75 75 1430 351 0 3 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\Debug\mrtable.a30" 100 100 1430 351 0 4 
 "E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\conf_noyau.cfg" 0 0 1596 539 0 2 
-"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\crt0mr.a30" 25 25 1426 347 0 1 
-"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\programme_principal_etud.c" -8 -30 1596 539 1 0 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\crt0mr.a30" -8 -30 1596 643 1 1 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\programme_principal_etud.c" 0 0 1596 539 0 0 
 [LOADED_PROJECTS]
 "EmbM32C87App" 
 [END]
Index: branch/najib_idzim/tp_info6/Emb_App/conf_noyau.cfg
===================================================================
--- branch/najib_idzim/tp_info6/Emb_App/conf_noyau.cfg	(revision 260)
+++ branch/najib_idzim/tp_info6/Emb_App/conf_noyau.cfg	(revision 261)
@@ -37,7 +37,7 @@
 task[]{
 	entry_address	= main();
 	name	= ID_main;
-	stack_size	= 512;
+	stack_size	= 1024;
 	stack_section	= stack;
 	priority	= 8;
 	initial_start	= ON;
@@ -70,6 +70,15 @@
 	initial_start	= OFF;
 	exinf	= 0x0;
 };
+task[]{
+	entry_address	= asserv_direction();
+	name	= ID_asserv_direction;
+	stack_size	= 1024;
+	stack_section	= stack;
+	priority	= 6;
+	initial_start	= OFF;
+	exinf	= 0x0;
+};
 
 
 
Index: branch/najib_idzim/tp_info6/Emb_App/EmbM32C87App.tps
===================================================================
--- branch/najib_idzim/tp_info6/Emb_App/EmbM32C87App.tps	(revision 260)
+++ branch/najib_idzim/tp_info6/Emb_App/EmbM32C87App.tps	(revision 261)
@@ -18,7 +18,7 @@
 "SessionM32C_E8a_system" 
 [GENERAL_DATA_PROJECT]
 [GENERAL_DATA_CONFIGURATION_Debug]
-"PROJECT_FILES_MODIFIED_DATA_TAG" "FALSE" 
+"PROJECT_FILES_MODIFIED_DATA_TAG" "TRUE" 
 [SESSIONS_Debug]
 "DefaultSession" 
 "SessionM32C_E8a_system" 
Index: branch/najib_idzim/tp_info6/Emb_App/SessionM32C_E8a_system.hsf
===================================================================
--- branch/najib_idzim/tp_info6/Emb_App/SessionM32C_E8a_system.hsf	(revision 260)
+++ branch/najib_idzim/tp_info6/Emb_App/SessionM32C_E8a_system.hsf	(revision 261)
@@ -207,7 +207,9 @@
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH" "c,buff,n,rx,flag," 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0000" "distance, 2, 0, P, Col, Dec, MA" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0000_SCOPE" "Current Scope," 
-"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "1" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001" "distanceMesure, 10, 0, P, Col, Hex, N" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "2" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth0" "120" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth1" "150" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth12" "200" 
@@ -277,14 +279,14 @@
 0 
 [WINDOW_POSITION_STATE_DATA_VD1]
 "Help" "TOOLBAR 0" 59419 2 4 "0.00" 0 0 0 0 0 17 0 "" "0.0" 
-"{WK_00000001_CmdLine}" "WINDOW" 59422 0 1 "0.07" 365 0 0 350 200 17 0 "32771|32772|32778|<<separator>>|32773|32774|<<separator>>|32820|<<separator>>|32801|32824" "0.0" 
+"{WK_00000001_CmdLine}" "WINDOW" 59422 0 1 "0.07" 261 0 0 350 200 17 0 "32771|32772|32778|<<separator>>|32773|32774|<<separator>>|32820|<<separator>>|32801|32824" "0.0" 
 "{WK_00000001_DISASSEMBLY}" "WINDOW" 0 0 0 "0.00" 0 -4 -30 948 486 9 0 "" "0.0" 
 "{WK_00000001_EVENT}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 0 "0.68" 365 0 0 350 200 2065 0 "32774|32775|32777|<<separator>>|32780|<<separator>>" "0.0" 
 "{WK_00000001_MEMORY}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 1 "0.23" 365 2 -1 350 200 2065 0 "42202|42203|42204|42233|<<separator>>|42206|42205|42230|42229|42207|<<separator>>|42208|42209|42210|49076|42228|42227|<<separator>>|42231|42232|42234|42235|<<separator>>|42211|<<separator>>|32796|32797" "0.0" 
-"{WK_00000001_OUTPUT}" "WINDOW" 59422 0 2 "0.56" 365 0 0 350 200 18 0 "36756|36757|36758|36759|<<separator>>|36746|36747|<<separator>>|39531|<<separator>>|39500|39534|<<separator>>|36687" "0.0" 
-"{WK_00000001_PDMR}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 3 "0.24" 365 0 0 350 200 18 0 "47300|47301|47302|47303|47304|47305|47314|47306|47307|47308|47311|47312|47313|42211|42509|42303" "0.0" 
+"{WK_00000001_OUTPUT}" "WINDOW" 59422 0 2 "0.59" 261 0 0 350 200 18 0 "36756|36757|36758|36759|<<separator>>|36746|36747|<<separator>>|39531|<<separator>>|39500|39534|<<separator>>|36687" "0.0" 
+"{WK_00000001_PDMR}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 3 "0.16" 261 0 0 350 200 18 0 "47300|47301|47302|47303|47304|47305|47314|47306|47307|47308|47311|47312|47313|42211|42509|42303" "0.0" 
 "{WK_00000001_REGISTERS}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59421 0 0 "1.00" 236 0 0 350 200 2065 0 "" "0.0" 
-"{WK_00000001_WATCH}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 0 "0.20" 365 0 0 350 200 18 0 "32781|32783|<<separator>>|32771|32772|32773|<<separator>>|32786|<<separator>>|32810|32811" "0.0" 
+"{WK_00000001_WATCH}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 0 "0.24" 261 0 0 350 200 18 0 "32781|32783|<<separator>>|32771|32772|32773|<<separator>>|32786|<<separator>>|32810|32811" "0.0" 
 "{WK_00000002_WORKSPACE}" "WINDOW" 59420 0 0 "1.00" 308 0 0 350 200 18 0 "" "0.0" 
 "{WK_TB00000001_STANDARD}" "TOOLBAR 0" 59419 0 2 "0.00" 0 0 0 0 0 18 0 "" "0.0" 
 "{WK_TB00000002_EDITOR}" "TOOLBAR 0" 59419 0 0 "0.00" 0 0 0 0 0 18 0 "" "0.0" 
@@ -309,9 +311,11 @@
 [WINDOW_POSITION_STATE_DATA_VD3]
 [WINDOW_POSITION_STATE_DATA_VD4]
 [WINDOW_Z_ORDER]
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\crt0mr.a30" 
 "E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\programme_principal_etud.c" 
-"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\crt0mr.a30" 
 "E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\conf_noyau.cfg" 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\Debug\mrtable.a30" 
+"E:\tp_info6_2018_najib_idzim\tp_info6\Emb_App\Debug\mr308.inc" 
 [TARGET_NAME]
 "M32C E8a SYSTEM" "" 0 
 [STATUSBAR_STATEINFO_VD1]
@@ -358,5 +362,5 @@
 [FLASH_DETAILS]
 "" 0 0 "" 0 "" 0 0 "" 0 0 0 0 0 0 0 "" "" "" "" "" 
 [BREAKPOINTS]
-"d:\profs\tp_info14_travail\tp_info14\emb_app\programme_principal_etud.c" 95 101005976 1 "{00000000-0000-0000-C000-000000000046}" "" 
+"d:\profs\tp_info14_travail\tp_info14\emb_app\programme_principal_etud.c" 95 99813168 1 "{00000000-0000-0000-C000-000000000046}" "" 
 [END]
Index: branch/najib_idzim/tp_info6/Emb_App/programme_principal_etud.c
===================================================================
--- branch/najib_idzim/tp_info6/Emb_App/programme_principal_etud.c	(revision 260)
+++ branch/najib_idzim/tp_info6/Emb_App/programme_principal_etud.c	(revision 261)
@@ -126,7 +126,8 @@
 unsigned short disMur();                  // lit distance du vehicule au mur en cm
 void vitesseVoiture(int vitesse);         // commande vitesse du vehicule en rad/sec
 void cmdRoue(unsigned short angle);       // commande angle des roues en 10e de degre
-void asserv_direction();
+int lireCapt();
+char typeCapteur();
 
 unsigned short distance = 56;
 
@@ -136,21 +137,28 @@
     lcd_init();
 	periph_init();
 	periph_nom("#Ferrari");
-
+          
     can_init();
     clavier_init(1);
 	capture_init();
 
 	sta_cyc(ID_acqui);
-	sta_tsk(ID_periph_rx);
+	sta_tsk(ID_periph_rx); // tache de tri de reponse du simulateur
 	
 	
 	
-    vitesseVoiture(3);
+    
 	sta_tsk(ID_asserv_tour);
+	dly_tsk(1000);
+	
+	sta_tsk(ID_asserv_direction);
+	dly_tsk(1000);
+	
+	vitesseVoiture(35);
 	
     while(1)
     {
+	
 		
     }
 }
@@ -165,6 +173,23 @@
 
 
 
+
+// fonction de tourelle
+unsigned short posTourelle()
+{
+	CanFrame requete;
+	UINT flag;
+	
+	requete.data.id = 'R';
+	requete.data.rtr = 1;          // Requete de lecture 
+	periph[ADDR('R')].ev =0x01;
+	snd_dtq(CanTx, requete.msg);
+	
+	wai_flg(ev_periph, 0x01, TWF_ANDW, &flag);
+	
+	return  periph[ADDR('R')].val; 
+}
+
 void vitesseTourelle(int vitesse)
 {
 	CanFrame comm;
@@ -176,6 +201,46 @@
 	snd_dtq (CanTx,comm.msg);
 }
 
+
+unsigned short disTelem()
+{
+	CanFrame requete;
+	UINT flag;
+	
+	requete.data.id = 'U';
+	requete.data.rtr = 1;          // Requete de lecture 
+	periph[ADDR('U')].ev =0x02;
+	snd_dtq(CanTx, requete.msg);
+	
+	wai_flg(ev_periph, 0x02, TWF_ANDW, &flag);
+	
+	return  periph[ADDR('U')].val; 
+}
+
+unsigned short disMur()
+{
+	unsigned short longeurTelem, pos, distanceMur; 
+	
+	longeurTelem = disTelem();
+	pos = posTourelle();
+	
+	distanceMur = longeurTelem * sin( 3.14*(pos/10)/180.0 );
+	return distanceMur; 
+}
+
+
+
+
+
+
+
+
+
+
+
+// fonction direction et vitesse vehicule
+
+
 void vitesseVoiture(int vitesse)
 {
 	CanFrame comm;
@@ -187,25 +252,65 @@
 	snd_dtq (CanTx,comm.msg);
 }
 
-unsigned short posTourelle()
+void cmdRoue(unsigned short angle)
 {
-	CanFrame requete, reponse;
+	CanFrame comm;
 	
-	requete.data.id = 'R';
-	requete.data.rtr = 1; // Requete de lecture 
+	comm.data.id = 'D';
+	comm.data.rtr = 0;     //ecriture
+	comm.data.val = angle;
+	
+	snd_dtq (CanTx,comm.msg);
+	
+}
+
+
+
+// capreur
+
+int lireCapt()
+{
+	CanFrame requete;
+	UINT flag;
+	
+	requete.data.id = 'C';
+	requete.data.rtr = 1;          // Requete de lecture 
+	periph[ADDR('U')].ev =0x03;
 	snd_dtq(CanTx, requete.msg);
 	
-	rcv_dtq(CanRx, &reponse.msg);
+	wai_flg(event, (FLGPTN) 0x0007, TWF_ANDW, &flag);
+	//wai_flg(ev_periph, 0x03, TWF_ANDW, &flag);
 	
-	return reponse.data.val;
+	return  periph[ADDR('C')].val;
 }
 
+char typeCapteur()
+{
+	int lsb, msb;
+	int capteur = lireCapt();
+	char val;
+	
+	lsb &= 0b00001111;
+	msb &= 0b11110000; 
+	
+	if (lsb == 6)
+	{
+		if (msb == 'C')
+		{
+			return 'C';
+		}
+	}
+	return 0;
+}
+
+// les asservissement
+
 void asserv_tour()
 {
 	unsigned short posCons,posSortie;
 	short k,vit;
 	
-	k = 5;  //gain def experimentalement
+	k = 3;         //gain definni experimentalement
 	posCons = 450;
 	
 	while(1)
@@ -219,63 +324,30 @@
 
 }
 
-unsigned short disTelem()
-{
-	CanFrame requete, reponse;
-	
-	requete.data.id = 'U';
-	requete.data.rtr = 1; // Requete de lecture 
-	snd_dtq(CanTx, requete.msg);
-	
-	rcv_dtq(CanRx, &reponse.msg);
-	
-	return reponse.data.val; 
-}
 
-unsigned short disMur()
+void asserv_direction()
 {
-	unsigned short longeurTelem, distanceMur; 
-	longeurTelem = disTelem();
-	distanceMur = longeurTelem * cos( 90 - posTourelle()/10 );
-	return distanceMur; 
-}
-
-void cmdRoue(unsigned short angle)
-{
-	CanFrame comm;
+	long distanceCons , distanceMesure, k;
+	int angle;
 	
-	comm.data.id = 'D';
-	comm.data.rtr = 0;     //ecriture
-	comm.data.val = angle;
 	
-	snd_dtq (CanTx,comm.msg);
+	k = 2;                //gain definni experimentalement
+	distanceCons = 500; //disMur(); //Pos initiale milieu de piste
 	
-}
-
-void asserv_direction()
-{
-	unsigned short distance = disMur();
-/*	short k,vit;
-	
-	k = 14;  //gain definni experimentalement
-	posCons = 450;
 	while(1)
 	{
-		posSortie = posTourelle();         
-		vit = k*( posCons - posSortie);  //correcteur P
-		vitesseTourelle(vit);	
-	}*/
-	if ( distance <45)
-	{
-		cmdRoue(-100);
+		if ( typeCapteur() == 'C')
+		{
+			cmdRoue(0);
+		}
+		else{
+			
+			distanceMesure = disMur();        
+			angle = -k*( distanceCons - distanceMesure );  //correcteur P
+			cmdRoue(angle);
+			
+			
+		}
+		dly_tsk(25);
 	}
-	else if (distance == 45)
-	{
-		cmdRoue(0);
-	}
-	else
-	{
-		cmdRoue(100);
-	}
-	
 }
