programme ines avce xbee
Dependencies: MMA8451Q mbed xbee_lib
Fork of Programme_course by
motor.cpp@0:3ec7fc598e48, 2017-01-26 (annotated)
- Committer:
- Freescale_cup
- Date:
- Thu Jan 26 07:37:45 2017 +0000
- Revision:
- 0:3ec7fc598e48
Programme de base
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Freescale_cup | 0:3ec7fc598e48 | 1 | #include "motor.h" |
Freescale_cup | 0:3ec7fc598e48 | 2 | |
Freescale_cup | 0:3ec7fc598e48 | 3 | |
Freescale_cup | 0:3ec7fc598e48 | 4 | PwmOut moteurA_avancer (PTC2); |
Freescale_cup | 0:3ec7fc598e48 | 5 | PwmOut moteurA_reculer (PTC1); |
Freescale_cup | 0:3ec7fc598e48 | 6 | |
Freescale_cup | 0:3ec7fc598e48 | 7 | PwmOut moteurB_avancer (PTC4); |
Freescale_cup | 0:3ec7fc598e48 | 8 | PwmOut moteurB_reculer (PTC3); |
Freescale_cup | 0:3ec7fc598e48 | 9 | |
Freescale_cup | 0:3ec7fc598e48 | 10 | |
Freescale_cup | 0:3ec7fc598e48 | 11 | PwmOut servo (PTB0); |
Freescale_cup | 0:3ec7fc598e48 | 12 | |
Freescale_cup | 0:3ec7fc598e48 | 13 | void PWM_motor (int vitesse_gauche ,int vitesse_droite) |
Freescale_cup | 0:3ec7fc598e48 | 14 | { |
Freescale_cup | 0:3ec7fc598e48 | 15 | |
Freescale_cup | 0:3ec7fc598e48 | 16 | if(vitesse_gauche >= 0)//On avance |
Freescale_cup | 0:3ec7fc598e48 | 17 | { |
Freescale_cup | 0:3ec7fc598e48 | 18 | moteurA_reculer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 19 | moteurA_avancer.write((vitesse_gauche*CORRECTION)/100.0); |
Freescale_cup | 0:3ec7fc598e48 | 20 | } |
Freescale_cup | 0:3ec7fc598e48 | 21 | else//On recule |
Freescale_cup | 0:3ec7fc598e48 | 22 | { |
Freescale_cup | 0:3ec7fc598e48 | 23 | moteurA_avancer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 24 | moteurA_reculer.write(vitesse_gauche/100.0); |
Freescale_cup | 0:3ec7fc598e48 | 25 | } |
Freescale_cup | 0:3ec7fc598e48 | 26 | |
Freescale_cup | 0:3ec7fc598e48 | 27 | |
Freescale_cup | 0:3ec7fc598e48 | 28 | if(vitesse_droite >= 0)//On avance |
Freescale_cup | 0:3ec7fc598e48 | 29 | { |
Freescale_cup | 0:3ec7fc598e48 | 30 | moteurB_reculer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 31 | moteurB_avancer.write(vitesse_droite/100.0); |
Freescale_cup | 0:3ec7fc598e48 | 32 | } |
Freescale_cup | 0:3ec7fc598e48 | 33 | else//On recule |
Freescale_cup | 0:3ec7fc598e48 | 34 | { |
Freescale_cup | 0:3ec7fc598e48 | 35 | moteurB_avancer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 36 | moteurB_reculer.write(vitesse_droite/100.0); |
Freescale_cup | 0:3ec7fc598e48 | 37 | } |
Freescale_cup | 0:3ec7fc598e48 | 38 | |
Freescale_cup | 0:3ec7fc598e48 | 39 | } |
Freescale_cup | 0:3ec7fc598e48 | 40 | void motor_init() |
Freescale_cup | 0:3ec7fc598e48 | 41 | { |
Freescale_cup | 0:3ec7fc598e48 | 42 | moteurA_avancer.period(1.0/FREQ_PWM); |
Freescale_cup | 0:3ec7fc598e48 | 43 | moteurB_avancer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 44 | moteurA_avancer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 45 | moteurB_reculer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 46 | moteurA_reculer.write(0); |
Freescale_cup | 0:3ec7fc598e48 | 47 | activate_motor = 1; |
Freescale_cup | 0:3ec7fc598e48 | 48 | |
Freescale_cup | 0:3ec7fc598e48 | 49 | } |
Freescale_cup | 0:3ec7fc598e48 | 50 | void angle_servo_moteur (double angle) |
Freescale_cup | 0:3ec7fc598e48 | 51 | { |
Freescale_cup | 0:3ec7fc598e48 | 52 | if(angle > 30) angle = 30; |
Freescale_cup | 0:3ec7fc598e48 | 53 | if(angle < -30) angle = -30; |
Freescale_cup | 0:3ec7fc598e48 | 54 | angle = (angle * PWM_ANGLE_DROIT_MAX) / ANGLE_DROIT_MAX; |
Freescale_cup | 0:3ec7fc598e48 | 55 | angle += 0.0725; |
Freescale_cup | 0:3ec7fc598e48 | 56 | servo.write(angle); |
Freescale_cup | 0:3ec7fc598e48 | 57 | } |