clean project

This commit is contained in:
Yohan Simard 2020-11-16 19:45:46 +01:00
parent 542722584d
commit c8ea3f3a91
10 changed files with 139 additions and 188 deletions

View file

@ -75,7 +75,7 @@
<OPTFL> <OPTFL>
<tvExp>1</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget> <IsCurrentTarget>0</IsCurrentTarget>
</OPTFL> </OPTFL>
<CpuCode>18</CpuCode> <CpuCode>18</CpuCode>
<DebugOpt> <DebugOpt>
@ -352,7 +352,7 @@
<OPTFL> <OPTFL>
<tvExp>1</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>0</IsCurrentTarget> <IsCurrentTarget>1</IsCurrentTarget>
</OPTFL> </OPTFL>
<CpuCode>18</CpuCode> <CpuCode>18</CpuCode>
<DebugOpt> <DebugOpt>
@ -397,7 +397,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGDARM</Key> <Key>DLGDARM</Key>
<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> <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>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -430,24 +430,7 @@
<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> <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>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint/>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>51</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134221038</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Src\Display.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\NUCLEO_F103RB\../Src/Display.c\51</Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -503,8 +486,8 @@
<periodic>1</periodic> <periodic>1</periodic>
<aLwin>0</aLwin> <aLwin>0</aLwin>
<aCover>0</aCover> <aCover>0</aCover>
<aSer1>1</aSer1> <aSer1>0</aSer1>
<aSer2>1</aSer2> <aSer2>0</aSer2>
<aPa>0</aPa> <aPa>0</aPa>
<viewmode>1</viewmode> <viewmode>1</viewmode>
<vrSel>0</vrSel> <vrSel>0</vrSel>
@ -513,12 +496,12 @@
<AscS1>0</AscS1> <AscS1>0</AscS1>
<AscS2>0</AscS2> <AscS2>0</AscS2>
<AscS3>0</AscS3> <AscS3>0</AscS3>
<aSer3>1</aSer3> <aSer3>0</aSer3>
<eProf>0</eProf> <eProf>0</eProf>
<aLa>1</aLa> <aLa>0</aLa>
<aPa1>0</aPa1> <aPa1>0</aPa1>
<AscS4>0</AscS4> <AscS4>0</AscS4>
<aSer4>1</aSer4> <aSer4>0</aSer4>
<StkLoc>0</StkLoc> <StkLoc>0</StkLoc>
<TrcWin>0</TrcWin> <TrcWin>0</TrcWin>
<newCpu>0</newCpu> <newCpu>0</newCpu>

View file

@ -15,10 +15,10 @@ void ADC_conf(ADC_TypeDef *adc)
// Division de la frequence // Division de la frequence
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
// Fixe le nombre de conversion à 1 // Fixe le nombre de conversion <EFBFBD> 1
adc->SQR1 &= ADC_SQR1_L; adc->SQR1 &= ADC_SQR1_L;
// Calibration // Calibration (ne fonctionne pas, mais pas necessaire donc ok)
// adc->CR2 |= ADC_CR2_CAL_Msk; // adc->CR2 |= ADC_CR2_CAL_Msk;
// while ((adc->CR2 & ADC_CR2_CAL_Msk)); // while ((adc->CR2 & ADC_CR2_CAL_Msk));
} }

View file

@ -45,37 +45,18 @@ void TIM4_IRQHandler(void)
} }
/**
* @brief Autorise les interruptions
* @note
* @param TIM_TypeDef Timer : indique le timer <EFBFBD> utiliser par le chronom<EFBFBD>tre, TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
void Timer_IT_enable(TIM_TypeDef * timer) void Timer_IT_enable(TIM_TypeDef * timer)
{ {
LL_TIM_EnableIT_UPDATE(timer); LL_TIM_EnableIT_UPDATE(timer);
} }
/**
* @brief Interdit les interruptions
* @note
* @param TIM_TypeDef Timer : indique le timer <EFBFBD> utiliser par le chronom<EFBFBD>tre, TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
void Timer_IT_disable(TIM_TypeDef * timer) void Timer_IT_disable(TIM_TypeDef * timer)
{ {
LL_TIM_DisableIT_UPDATE(timer); LL_TIM_DisableIT_UPDATE(timer);
} }
/**
* @brief Configure le Timer consid<EFBFBD>r<EFBFBD> en interruption sur d<EFBFBD>bordement.
* @note A ce stade, les interruptions ne sont pas valid<EFBFBD>s (voir MyTimer_IT_Enable )
* @param TIM_TypeDef Timer : indique le timer <EFBFBD> utiliser par le chronom<EFBFBD>tre, TIM1, TIM2, TIM3 ou TIM4
* void (*IT_function) (void) : nom (adresse) de la fonction <EFBFBD> lancer sur interruption
* int Prio : priorit<EFBFBD> associ<EFBFBD>e <EFBFBD> l'interruption
* @retval None
*/
void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio) void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
{ {
// affectation de la fonction // affectation de la fonction
@ -85,7 +66,7 @@ void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
else it_callback_TIM4 = it_callback; else it_callback_TIM4 = it_callback;
// Blocage IT (il faudra la d<EFBFBD>bloquer voir fct suivante) // Blocage IT (il faudra la debloquer voir fct suivante)
LL_TIM_DisableIT_UPDATE(timer); LL_TIM_DisableIT_UPDATE(timer);
// validation du canal NVIC // validation du canal NVIC
@ -106,36 +87,17 @@ void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
* TIMER * TIMER
***************************************************************************/ ***************************************************************************/
/**
* @brief D<EFBFBD>marre le timer consid<EFBFBD>r<EFBFBD> et active les interruptions
* @note
* @param TIM_TypeDef Timer : indique le timer <EFBFBD> utiliser par le chronom<EFBFBD>tre, TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
void Timer_start(TIM_TypeDef * timer) void Timer_start(TIM_TypeDef * timer)
{ {
LL_TIM_EnableCounter(timer); LL_TIM_EnableCounter(timer);
} }
/**
* @brief Arr<EFBFBD>t le timer consid<EFBFBD>r<EFBFBD> et d<EFBFBD>sactive les interruptions
* @note
* @param TIM_TypeDef Timer : indique le timer <EFBFBD> utiliser par le chronom<EFBFBD>tre, TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
void Timer_stop(TIM_TypeDef * timer) void Timer_stop(TIM_TypeDef * timer)
{ {
LL_TIM_DisableCounter(timer); LL_TIM_DisableCounter(timer);
} }
/**
* @brief Active l'horloge et r<EFBFBD>gle l'ARR et le PSC du timer vis<EFBFBD>.
* @note Fonction <EFBFBD> lancer avant toute autre. Le timer n'est pas encore lanc<EFBFBD> (voir Timer_start)
* @param TIM_TypeDef Timer : indique le timer <EFBFBD> utiliser par le chronom<EFBFBD>tre, TIM1, TIM2, TIM3 ou TIM4
* int Arr : valeur <EFBFBD> placer dans ARR
* int Psc : valeur <EFBFBD> placer dans PSC
* @retval None
*/
void Timer_conf(TIM_TypeDef * timer, int arr, int psc) void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
{ {
LL_TIM_InitTypeDef init_struct; LL_TIM_InitTypeDef init_struct;
@ -178,7 +140,7 @@ void Timer_pwmi_conf(TIM_TypeDef * TIMx, int channel)
if (channel == 1) { if (channel == 1) {
//
TIMx->CCMR1 |= TIM_CCMR1_CC1S_0; TIMx->CCMR1 |= TIM_CCMR1_CC1S_0;
TIMx->CCMR1 |= TIM_CCMR1_CC2S_1; TIMx->CCMR1 |= TIM_CCMR1_CC2S_1;
@ -280,7 +242,9 @@ float Timer_pwmo_getDutyCycle(TIM_TypeDef * timer, int channel)
void Timer_encoder_conf(TIM_TypeDef * timer) void Timer_encoder_conf(TIM_TypeDef * timer)
{ {
Timer_conf(timer, 719, 0); // 360 * 2 - 1 // L'encodeur compte 2 tours quand on en fait qu'un, donc on divise l'angle
// par deux avant de le renvoyer. Il faut donc un autoreload de 360 * 2 = 720
Timer_conf(timer, 719, 0);
LL_TIM_ENCODER_InitTypeDef init_struct; LL_TIM_ENCODER_InitTypeDef init_struct;
LL_TIM_ENCODER_StructInit(&init_struct); LL_TIM_ENCODER_StructInit(&init_struct);
@ -291,6 +255,8 @@ void Timer_encoder_conf(TIM_TypeDef * timer)
int Timer_encoder_getAngle(TIM_TypeDef * timer) int Timer_encoder_getAngle(TIM_TypeDef * timer)
{ {
// L'encodeur compte 2 tours quand on en fait qu'un, donc on divise l'angle
// par deux avant de le renvoyer
return LL_TIM_GetCounter(timer)/2; return LL_TIM_GetCounter(timer)/2;
} }

View file

@ -1,18 +1,20 @@
#include "DCMotor.h" #include "DCMotor.h"
#include "math.h" #include "math.h"
void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin) const int MOTOR_PWM_FREQ = 50;
void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpioPwm, int pinPwm, GPIO_TypeDef * gpioDirection, int pinDirection)
{ {
//On règle la vitesse en valeur absolue, ici à 0 // On regle la vitesse en valeur absolue, ici a 0
Timer_pwmo_conf(timer, channel, 50, 0); Timer_pwmo_conf(timer, channel, MOTOR_PWM_FREQ, 0);
// Configuration du GPIO // Configuration du GPIO
GPIO_conf(GPIOA, LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP); GPIO_conf(gpioPwm, pinPwm, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
//On règle le sens du moteur, ici sens direct (?) // On regle le sens du moteur
GPIO_conf(gpio, pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_DOWN); GPIO_conf(gpioDirection, pinDirection, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_DOWN);
GPIO_setPin(gpio, pin, 0); GPIO_setPin(gpioDirection, pinDirection, 0);
Timer_start(timer); Timer_start(timer);
} }
@ -21,8 +23,7 @@ void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin
void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed) void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed)
{ {
const int dir = (speed > 0.) ? 1 : 0; const int dir = speed > 0.0;
Timer_pwmo_setDutyCycle(timer, channel, fabs(speed)); Timer_pwmo_setDutyCycle(timer, channel, fabs(speed));
GPIO_setPin(gpio, pin, dir); GPIO_setPin(gpio, pin, dir);
} }
@ -31,6 +32,5 @@ float DCMotor_getSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, in
{ {
const float speedAbs = Timer_pwmo_getDutyCycle(timer, channel); const float speedAbs = Timer_pwmo_getDutyCycle(timer, channel);
const int dir = GPIO_readPin(gpio, pin); const int dir = GPIO_readPin(gpio, pin);
return dir ? speedAbs : -speedAbs; return dir ? speedAbs : -speedAbs;
} }

View file

@ -7,20 +7,20 @@
/** /**
* @brief Configure le Timer et le GPIO du DCmotor * @brief Configure le Timer et le GPIO du DCmotor
* @note * @note
* @param timer : Timer utilisé pour controler le moteur * @param timer : Timer utilise pour controler le moteur
* channel : channel du timer * channel : channel du timer
* gpio : GPIO utilisé pour gler le sens du moteur * gpio : GPIO utilise pour regler le sens du moteur
* pin : Pin pour l'axe Y * pin : Pin pour l'axe Y
* @retval None * @retval None
*/ */
void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin); void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpioPwm, int pinPwm, GPIO_TypeDef * gpioDirection, int pinDirection);
/** /**
* @brief Configure le Timer et le GPIO du DCmotor * @brief Configure le Timer et le GPIO du DCmotor
* @note * @note
* @param timer : Timer utilisé pour controler le moteur * @param timer : Timer utilise pour controler le moteur
* channel : channel du timer * channel : channel du timer
* gpio : GPIO utilisé pour gler le sens du moteur * gpio : GPIO utilise pour regler le sens du moteur
* pin : Pin pour l'axe Y * pin : Pin pour l'axe Y
* speed : vitesse voulue * speed : vitesse voulue
* @retval None * @retval None
@ -28,11 +28,11 @@ void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin
void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed); void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed);
/** /**
* @brief Récupère la vitesse actuelle du moteur * @brief Recupere la vitesse actuelle du moteur
* @note * @note
* @param timer : Timer utilisé pour controler le moteur * @param timer : Timer utilise pour controler le moteur
* channel : channel du timer * channel : channel du timer
* gpio : GPIO utilisé pour gler le sens du moteur * gpio : GPIO utilise pour regler le sens du moteur
* pin : Pin pour l'axe Y * pin : Pin pour l'axe Y
* speed : vitesse voulue * speed : vitesse voulue
* @retval None * @retval None

View file

@ -4,35 +4,35 @@
#include "stm32f103xb.h" #include "stm32f103xb.h"
/** /**
* @brief Configure le timer et le pin du gpio pour le codeur incrémental * @brief Configure le timer et le pin du gpio pour le codeur incremental
* @note * @note
* @param TIM_TypeDef timer : le timer à utiliser * @param TIM_TypeDef timer : le timer a utiliser
* GPIO_TypeDef gpio : le gpio à utiliser pour le zero * GPIO_TypeDef gpio : le gpio a utiliser pour le zero
* int pin : le pin associé au GPIO pour le zero * int pin : le pin associe au GPIO pour le zero
* @retval None * @retval None
*/ */
void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin); void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin);
/** /**
* @brief Démarre le timer pour le codeur incrémental * @brief Demarre le timer pour le codeur incremental
* @note * @note
* @param TIM_TypeDef timer : le timer à utiliser * @param TIM_TypeDef timer : le timer a utiliser
* @retval None * @retval None
*/ */
void IncrementalEncoder_start(TIM_TypeDef * timer); void IncrementalEncoder_start(TIM_TypeDef * timer);
/** /**
* @brief Récupère l'angle du codeur incrémental associé au timer donné * @brief Recupere l'angle du codeur incremental associe au timer donne
* @note * @note
* @param TIM_TypeDef timer : le timer à utiliser * @param TIM_TypeDef timer : le timer a utiliser
* @retval L'angle en degrès * @retval L'angle en degres
*/ */
int IncrementalEncoder_getAngle(TIM_TypeDef * timer); int IncrementalEncoder_getAngle(TIM_TypeDef * timer);
/** /**
* @brief Récupère la direction du codeur incrémental associé au timer donné * @brief Recupere la direction du codeur incremental associe au timer donne
* @note * @note
* @param TIM_TypeDef timer : le timer à utiliser * @param TIM_TypeDef timer : le timer a utiliser
* @retval la direction actuelle du codeur * @retval la direction actuelle du codeur
*/ */
enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer); enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer);

View file

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

View file

@ -1,7 +1,7 @@
#include "Orientation.h" #include "Orientation.h"
#include "math.h" #include "math.h"
#define THRESHOLD 0 const float THRESHOLD = 0.05;
const float MIN_DUTY_CYCLE = 0.05; const float MIN_DUTY_CYCLE = 0.05;
const float ZERO_DUTY_CYCLE = 0.075; const float ZERO_DUTY_CYCLE = 0.075;
@ -15,11 +15,13 @@ const int RECEIVER_CHANNEL = LL_TIM_CHANNEL_CH1;
TIM_TypeDef * DCMOTOR_TIMER = TIM2; TIM_TypeDef * DCMOTOR_TIMER = TIM2;
const int DCMOTOR_CHANNEL = LL_TIM_CHANNEL_CH2; const int DCMOTOR_CHANNEL = LL_TIM_CHANNEL_CH2;
GPIO_TypeDef * DCMOTOR_GPIO = GPIOA; GPIO_TypeDef * DCMOTOR_GPIO = GPIOA;
const int DCMOTOR_PIN = LL_GPIO_PIN_2; const int DCMOTOR_PIN_PWM = LL_GPIO_PIN_2;
const int DCMOTOR_PIN_DIRECTION = LL_GPIO_PIN_2;
void Orientation_conf() void Orientation_conf()
{ {
DCMotor_conf(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN); DCMotor_conf(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_PWM, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION);
RFReceiver_conf(RECEIVER_TIMER, LL_TIM_CHANNEL_CH1); RFReceiver_conf(RECEIVER_TIMER, LL_TIM_CHANNEL_CH1);
} }
@ -27,13 +29,12 @@ void Orientation_background()
{ {
const float duty_cycle = RFReceiver_getData(RECEIVER_TIMER); const float duty_cycle = RFReceiver_getData(RECEIVER_TIMER);
// Calcul de la vitesse du moteur (entre 0 et 1)
const float speed = (duty_cycle - ZERO_DUTY_CYCLE) / (MAX_DUTY_CYCLE - ZERO_DUTY_CYCLE); const float speed = (duty_cycle - ZERO_DUTY_CYCLE) / (MAX_DUTY_CYCLE - ZERO_DUTY_CYCLE);
//Si la vitesse (en valeur absolue) ne dépasse pas un certain seuil, on ne démarre pas le moteur // On ne demarre le moteur que si la vitesse depasse un certain seuil
if (THRESHOLD > fabs(speed)) { if (fabs(speed) > THRESHOLD)
DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN, 0); DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION, speed);
} else
else { DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION, 0);
DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN, speed);
}
} }

View file

@ -31,12 +31,12 @@ int Roll_getEmergencyState(void)
void Roll_background(void) void Roll_background(void)
{ {
const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL); const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_X_CHANNEL);
//const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL); const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
const int currentState = abs(xAngle) >= 40; const int currentState = abs(yAngle) >= 40;
if (Roll_isEmergencyState && !currentState) if (Roll_isEmergencyState != currentState) {
Sail_setEmergency(1); Sail_setEmergency(currentState);
else if (!Roll_isEmergencyState && currentState) Roll_isEmergencyState = currentState;
Sail_setEmergency(0); }
} }

View file

@ -38,7 +38,7 @@ int secCounter = 0;
/* Private functions ---------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
/** /**
* @brief Effectue la tache de fond (programmée toutes les 1ms) * @brief Effectue la tache de fond (programmee toutes les ms)
* @note * @note
* @param None * @param None
* @retval None * @retval None
@ -58,7 +58,7 @@ void backgroundTask()
} }
/** /**
* @brief Configure les périphériques * @brief Configure les peripheriques
* @note * @note
* @param None * @param None
* @retval None * @retval None
@ -72,7 +72,7 @@ void configurePeripherals()
} }
/** /**
* @brief Démarre les périphériques * @brief Demarre les peripheriques
* @note * @note
* @param None * @param None
* @retval None * @retval None
@ -102,7 +102,7 @@ int main(void)
Scheduler_start(); Scheduler_start();
while (1) { while (1) {
// Display_background(secCounter); // Display_background(secCounter);
} }
@ -150,7 +150,7 @@ void SystemClock_Config(void)
/* Enable HSE oscillator */ /* Enable HSE oscillator */
// ********* Commenter la ligne ci-dessous pour MCBSTM32 ***************** // ********* Commenter la ligne ci-dessous pour MCBSTM32 *****************
// ********* Conserver la ligne si Nucléo********************************* // ********* Conserver la ligne si Nucleo*********************************
// LL_RCC_HSE_EnableBypass(); // LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable(); LL_RCC_HSE_Enable();
while(LL_RCC_HSE_IsReady() != 1) while(LL_RCC_HSE_IsReady() != 1)