Index: branch/porte/Emb_App.tws
===================================================================
--- branch/porte/Emb_App.tws	(revision 221)
+++ branch/porte/Emb_App.tws	(revision 222)
@@ -7,6 +7,7 @@
 [GENERAL_DATA]
 [BREAKPOINTS]
 [OPEN_WORKSPACE_FILES]
+"E:\tp_info6_2018_porte\tp_info6\bsp\periph.c" 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\conf_noyau.cfg" 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\crt0mr.a30" 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\Debug\mr308.inc" 
@@ -13,9 +14,10 @@
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\programme_principal_etud.c" 
 [WORKSPACE_FILE_STATES]
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\Debug\mr308.inc" 100 100 1430 351 0 2 
-"E:\tp_info6_2018_porte\tp_info6\Emb_App\conf_noyau.cfg" -541 203 1426 347 0 0 
+"E:\tp_info6_2018_porte\tp_info6\Emb_App\conf_noyau.cfg" 0 0 1426 347 0 0 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\crt0mr.a30" -8 -30 1596 539 1 3 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\programme_principal_etud.c" 50 50 1430 351 0 1 
+"E:\tp_info6_2018_porte\tp_info6\bsp\periph.c" 100 100 1430 351 0 4 
 [LOADED_PROJECTS]
 "EmbM32C87App" 
 [END]
Index: branch/porte/Emb_App/SessionM32C_E8a_system.ini
===================================================================
--- branch/porte/Emb_App/SessionM32C_E8a_system.ini	(revision 221)
+++ branch/porte/Emb_App/SessionM32C_E8a_system.ini	(revision 222)
@@ -25,4 +25,4 @@
 [Target]
 M32C E8a SYSTEM=Renesas Communications
 [USER_DATA]
-RESET=ff003c
+RESET=ff0042
Index: branch/porte/Emb_App/SessionM32C_E8a_system.hsf
===================================================================
--- branch/porte/Emb_App/SessionM32C_E8a_system.hsf	(revision 221)
+++ branch/porte/Emb_App/SessionM32C_E8a_system.hsf	(revision 222)
@@ -141,7 +141,7 @@
 "{55384715-F881-421C-A548-D7D1ABE158E1}PDMRWndInstanceKey0" "{WK_00000001_PDMR}EmbM32C87AppSessionM32C_E8a_system" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_EVAL_DENORMAL_MODE" "0" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_EVAL_ROUND_MODE" "0" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_0" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_0" "0000000000000044" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_1" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_10" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_11" "0000000000000000" 
@@ -148,13 +148,13 @@
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_12" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_13" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_14" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_15" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_16" "0000000000FF003C" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_17" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_18" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_19" "0000000000000700" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_2" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_20" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_15" "0000000000000512" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_16" "0000000000FF054A" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_17" "0000000000FFF800" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_18" "0000000000000B36" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_19" "000000000000086E" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_2" "0000000000000001" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_20" "0000000000004044" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_21" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_22" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_23" "0000000000000000" 
@@ -169,12 +169,12 @@
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_31" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_32" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_33" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_34" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_34" "000000000000036A" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_35" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_4" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_5" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_6" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_7" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_4" "0000000000000004" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_5" "0000000000000009" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_6" "0000000000000B6A" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_7" "0000000000000512" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_8" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_9" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_COUNT" "36" 
@@ -207,7 +207,15 @@
 "{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, Hex, 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" "Somme_ErreurRoues, 2, 0, P, Col, Hex, MA" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002" "Delta_Erreur, 2, 0, P, Col, Hex, MA" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0003" "ErreurRoues, 2, 0, P, Col, Hex, MA" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0003_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0004" "Bord_defaut, 2, 0, P, Col, Hex, MA" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0004_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "5" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth0" "120" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth1" "150" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth12" "200" 
@@ -310,9 +318,10 @@
 [WINDOW_POSITION_STATE_DATA_VD4]
 [WINDOW_Z_ORDER]
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\crt0mr.a30" 
+"E:\tp_info6_2018_porte\tp_info6\Emb_App\conf_noyau.cfg" 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\programme_principal_etud.c" 
 "E:\tp_info6_2018_porte\tp_info6\Emb_App\Debug\mr308.inc" 
-"E:\tp_info6_2018_porte\tp_info6\Emb_App\conf_noyau.cfg" 
+"E:\tp_info6_2018_porte\tp_info6\bsp\periph.c" 
 [TARGET_NAME]
 "M32C E8a SYSTEM" "" 0 
 [STATUSBAR_STATEINFO_VD1]
@@ -359,5 +368,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 90832792 1 "{00000000-0000-0000-C000-000000000046}" "" 
+"d:\profs\tp_info14_travail\tp_info14\emb_app\programme_principal_etud.c" 95 94889256 1 "{00000000-0000-0000-C000-000000000046}" "" 
 [END]
Index: branch/porte/Emb_App/programme_principal_etud.c
===================================================================
--- branch/porte/Emb_App/programme_principal_etud.c	(revision 221)
+++ branch/porte/Emb_App/programme_principal_etud.c	(revision 222)
@@ -124,16 +124,19 @@
 unsigned int Consigne_T=500; //Consigne de l'angle de la tourelle
 unsigned int valeur=0; //valeur transmise corrigé
 unsigned int Somme_Erreur=0, Erreur=0, Delta_Erreur=0, Erreur_pre=0;
-int Kp=1.5,	Kpr=1.6;	//Paramètre des PID tourelle et roues
-int Ki=4,	Kir=10;
+unsigned int ErreurRoues=0, ErreurRouesPre=0, Delta_ErreurRoues=0,Somme_ErreurRoues=0;
+int Kp=1.5,	Kpr=2;	//Paramètre des PID tourelle et roues
+int Ki=4,	Kir=30;
 int Kd=1.5,	Kdr=1;
-unsigned int Vitesse=42,Distance;
+int i;
+unsigned int Vitesse_final=35, Vitesse_commande=5, Distance;
 unsigned int Angle_R=0; //Angle des roues
-unsigned int ErreurRoues=0, ErreurRouesPre=0, Delta_ErreurRoues=0,Somme_ErreurRoues=0;
+unsigned int Info_capteur;
+unsigned int Bord_defaut=0, Distance_pre=660;
+
 
-void Asserv_T(){
+void Asserv_T(){	
 	
-	
 	//'T'/84/0x54 : Commande en vitesse de la tourelle portant le telemetre (en 1/10 de degre/secondes).
 	//'R'/82/0x52 : Lecture de l'angle effectif de la tourelle portant le telemetre (en 1/10 de degre).
 	CanFrame comm;
@@ -152,24 +155,29 @@
 		comm.data.val=valeur;
 		snd_dtq (CanTx,comm.msg);//Envoi de la commande
 		
-		dly_tsk(200);
+		dly_tsk(100);
 		}
 	}
 
+void Asserv_T_hc(){
+	
+	Erreur_pre=Erreur;
+	Erreur=Consigne_T-Angle_T;
+	Delta_Erreur=Erreur-Erreur_pre;
+	Somme_Erreur+=Erreur;
+	
+	if(Angle_T!=Consigne_T)
+		valeur=Kp*Erreur+Kd*Delta_Erreur+(1/Ki)*Somme_Erreur;//correction de l'angle par handler cyclique de la tourelle
+	}
+
 void Asserv_R(){
 	
 	//'D'/68/0x44 : Commande de l'angle des roues directrices (en 1/10 de degre).
-	//'U'/85/0x55 : Distance mesuree par le telemetre (1/100 de metre).
 	CanFrame comm;
 	CanFrame demande;
 	CanFrame reponse;
+	
 	while(1){
-			
-		demande.data.id='U'; 
-		demande.data.rtr=1;
-	
-		snd_dtq (CanTx,demande.msg); // Interrogation du peripherique
-		Distance=periph[ADDR('U')].val; // contient la valeur de retour du simulateur.
 		
 		comm.data.id='D'; //Commande de l'angle des roues
 		comm.data.rtr=0; 
@@ -176,10 +184,22 @@
 		comm.data.val=Angle_R;
 		snd_dtq (CanTx,comm.msg);//Envoi de la commande
 				
-		dly_tsk(5);
+		dly_tsk(4);
 		}
 	}
 
+void Asserv_R_hc(){	
+	
+	ErreurRouesPre=ErreurRoues;
+	ErreurRoues=660-Distance;
+	Delta_ErreurRoues=ErreurRoues-ErreurRouesPre;
+	Somme_ErreurRoues+=ErreurRoues;
+	
+	if(Distance != 660 && Bord_defaut == 0)
+		Angle_R=-1*(Kpr*ErreurRoues+Kdr*Delta_Erreur+(1/Kir)*Somme_ErreurRoues);//correction de l'angle par handler cyclique des roues
+	}
+
+
 void Asserv_V(){
 	
 	//'V'/86/0x56 : Commande en vitesse des roues motrices du vehicule (en radian /secondes).
@@ -188,37 +208,74 @@
 	CanFrame reponse;
 	while(1){		
 		
-		dly_tsk(2600);
+		dly_tsk(3000);
 		comm.data.id='V'; //Commande de l'angle des roues
-		comm.data.rtr=0; 
-		comm.data.val=Vitesse;	
+		comm.data.rtr=0;
+		
+		//Rampe de vitesse au démarrage
+		for(i=0;i++;Vitesse_final < Vitesse_commande){
+			comm.data.val=Vitesse_final-Vitesse_commande+i;
+			snd_dtq (CanTx,comm.msg);		//Envoi de la commande de vitesse
+			dly_tsk(100);
+		}
+		
+		comm.data.val=Vitesse_final;	
 		snd_dtq (CanTx,comm.msg);//Envoi de la commande de vitesse
 				
-		dly_tsk(500);
+		dly_tsk(200);
 		}
 	}
-
-void Asserv_T_hc(){
+/*
+void Capteur(){
 	
-	Erreur_pre=Erreur;
-	Erreur=Consigne_T-Angle_T;
-	Delta_Erreur=Erreur-Erreur_pre;
-	Somme_Erreur+=Erreur;
+	//'C'/67/0x43 : Informations sur le dernier capteur touche :
+	//  8 bits de poids faible : numero du capteur
+	//  8 bits de poids fort : couleur ('C','R','J','B' ou 'V')
+	CanFrame comm;
+	CanFrame demande;
+	CanFrame reponse;
 	
-	if(Angle_T!=Consigne_T)
-		valeur=Kp*Erreur+Kd*Delta_Erreur+(1/Ki)*Somme_Erreur;//correction de l'angle par handler cyclique de la tourelle
+	while(1){
+		
+		demande.data.id='C';
+		demande.data.rtr=1;
+		snd_dtq (CanTx,demande.msg); 			// Interrogation du peripherique sur les donnees du dernier capteur touché.
+		Info_capteur=periph[ADDR('C')].val>>2; 		// contient la valeur de retour du simulateur sur le dernier capteur touché.
 	}
+	
+	
+}*/
 
-void Asserv_R_hc(){	
+void Distance_bord(){
 	
-	ErreurRouesPre=ErreurRoues;
-	ErreurRoues=660-Distance;
-	Delta_ErreurRoues=ErreurRoues-ErreurRouesPre;
-	Somme_ErreurRoues+=ErreurRoues;
+	//'U'/85/0x55 : Distance mesuree par le telemetre (1/100 de metre).
+	CanFrame comm;
+	CanFrame demande;
+	CanFrame reponse;
 	
-	if(Distance!=660)
-		Angle_R=-Kpr*ErreurRoues+Kdr*Delta_Erreur+(1/Kir)*Somme_ErreurRoues;//correction de l'angle par handler cyclique des roues
+	while(1){
+		
+		demande.data.id='U';
+		demande.data.rtr=1;
+
+		snd_dtq (CanTx,demande.msg); // Interrogation du peripherique sur la distance mesure par le telemetre.
+		Distance=periph[ADDR('U')].val; // contient la valeur de retour du simulateur sur la distance mesuré par le telemetre.
+		
+		if(Distance > 660+300){
+			Bord_defaut=1;
+		}
+		else if(Distance < 660-300){
+			Bord_defaut=1;
+		}
+		else{
+			Bord_defaut=0;
+		}
+		Distance_pre=Distance;
+		
+		dly_tsk(10);
 	}
+	
+}
 
 void main()
 {
@@ -240,7 +297,9 @@
 	sta_tsk(ID_Asserv_R);
 	sta_cyc(ID_Asserv_R_hc);
 	
-	sta_tsk(ID_Asserv_V);
+	sta_tsk(ID_Asserv_V);
+	
+	sta_tsk(ID_Distance_bord);
 
     while(1)
     {
Index: branch/porte/Emb_App/conf_noyau.cfg
===================================================================
--- branch/porte/Emb_App/conf_noyau.cfg	(revision 221)
+++ branch/porte/Emb_App/conf_noyau.cfg	(revision 222)
@@ -66,7 +66,7 @@
 	name	= ID_Asserv_T;
 	stack_size	= 256;
 	stack_section	= stack;
-	priority	= 4;
+	priority	= 5;
 	initial_start	= OFF;
 	exinf	= 0x0;
 };
@@ -86,11 +86,21 @@
 	name	= ID_Asserv_V;
 	stack_size	= 256;
 	stack_section	= stack;
-	priority	= 4;
+	priority	= 6;
 	initial_start	= OFF;
 	exinf	= 0x0;
 };
 
+task[]{
+	entry_address	= Distance_bord();
+	name	= ID_Distance_bord;
+	stack_size	= 256;
+	stack_section	= stack;
+	priority	= 7;
+	initial_start	= OFF;
+	exinf	= 0x0;
+};
+
 flag[]{
 	name	= ev_bus_fin_tr;
 	initial_pattern	= 0x0000;
@@ -155,7 +165,6 @@
 	phs_counter	= 0x0;
 };
 
-
 vdataqueue[]{
 	name	= QdmTouche;
 	wait_queue	= TA_TFIFO;
