39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
#include "Orientation.h"
|
|
#include "math.h"
|
|
|
|
#define THRESHOLD 0
|
|
|
|
const float MIN_DUTY_CYCLE = 0.05;
|
|
const float ZERO_DUTY_CYCLE = 0.075;
|
|
const float MAX_DUTY_CYCLE = 0.1;
|
|
|
|
// Recepteur
|
|
TIM_TypeDef * RECEIVER_TIMER = TIM4;
|
|
const int RECEIVER_CHANNEL = LL_TIM_CHANNEL_CH1;
|
|
|
|
// Moteur
|
|
TIM_TypeDef * DCMOTOR_TIMER = TIM2;
|
|
const int DCMOTOR_CHANNEL = LL_TIM_CHANNEL_CH2;
|
|
GPIO_TypeDef * DCMOTOR_GPIO = GPIOA;
|
|
const int DCMOTOR_PIN = LL_GPIO_PIN_2;
|
|
|
|
void Orientation_conf()
|
|
{
|
|
DCMotor_conf(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN);
|
|
RFReceiver_conf(RECEIVER_TIMER, LL_TIM_CHANNEL_CH1);
|
|
}
|
|
|
|
void Orientation_background()
|
|
{
|
|
const float duty_cycle = RFReceiver_getData(RECEIVER_TIMER);
|
|
|
|
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
|
|
if (THRESHOLD > fabs(speed)) {
|
|
DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN, 0);
|
|
}
|
|
else {
|
|
DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN, speed);
|
|
}
|
|
}
|