Browse Source

clean project

Yohan Simard 3 years ago
parent
commit
c8ea3f3a91
10 changed files with 138 additions and 187 deletions
  1. 9
    26
      MDK-ARM/Project.uvoptx
  2. 10
    10
      MyDrivers/ADC.c
  3. 40
    74
      MyDrivers/Timer.c
  4. 14
    14
      Services/DCMotor.c
  5. 11
    11
      Services/DCMotor.h
  6. 15
    15
      Services/IncrementalEncoder.h
  7. 2
    1
      Services/ServoMotor.c
  8. 14
    13
      Src/Orientation.c
  9. 8
    8
      Src/Roll.c
  10. 15
    15
      Src/main.c

+ 9
- 26
MDK-ARM/Project.uvoptx View File

@@ -75,7 +75,7 @@
75 75
       <OPTFL>
76 76
         <tvExp>1</tvExp>
77 77
         <tvExpOptDlg>0</tvExpOptDlg>
78
-        <IsCurrentTarget>1</IsCurrentTarget>
78
+        <IsCurrentTarget>0</IsCurrentTarget>
79 79
       </OPTFL>
80 80
       <CpuCode>18</CpuCode>
81 81
       <DebugOpt>
@@ -352,7 +352,7 @@
352 352
       <OPTFL>
353 353
         <tvExp>1</tvExp>
354 354
         <tvExpOptDlg>0</tvExpOptDlg>
355
-        <IsCurrentTarget>0</IsCurrentTarget>
355
+        <IsCurrentTarget>1</IsCurrentTarget>
356 356
       </OPTFL>
357 357
       <CpuCode>18</CpuCode>
358 358
       <DebugOpt>
@@ -397,7 +397,7 @@
397 397
         <SetRegEntry>
398 398
           <Number>0</Number>
399 399
           <Key>DLGDARM</Key>
400
-          <Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=1554,213,1920,450,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=129,555,687,1080,0)(121=924,444,1482,969,1)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=150,46,938,969,0)(133=-13,526,775,1449,1)(160=1046,190,1640,699,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=130,96,930,1019,0)(151=127,38,927,961,0)</Name>
400
+          <Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=1554,213,1920,450,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=129,555,687,1080,0)(121=924,444,1482,969,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=150,46,938,969,0)(133=0,157,788,1080,0)(160=1046,190,1640,699,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=130,96,930,1019,0)(151=127,38,927,961,0)</Name>
401 401
         </SetRegEntry>
402 402
         <SetRegEntry>
403 403
           <Number>0</Number>
@@ -430,24 +430,7 @@
430 430
           <Name>-U-O142 -O2254 -S0 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
431 431
         </SetRegEntry>
432 432
       </TargetDriverDllRegistry>
433
-      <Breakpoint>
434
-        <Bp>
435
-          <Number>0</Number>
436
-          <Type>0</Type>
437
-          <LineNumber>51</LineNumber>
438
-          <EnabledFlag>1</EnabledFlag>
439
-          <Address>134221038</Address>
440
-          <ByteObject>0</ByteObject>
441
-          <HtxType>0</HtxType>
442
-          <ManyObjects>0</ManyObjects>
443
-          <SizeOfObject>0</SizeOfObject>
444
-          <BreakByAccess>0</BreakByAccess>
445
-          <BreakIfRCount>1</BreakIfRCount>
446
-          <Filename>..\Src\Display.c</Filename>
447
-          <ExecCommand></ExecCommand>
448
-          <Expression>\\NUCLEO_F103RB\../Src/Display.c\51</Expression>
449
-        </Bp>
450
-      </Breakpoint>
433
+      <Breakpoint/>
451 434
       <WatchWindow1>
452 435
         <Ww>
453 436
           <count>0</count>
@@ -503,8 +486,8 @@
503 486
         <periodic>1</periodic>
504 487
         <aLwin>0</aLwin>
505 488
         <aCover>0</aCover>
506
-        <aSer1>1</aSer1>
507
-        <aSer2>1</aSer2>
489
+        <aSer1>0</aSer1>
490
+        <aSer2>0</aSer2>
508 491
         <aPa>0</aPa>
509 492
         <viewmode>1</viewmode>
510 493
         <vrSel>0</vrSel>
@@ -513,12 +496,12 @@
513 496
         <AscS1>0</AscS1>
514 497
         <AscS2>0</AscS2>
515 498
         <AscS3>0</AscS3>
516
-        <aSer3>1</aSer3>
499
+        <aSer3>0</aSer3>
517 500
         <eProf>0</eProf>
518
-        <aLa>1</aLa>
501
+        <aLa>0</aLa>
519 502
         <aPa1>0</aPa1>
520 503
         <AscS4>0</AscS4>
521
-        <aSer4>1</aSer4>
504
+        <aSer4>0</aSer4>
522 505
         <StkLoc>0</StkLoc>
523 506
         <TrcWin>0</TrcWin>
524 507
         <newCpu>0</newCpu>

+ 10
- 10
MyDrivers/ADC.c View File

@@ -4,23 +4,23 @@
4 4
 const float MAX_VOLTS = 3.3;
5 5
 const float MAX_CONVERTED_VALUE = 4095.0;
6 6
 
7
-void ADC_conf(ADC_TypeDef *adc) 
7
+void ADC_conf(ADC_TypeDef *adc)
8 8
 {
9 9
 	if (adc == ADC1) {
10 10
 		LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
11 11
 	} else if (adc == ADC2) {
12 12
 		LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC2);
13 13
 	}
14
-	
14
+
15 15
 	// Division de la frequence
16 16
 	RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
17
-	
18
-	// Fixe le nombre de conversion à 1
19
-	adc->SQR1 &= ADC_SQR1_L; 
20
-	
21
-	 // Calibration
17
+
18
+	// Fixe le nombre de conversion � 1
19
+	adc->SQR1 &= ADC_SQR1_L;
20
+
21
+	 // Calibration (ne fonctionne pas, mais pas necessaire donc ok)
22 22
 //	adc->CR2 |= ADC_CR2_CAL_Msk;
23
-//	while ((adc->CR2 & ADC_CR2_CAL_Msk));	
23
+//	while ((adc->CR2 & ADC_CR2_CAL_Msk));
24 24
 }
25 25
 
26 26
 
@@ -32,9 +32,9 @@ void ADC_start(ADC_TypeDef *adc)
32 32
 uint16_t ADC_readRaw(ADC_TypeDef *adc, int channel)
33 33
 {
34 34
 		// Indique la voie a convertir
35
-		adc->SQR3 = channel; 
35
+		adc->SQR3 = channel;
36 36
 		// Lancement de la conversion
37
-	  adc->CR2 |= ADC_CR2_ADON; 
37
+	  adc->CR2 |= ADC_CR2_ADON;
38 38
     while(!(adc->SR & ADC_SR_EOC)) {}
39 39
 
40 40
     return adc->DR & ADC_DR_DATA_Msk;

+ 40
- 74
MyDrivers/Timer.c View File

@@ -10,10 +10,10 @@
10 10
 
11 11
 // variable pointeur de fonction permettant de m�moriser le callback � appeler depuis
12 12
 // le handler d'IT
13
-void (*it_callback_TIM1)(void); 
14
-void (*it_callback_TIM2)(void); 
15
-void (*it_callback_TIM3)(void); 
16
-void (*it_callback_TIM4)(void); 
13
+void (*it_callback_TIM1)(void);
14
+void (*it_callback_TIM2)(void);
15
+void (*it_callback_TIM3)(void);
16
+void (*it_callback_TIM4)(void);
17 17
 
18 18
 
19 19
 void TIM1_UP_IRQHandler(void)
@@ -21,61 +21,42 @@ void TIM1_UP_IRQHandler(void)
21 21
 	// rabaisser le flag d'IT
22 22
 	LL_TIM_ClearFlag_UPDATE(TIM1);
23 23
 	(*it_callback_TIM1)();
24
-}	
24
+}
25 25
 
26 26
 void TIM2_IRQHandler(void)
27 27
 {
28 28
 	// rabaisser le flag d'IT
29 29
 	LL_TIM_ClearFlag_UPDATE(TIM2);
30 30
 	(*it_callback_TIM2)();
31
-}	
31
+}
32 32
 
33 33
 void TIM3_IRQHandler(void)
34 34
 {
35 35
 	// rabaisser le flag d'IT
36 36
 	LL_TIM_ClearFlag_UPDATE(TIM3);
37 37
 	(*it_callback_TIM3)();
38
-}	
38
+}
39 39
 
40 40
 void TIM4_IRQHandler(void)
41 41
 {
42 42
 	// rabaisser le flag d'IT
43 43
 	LL_TIM_ClearFlag_UPDATE(TIM4);
44 44
 	(*it_callback_TIM4)();
45
-}	
45
+}
46 46
 
47 47
 
48
-/**
49
-	* @brief  Autorise les interruptions
50
-	* @note   
51
-	* @param  TIM_TypeDef Timer : indique le timer � utiliser par le chronom�tre, TIM1, TIM2, TIM3 ou TIM4
52
-	* @retval None
53
-	*/
54 48
 void Timer_IT_enable(TIM_TypeDef * timer)
55 49
 {
56 50
 	LL_TIM_EnableIT_UPDATE(timer);
57 51
 }
58 52
 
59 53
 
60
-/**
61
-	* @brief  Interdit les interruptions
62
-	* @note   
63
-	* @param  TIM_TypeDef Timer : indique le timer � utiliser par le chronom�tre, TIM1, TIM2, TIM3 ou TIM4
64
-	* @retval None
65
-	*/
66 54
 void Timer_IT_disable(TIM_TypeDef * timer)
67 55
 {
68
-	LL_TIM_DisableIT_UPDATE(timer); 
56
+	LL_TIM_DisableIT_UPDATE(timer);
69 57
 }
70 58
 
71
-/**
72
-	* @brief  Configure le Timer consid�r� en interruption sur d�bordement.
73
-	* @note   A ce stade, les interruptions ne sont pas valid�s (voir  MyTimer_IT_Enable )
74
-	* @param  TIM_TypeDef Timer : indique le timer � utiliser par le chronom�tre, TIM1, TIM2, TIM3 ou TIM4
75
-	* 				void (*IT_function) (void) : nom (adresse) de la fonction � lancer sur interruption
76
-	*         int Prio : priorit� associ�e � l'interruption
77
-	* @retval None
78
-	*/
59
+
79 60
 void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
80 61
 {
81 62
 	// affectation de la fonction
@@ -84,80 +65,61 @@ void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
84 65
 	else if (timer == TIM3)	it_callback_TIM3 = it_callback;
85 66
 	else  it_callback_TIM4 = it_callback;
86 67
 
87
-	
88
-	// Blocage IT (il faudra la dbloquer voir fct suivante)
68
+
69
+	// Blocage IT (il faudra la debloquer voir fct suivante)
89 70
 	LL_TIM_DisableIT_UPDATE(timer);
90
-	
71
+
91 72
 	// validation du canal NVIC
92 73
 	IRQn_Type TIM_irq;
93
-	
74
+
94 75
 	if (timer == TIM1) TIM_irq = TIM1_UP_IRQn;
95 76
 	else if (timer == TIM2)	TIM_irq = TIM2_IRQn;
96 77
 	else if (timer == TIM3)	TIM_irq = TIM3_IRQn;
97 78
 	else 	TIM_irq = TIM4_IRQn;
98
-	
79
+
99 80
 	NVIC_SetPriority(TIM_irq, prio);
100 81
 	NVIC_EnableIRQ(TIM_irq);
101 82
 
102
-	
83
+
103 84
 }
104 85
 
105 86
 /****************************************************************************
106 87
 	*																	TIMER
107 88
 	***************************************************************************/
108 89
 
109
-/**
110
-	* @brief  D�marre le timer consid�r� et active les interruptions
111
-	* @note   
112
-	* @param  TIM_TypeDef Timer : indique le timer � utiliser par le chronom�tre, TIM1, TIM2, TIM3 ou TIM4
113
-	* @retval None
114
-	*/
115 90
 void Timer_start(TIM_TypeDef * timer)
116 91
 {
117 92
 	LL_TIM_EnableCounter(timer);
118 93
 }
119 94
 
120
-/**
121
-	* @brief  Arr�t le timer consid�r�  et d�sactive les interruptions
122
-	* @note   
123
-	* @param  TIM_TypeDef Timer : indique le timer � utiliser par le chronom�tre, TIM1, TIM2, TIM3 ou TIM4
124
-	* @retval None
125
-	*/
126 95
 void Timer_stop(TIM_TypeDef * timer)
127 96
 {
128 97
 	LL_TIM_DisableCounter(timer);
129 98
 }
130 99
 
131
-/**
132
-	* @brief  Active l'horloge et r�gle l'ARR et le PSC du timer vis�.
133
-	* @note   Fonction � lancer avant toute autre. Le timer n'est pas encore lanc� (voir Timer_start)
134
-	* @param  TIM_TypeDef Timer : indique le timer � utiliser par le chronom�tre, TIM1, TIM2, TIM3 ou TIM4
135
-	* 				int Arr   : valeur � placer dans ARR
136
-	*					int Psc   : valeur � placer dans PSC
137
-	* @retval None
138
-	*/
100
+
139 101
 void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
140 102
 {
141 103
 	LL_TIM_InitTypeDef init_struct;
142
-	
104
+
143 105
 	// Validation horloge locale
144 106
 	if (timer == TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
145 107
 	else if (timer == TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
146 108
 	else if (timer == TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
147 109
 	else  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
148
-	
110
+
149 111
 	// chargement structure Arr, Psc, Up Count
150 112
 	init_struct.Autoreload = arr;
151 113
 	init_struct.Prescaler = psc;
152 114
 	init_struct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
153 115
 	init_struct.CounterMode = LL_TIM_COUNTERMODE_UP;
154 116
 	init_struct.RepetitionCounter = 0;
155
-	
117
+
156 118
 	LL_TIM_Init(timer,&init_struct);
157 119
 
158 120
 	// Blocage interruptions
159 121
 	Timer_IT_disable(timer);
160
-	
122
+
161 123
 	// Blocage Timer
162 124
 	Timer_stop(timer);
163 125
 }
@@ -169,16 +131,16 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
169 131
 void Timer_pwmi_conf(TIM_TypeDef * TIMx, int channel)
170 132
 {
171 133
 	// Periode à recuperer dans TIMx_CCR1, duty cycle dans TIMx_CCR2. Seul les 2 premiers channels peuvent être utilisés (cf 315).
172
-	
134
+
173 135
 	// Validation horloge locale
174 136
 	if (TIMx == TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
175 137
 	else if (TIMx == TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
176 138
 	else if (TIMx == TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
177 139
 	else  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
178
-	
179
-	
140
+
141
+
180 142
 	if (channel == 1) {
181
-		//
143
+
182 144
 		TIMx->CCMR1 |= TIM_CCMR1_CC1S_0;
183 145
 		TIMx->CCMR1 |= TIM_CCMR1_CC2S_1;
184 146
 
@@ -187,28 +149,28 @@ void Timer_pwmi_conf(TIM_TypeDef * TIMx, int channel)
187 149
 		// On met le channel principal en rising edge, le secondaire en falling edge
188 150
 		TIMx->CCER &= ~TIM_CCER_CC1P;
189 151
 		TIMx->CCER |= TIM_CCER_CC2P;
190
-		
152
+
191 153
 		TIMx->SMCR |= TIM_SMCR_TS_0 | TIM_SMCR_TS_2; //101
192 154
 		TIMx->SMCR |= TIM_SMCR_SMS_2; //100
193 155
 	}
194
-	
156
+
195 157
 	else {
196 158
 		TIMx->CCMR1 |= TIM_CCMR1_CC1S_1;
197 159
 		TIMx->CCMR1 |= TIM_CCMR1_CC2S_0;
198
-		
160
+
199 161
 		TIMx->CCER |= TIM_CCER_CC1P;
200 162
 		TIMx->CCER &= ~TIM_CCER_CC2P;
201 163
 
202 164
 		TIMx->SMCR |= TIM_SMCR_TS_1 | TIM_SMCR_TS_2; //110
203 165
 		TIMx->SMCR |= TIM_SMCR_SMS_2; //100
204 166
 	}
205
-	
167
+
206 168
 	// On met les prescalers à 0, on veut compter chaque transition
207 169
 	TIMx -> CCMR1 &= ~TIM_CCMR1_IC1PSC;
208 170
 	TIMx -> CCMR1 &= ~TIM_CCMR1_IC2PSC;
209
-	
171
+
210 172
 	TIMx -> CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E;
211
-	
173
+
212 174
 	// TIMx -> DIER |= TIM_DIER_CC1IE; gestion des interrupts, probablement pas utile
213 175
   // TIM_DIER_CC1DE_Pos; Probablement pas utile
214 176
 }
@@ -239,11 +201,11 @@ void Timer_pwmo_conf(TIM_TypeDef * timer, int channel, float freq, float dutyCyc
239 201
 	Timer_conf(timer, arr, 1000);
240 202
 	LL_TIM_OC_InitTypeDef init_struct;
241 203
 	LL_TIM_OC_StructInit(&init_struct);
242
-	
204
+
243 205
 	init_struct.OCMode = LL_TIM_OCMODE_PWM1;
244 206
 	init_struct.OCState = LL_TIM_OCSTATE_ENABLE;
245 207
 	init_struct.CompareValue= dutyCycle * arr;
246
-	
208
+
247 209
 	LL_TIM_OC_Init(timer, channel, &init_struct);
248 210
 }
249 211
 
@@ -280,17 +242,21 @@ float Timer_pwmo_getDutyCycle(TIM_TypeDef * timer, int channel)
280 242
 
281 243
 void Timer_encoder_conf(TIM_TypeDef * timer)
282 244
 {
283
-	Timer_conf(timer, 719, 0); // 360 * 2 - 1
245
+	// L'encodeur compte 2 tours quand on en fait qu'un, donc on divise l'angle
246
+	// par deux avant de le renvoyer. Il faut donc un autoreload de 360 * 2 = 720
247
+	Timer_conf(timer, 719, 0);
284 248
 	LL_TIM_ENCODER_InitTypeDef init_struct;
285 249
 	LL_TIM_ENCODER_StructInit(&init_struct);
286
-	
250
+
287 251
 	init_struct.EncoderMode = LL_TIM_ENCODERMODE_X2_TI1;
288
-	
252
+
289 253
 	LL_TIM_ENCODER_Init(timer, &init_struct);
290 254
 }
291 255
 
292 256
 int Timer_encoder_getAngle(TIM_TypeDef * timer)
293 257
 {
258
+	// L'encodeur compte 2 tours quand on en fait qu'un, donc on divise l'angle
259
+	// par deux avant de le renvoyer
294 260
 	return LL_TIM_GetCounter(timer)/2;
295 261
 }
296 262
 

+ 14
- 14
Services/DCMotor.c View File

@@ -1,19 +1,21 @@
1 1
 #include "DCMotor.h"
2 2
 #include "math.h"
3 3
 
4
-void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin)
5
-{	
6
-	//On règle la vitesse en valeur absolue, ici à 0
7
-	Timer_pwmo_conf(timer, channel, 50, 0);
8
-	
4
+const int MOTOR_PWM_FREQ = 50;
5
+
6
+void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpioPwm, int pinPwm, GPIO_TypeDef * gpioDirection, int pinDirection)
7
+{
8
+	// On regle la vitesse en valeur absolue, ici a 0
9
+	Timer_pwmo_conf(timer, channel, MOTOR_PWM_FREQ, 0);
10
+
9 11
 	// Configuration du GPIO
10
-	GPIO_conf(GPIOA, LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
12
+	GPIO_conf(gpioPwm, pinPwm, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
13
+
14
+
15
+	// On regle le sens du moteur
16
+	GPIO_conf(gpioDirection, pinDirection, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_DOWN);
17
+	GPIO_setPin(gpioDirection, pinDirection, 0);
11 18
 
12
-	
13
-	//On règle le sens du moteur, ici sens direct (?)
14
-	GPIO_conf(gpio, pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_DOWN);
15
-	GPIO_setPin(gpio, pin, 0);
16
-	
17 19
 	Timer_start(timer);
18 20
 }
19 21
 
@@ -21,8 +23,7 @@ void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin
21 23
 
22 24
 void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed)
23 25
 {
24
-	const int dir = (speed > 0.) ? 1 : 0;
25
-	
26
+	const int dir = speed > 0.0;
26 27
 	Timer_pwmo_setDutyCycle(timer, channel, fabs(speed));
27 28
 	GPIO_setPin(gpio, pin, dir);
28 29
 }
@@ -31,6 +32,5 @@ float DCMotor_getSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, in
31 32
 {
32 33
 	const float speedAbs = Timer_pwmo_getDutyCycle(timer, channel);
33 34
 	const int dir = GPIO_readPin(gpio, pin);
34
-	
35 35
 	return dir ? speedAbs : -speedAbs;
36 36
 }

+ 11
- 11
Services/DCMotor.h View File

@@ -6,21 +6,21 @@
6 6
 
7 7
 /**
8 8
 	* @brief  Configure le Timer et le GPIO du DCmotor
9
-  * @note   
10
-	* @param  timer 	: Timer utilisé pour controler le moteur
9
+  * @note
10
+	* @param  timer 	: Timer utilise pour controler le moteur
11 11
 	*					channel : channel du timer
12
-	*					gpio 		: GPIO utilisé pour régler le sens du moteur
12
+	*					gpio 		: GPIO utilise pour regler le sens du moteur
13 13
 	*					pin 		: Pin pour l'axe Y
14 14
   * @retval None
15 15
   */
16
-void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin);
16
+void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpioPwm, int pinPwm, GPIO_TypeDef * gpioDirection, int pinDirection);
17 17
 
18 18
 /**
19 19
 	* @brief  Configure le Timer et le GPIO du DCmotor
20
-  * @note   
21
-	* @param  timer 	: Timer utilisé pour controler le moteur
20
+  * @note
21
+	* @param  timer 	: Timer utilise pour controler le moteur
22 22
 	*					channel : channel du timer
23
-	*					gpio 		: GPIO utilisé pour régler le sens du moteur
23
+	*					gpio 		: GPIO utilise pour regler le sens du moteur
24 24
 	*					pin 		: Pin pour l'axe Y
25 25
 	*					speed		: vitesse voulue
26 26
   * @retval None
@@ -28,11 +28,11 @@ void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin
28 28
 void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed);
29 29
 
30 30
 /**
31
-	* @brief  Récupère la vitesse actuelle du moteur
32
-  * @note   
33
-	* @param  timer 	: Timer utilisé pour controler le moteur
31
+	* @brief  Recupere la vitesse actuelle du moteur
32
+  * @note
33
+	* @param  timer 	: Timer utilise pour controler le moteur
34 34
 	*					channel : channel du timer
35
-	*					gpio 		: GPIO utilisé pour régler le sens du moteur
35
+	*					gpio 		: GPIO utilise pour regler le sens du moteur
36 36
 	*					pin 		: Pin pour l'axe Y
37 37
 	*					speed		: vitesse voulue
38 38
   * @retval None

+ 15
- 15
Services/IncrementalEncoder.h View File

@@ -4,35 +4,35 @@
4 4
 #include "stm32f103xb.h"
5 5
 
6 6
 /**
7
-	* @brief  Configure le timer et le pin du gpio pour le codeur incrémental
8
-  * @note   
9
-	* @param  TIM_TypeDef timer : le timer à utiliser
10
-	* 				GPIO_TypeDef gpio : le gpio à utiliser pour le zero
11
-	* 				int pin 					: le pin associé au GPIO pour le zero
7
+	* @brief  Configure le timer et le pin du gpio pour le codeur incremental
8
+  * @note
9
+	* @param  TIM_TypeDef timer : le timer a utiliser
10
+	* 				GPIO_TypeDef gpio : le gpio a utiliser pour le zero
11
+	* 				int pin 					: le pin associe au GPIO pour le zero
12 12
   * @retval None
13 13
   */
14 14
 void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin);
15 15
 
16 16
 /**
17
-	* @brief  Démarre le timer pour le codeur incrémental
18
-  * @note   
19
-	* @param  TIM_TypeDef timer : le timer à utiliser
17
+	* @brief  Demarre le timer pour le codeur incremental
18
+  * @note
19
+	* @param  TIM_TypeDef timer : le timer a utiliser
20 20
   * @retval None
21 21
   */
22 22
 void IncrementalEncoder_start(TIM_TypeDef * timer);
23 23
 
24 24
 /**
25
-	* @brief  Récupère l'angle du codeur incrémental associé au timer donné
26
-  * @note   
27
-	* @param  TIM_TypeDef timer : le timer à utiliser
28
-  * @retval L'angle en degrès
25
+	* @brief  Recupere l'angle du codeur incremental associe au timer donne
26
+  * @note
27
+	* @param  TIM_TypeDef timer : le timer a utiliser
28
+  * @retval L'angle en degres
29 29
   */
30 30
 int IncrementalEncoder_getAngle(TIM_TypeDef * timer);
31 31
 
32 32
 /**
33
-	* @brief  Récupère la direction du codeur incrémental associé au timer donné
34
-  * @note   
35
-	* @param  TIM_TypeDef timer : le timer à utiliser
33
+	* @brief  Recupere la direction du codeur incremental associe au timer donne
34
+  * @note
35
+	* @param  TIM_TypeDef timer : le timer a utiliser
36 36
   * @retval la direction actuelle du codeur
37 37
   */
38 38
 enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer);

+ 2
- 1
Services/ServoMotor.c View File

@@ -14,7 +14,8 @@ void ServoMotor_start(TIM_TypeDef * timer)
14 14
 }
15 15
 
16 16
 float convertAngleToDutyCycle(int angle) {
17
-	return ((float) angle) / 90.0 / 20 + 0.05;
17
+	// fonction lineaire [0 - 90] -> [0.05 - 0.1]
18
+	return (float)angle / 1800.0 + 0.05;
18 19
 }
19 20
 
20 21
 void ServoMotor_setAngle(TIM_TypeDef * timer, int channel, int angle)

+ 14
- 13
Src/Orientation.c View File

@@ -1,7 +1,7 @@
1 1
 #include "Orientation.h"
2 2
 #include "math.h"
3 3
 
4
-#define THRESHOLD 0
4
+const float THRESHOLD = 0.05;
5 5
 
6 6
 const float MIN_DUTY_CYCLE = 0.05;
7 7
 const float ZERO_DUTY_CYCLE = 0.075;
@@ -15,25 +15,26 @@ const int RECEIVER_CHANNEL = LL_TIM_CHANNEL_CH1;
15 15
 TIM_TypeDef * DCMOTOR_TIMER = TIM2;
16 16
 const int DCMOTOR_CHANNEL = LL_TIM_CHANNEL_CH2;
17 17
 GPIO_TypeDef * DCMOTOR_GPIO = GPIOA;
18
-const int DCMOTOR_PIN = LL_GPIO_PIN_2;
18
+const int DCMOTOR_PIN_PWM = LL_GPIO_PIN_2;
19
+const int DCMOTOR_PIN_DIRECTION = LL_GPIO_PIN_2;
19 20
 
20
-void Orientation_conf() 
21
+
22
+void Orientation_conf()
21 23
 {
22
-	DCMotor_conf(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN);
24
+	DCMotor_conf(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_PWM, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION);
23 25
 	RFReceiver_conf(RECEIVER_TIMER, LL_TIM_CHANNEL_CH1);
24 26
 }
25 27
 
26 28
 void Orientation_background()
27 29
 {
28 30
 	const float duty_cycle = RFReceiver_getData(RECEIVER_TIMER);
29
-	
31
+
32
+	// Calcul de la vitesse du moteur (entre 0 et 1)
30 33
 	const float speed = (duty_cycle - ZERO_DUTY_CYCLE) / (MAX_DUTY_CYCLE - ZERO_DUTY_CYCLE);
31
-	
32
-	//Si la vitesse (en valeur absolue) ne dépasse pas un certain seuil, on ne démarre pas le moteur
33
-	if (THRESHOLD > fabs(speed)) {
34
-		DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN, 0);
35
-	}
36
-	else { 
37
-		DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN, speed);
38
-	}
34
+
35
+	// On ne demarre le moteur que si la vitesse depasse un certain seuil
36
+	if (fabs(speed) > THRESHOLD)
37
+		DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION, speed);
38
+	else
39
+		DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION, 0);
39 40
 }

+ 8
- 8
Src/Roll.c View File

@@ -31,12 +31,12 @@ int Roll_getEmergencyState(void)
31 31
 
32 32
 void Roll_background(void)
33 33
 {
34
-	const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
35
-	//const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
36
-	
37
-	const int currentState = abs(xAngle) >= 40;
38
-	if (Roll_isEmergencyState && !currentState)
39
-		Sail_setEmergency(1);
40
-	else if (!Roll_isEmergencyState && currentState)
41
-		Sail_setEmergency(0);
34
+	const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_X_CHANNEL);
35
+	const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
36
+
37
+	const int currentState = abs(yAngle) >= 40;
38
+	if (Roll_isEmergencyState != currentState) {
39
+		Sail_setEmergency(currentState);
40
+		Roll_isEmergencyState = currentState;
41
+	}
42 42
 }

+ 15
- 15
Src/main.c View File

@@ -38,8 +38,8 @@ int secCounter = 0;
38 38
 /* Private functions ---------------------------------------------------------*/
39 39
 
40 40
 /**
41
-	* @brief  Effectue la tache de fond (programmée toutes les 1ms)
42
-  * @note   
41
+	* @brief  Effectue la tache de fond (programmee toutes les ms)
42
+  * @note
43 43
 	* @param  None
44 44
   * @retval None
45 45
   */
@@ -58,8 +58,8 @@ void backgroundTask()
58 58
 }
59 59
 
60 60
 /**
61
-	* @brief  Configure les périphériques
62
-  * @note   
61
+	* @brief  Configure les peripheriques
62
+  * @note
63 63
 	* @param  None
64 64
   * @retval None
65 65
   */
@@ -72,8 +72,8 @@ void configurePeripherals()
72 72
 }
73 73
 
74 74
 /**
75
-	* @brief  Démarre les périphériques
76
-  * @note   
75
+	* @brief  Demarre les peripheriques
76
+  * @note
77 77
 	* @param  None
78 78
   * @retval None
79 79
   */
@@ -90,36 +90,36 @@ void startPeripherals()
90 90
   * @retval None
91 91
   */
92 92
 int main(void)
93
-{	
93
+{
94 94
   /* Configure the system clock to 72 MHz */
95 95
   SystemClock_Config();
96 96
 
97 97
   /* Add your application code here */
98 98
   configurePeripherals();
99 99
 	startPeripherals();
100
-	
100
+
101 101
 	Scheduler_conf(backgroundTask);
102 102
 	Scheduler_start();
103 103
 
104 104
   while (1) {
105
-//		Display_background(secCounter);
105
+		// Display_background(secCounter);
106 106
   }
107
-	
108
-	
107
+
108
+
109 109
 //// ADC 2 marche niquel, ADC1 ne marche pas :(
110 110
 //	ADC_conf(ADC1);
111 111
 //	ADC_start(ADC1);
112
-//	
112
+//
113 113
 //	ADC_conf(ADC2);
114 114
 //	ADC_start(ADC2);
115 115
 
116
-//	
116
+//
117 117
 //	while (1) {
118 118
 //		val1 = ADC_readRaw(ADC1, 10);
119 119
 //		val2 = ADC_readRaw(ADC2, 10);
120 120
 //	}
121 121
 
122
-	
122
+
123 123
 }
124 124
 
125 125
 
@@ -150,7 +150,7 @@ void SystemClock_Config(void)
150 150
 
151 151
   /* Enable HSE oscillator */
152 152
 	// ********* Commenter la ligne ci-dessous pour MCBSTM32 *****************
153
-	// ********* Conserver la ligne si Nucléo*********************************
153
+	// ********* Conserver la ligne si Nucleo*********************************
154 154
 //  LL_RCC_HSE_EnableBypass();
155 155
   LL_RCC_HSE_Enable();
156 156
   while(LL_RCC_HSE_IsReady() != 1)

Loading…
Cancel
Save