Projet voilier 4IRA1 Arnaud Vergnet Marino Benassai Bastien Picco Yohan Simard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Orientation.c 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "Orientation.h"
  2. #include "math.h"
  3. const float THRESHOLD = 0.05;
  4. const float MIN_DUTY_CYCLE = 0.05;
  5. const float ZERO_DUTY_CYCLE = 0.075;
  6. const float MAX_DUTY_CYCLE = 0.1;
  7. // Recepteur
  8. TIM_TypeDef * RECEIVER_TIMER = TIM4;
  9. const int RECEIVER_CHANNEL = LL_TIM_CHANNEL_CH1;
  10. // Moteur
  11. TIM_TypeDef * DCMOTOR_TIMER = TIM2;
  12. const int DCMOTOR_CHANNEL = LL_TIM_CHANNEL_CH2;
  13. GPIO_TypeDef * DCMOTOR_GPIO = GPIOA;
  14. const int DCMOTOR_PIN_PWM = LL_GPIO_PIN_1;
  15. const int DCMOTOR_PIN_DIRECTION = LL_GPIO_PIN_2;
  16. void Orientation_conf()
  17. {
  18. DCMotor_conf(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_PWM, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION);
  19. RFReceiver_conf(RECEIVER_TIMER, LL_TIM_CHANNEL_CH1);
  20. }
  21. void Orientation_background()
  22. {
  23. const float duty_cycle = RFReceiver_getData(RECEIVER_TIMER);
  24. // Calcul de la vitesse du moteur (entre 0 et 1)
  25. const float speed = (duty_cycle - ZERO_DUTY_CYCLE) / (MAX_DUTY_CYCLE - ZERO_DUTY_CYCLE);
  26. // On ne demarre le moteur que si la vitesse depasse un certain seuil
  27. if (fabs(speed) > THRESHOLD)
  28. DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION, speed);
  29. else
  30. DCMotor_setSpeed(DCMOTOR_TIMER, DCMOTOR_CHANNEL, DCMOTOR_GPIO, DCMOTOR_PIN_DIRECTION, 0);
  31. }