From 2103417e66c65f09ea85f82d96f5f5a2a6f3bd64 Mon Sep 17 00:00:00 2001
From: Sarra Ayed <sarrah.ayed@gmail.com>
Date: Tue, 3 Mar 2020 15:15:16 -0500
Subject: [PATCH] ajout du moteur de la tourelle

---
 Device/list_motor.c | 82 ++++++++++++++++++++++++++-------------------
 Device/list_motor.h |  3 +-
 2 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/Device/list_motor.c b/Device/list_motor.c
index b18aa65..337e5a5 100644
--- a/Device/list_motor.c
+++ b/Device/list_motor.c
@@ -3,6 +3,10 @@
 #include "list_motor.h"
 
 motor_t gm6020;
+
+motor_t gm6020_up;
+motor_t gm6020_down;
+
 motor_t m3508_frontleft;
 motor_t m3508_frontright;
 motor_t m3508_backleft;
@@ -22,40 +26,48 @@ const pid_struct_t GM6020_pid_pos = { //A VERIFIER
 		0, 12, 3, 5, 10000, 10000
 	};
 
-void motors_init(void){
-	gm6020.type = GM6020;
-	gm6020.can_info.can_id = 0;
-	gm6020.can_info.tx_id = 1;
-	gm6020.can_info.rx_id = 0x205; 
-	gm6020.pid_pos = GM6020_pid_pos;
-	gm6020.pid_speed = GM6020_pid_speed;
-	
-	m3508_frontleft.type = M3508;
-	m3508_frontleft.can_info.can_id = 0;
-	m3508_frontleft.can_info.tx_id = 0;
-	m3508_frontleft.can_info.rx_id = 0x201; 
-	m3508_frontleft.pid_pos = M3508_pid_pos;
-	m3508_frontleft.pid_speed = M3508_pid_speed;
-	
-	m3508_frontright.type = M3508;
-	m3508_frontright.can_info.can_id = 0;
-	m3508_frontright.can_info.tx_id = 0;
-	m3508_frontright.can_info.rx_id = 0x202; 
-	m3508_frontright.pid_pos = M3508_pid_pos;
-	m3508_frontright.pid_speed = M3508_pid_speed;
-	
-	m3508_backleft.type = M3508;
-	m3508_backleft.can_info.can_id = 0;
-	m3508_backleft.can_info.tx_id = 0;
-	m3508_backleft.can_info.rx_id = 0x203; 
-	m3508_backleft.pid_pos = M3508_pid_pos;
-	m3508_backleft.pid_speed = M3508_pid_speed;
-	
-	m3508_backright.type = M3508;
-	m3508_backright.can_info.can_id = 0;
-	m3508_backright.can_info.tx_id = 0;
-	m3508_backright.can_info.rx_id = 0x204; 
-	m3508_backright.pid_pos = M3508_pid_pos;
-	m3508_backright.pid_speed = M3508_pid_speed;
+
+// void motors_init (motor_t motor, int motor_tx_id, int motor_rx_id, enum motors mot){
+// 	switch ()
+
+// 	motor.type = GM6020;
+// 	motor.can_info.can_id = 0;
+// 	motor.can_info.tx_id = 1;
+// 	motor.can_info.rx_id = 0x205; 
+// 	motor.pid_pos = GM6020_pid_pos;
+// 	motor.pid_speed = GM6020_pid_speed;
+// }
+//extern motor_t gm6020_down;
+//extern motor_t gm6020_up;
+
+
+void motors_init(motor_t motor,  int motor_rx_id, enum motors mtr){
+	switch (mtr){
+		case GM6020 :
+			motor.type = GM6020 ;
+			motor.pid_pos = GM6020_pid_pos;
+			motor.pid_speed = GM6020_pid_speed;
+			motor.can_info.tx_id = 1;
+			break;
+		case M3508 :
+			motor.type = M3508 ;
+			motor.pid_pos = M3508_pid_pos;
+			motor.pid_speed = M3508_pid_speed;
+			motor.can_info.tx_id = 0;
+			break;
+		default :
+			break;
+	}
+	motor.can_info.can_id = 0;
+	motor.can_info.rx_id = motor_rx_id ;
+}
+
+void motors_all_init(void){
+	motors_init(gm6020_down,  0x206, GM6020);
+	motors_init(gm6020_up,  0x205, GM6020);
+	motors_init(m3508_frontleft,  0x204, M3508);
+	motors_init(m3508_frontright,  0x203, M3508);
+	motors_init(m3508_backleft,  0x202, M3508);
+	motors_init(m3508_backright,  0x201, M3508);
 }
 
diff --git a/Device/list_motor.h b/Device/list_motor.h
index 2090545..2ad2340 100644
--- a/Device/list_motor.h
+++ b/Device/list_motor.h
@@ -18,4 +18,5 @@ extern const pid_struct_t M3508_pid_pos;
 extern const pid_struct_t GM6020_pid_speed;
 extern const pid_struct_t GM6020_pid_pos;
 
-void motors_init(void);
+void motors_all_init(void);
+void motors_init(motor_t motor,  int motor_rx_id, enum motors mtr);
-- 
GitLab