From 67bea93e3c554dbd0489fa5c6caaecf7b63077f8 Mon Sep 17 00:00:00 2001
From: Marc Antoine Hien <marc-antoine.hien@polymtl.ca>
Date: Tue, 9 Mar 2021 17:36:26 -0500
Subject: [PATCH] ajout verification controller neutre avant boucle infinie

---
 Inc/traitement.h |  3 +++
 Src/main.c       | 10 ++++++++++
 Src/traitement.c | 28 ++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/Inc/traitement.h b/Inc/traitement.h
index 83754f0..936f987 100644
--- a/Inc/traitement.h
+++ b/Inc/traitement.h
@@ -36,4 +36,7 @@ void chassis_consigne(double Vx, double Vy, double W);
 /*Effectue le suivi automatique des cibles */
 void auto_follow_target(void);
 
+/*Retourne true si le controller est a une position neutre*/
+bool isControllerNeutral(void);
+
 #endif
diff --git a/Src/main.c b/Src/main.c
index 2043d57..1bb5dc8 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -113,11 +113,21 @@ int main(void)
 	extern motor_t motors[MAX_MOTORS];
 	extern pilote_t pilote;
 	extern jetson_t jetson;
+	extern uint32_t signOfLife_Receiver_RadioController_tick;
 	piloteInit(PILOTE_ANTONIN);
   /* USER CODE END 2 */
 
   /* Infinite loop */
   /* USER CODE BEGIN WHILE */
+	
+	while(1){
+		
+	if(signOfLife_Receiver_RadioController_tick !=0 ){
+		if(isControllerNeutral()){
+			break;
+		}
+	}
+	}
   while (1)
   {
 		signOfLife(); //LEDs BLINK
diff --git a/Src/traitement.c b/Src/traitement.c
index 4b8ea4e..b266c29 100644
--- a/Src/traitement.c
+++ b/Src/traitement.c
@@ -30,6 +30,34 @@ void traitement_pids_compute(){
 	}
 }
 
+/*Returns true if controller is in neutral state*/
+bool isControllerNeutral(){
+	
+	if(receiver_RadioController.data.ch1_float != 0){
+		return false;
+	}
+	if(receiver_RadioController.data.ch2_float != 0){
+		return false;
+	}
+	if(receiver_RadioController.data.ch3_float != 0){
+		return false;
+	}
+	if(receiver_RadioController.data.ch4_float != 0){
+		return false;
+	}
+	if(receiver_RadioController.data.sw1 != 1){
+		return false;
+	}
+	if(receiver_RadioController.data.sw2 != 1){
+		return false;
+	}
+	/*if(receiver_RadioController.data.wheel != 0){
+		return false;
+	}*/
+	return true;
+}
+
+
 /* Fonctions qui fait les liens entre les entrées (capteurs, radio controller, CV, ...) et les sorties (consignes moteurs), on peut créer plusieurs traitements */
 void traitement_1(){
 	
-- 
GitLab