projet tut 2019
Dependencies: mbed Grove_LCD_RGB_Backlight
main.cpp@0:94131475b4c1, 2019-02-11 (annotated)
- Committer:
- Boborski
- Date:
- Mon Feb 11 14:45:39 2019 +0000
- Revision:
- 0:94131475b4c1
programme test Servo moteur by Bagrow
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Boborski | 0:94131475b4c1 | 1 | //Cachan Programme Principal mbed 1 |
Boborski | 0:94131475b4c1 | 2 | #include "mbed.h" |
Boborski | 0:94131475b4c1 | 3 | #include "Grove_LCD_RGB_Backlight.h" |
Boborski | 0:94131475b4c1 | 4 | |
Boborski | 0:94131475b4c1 | 5 | |
Boborski | 0:94131475b4c1 | 6 | //////////////////////////////////////// DEFINE //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 7 | //période servomoteur |
Boborski | 0:94131475b4c1 | 8 | #define PERIODSERVO 0.02 |
Boborski | 0:94131475b4c1 | 9 | |
Boborski | 0:94131475b4c1 | 10 | |
Boborski | 0:94131475b4c1 | 11 | //angle du servomoteur du perceur en position éteint |
Boborski | 0:94131475b4c1 | 12 | #define ANGLESERVOARRET 19275 |
Boborski | 0:94131475b4c1 | 13 | //angle du servomoteur du perceur à hauteur du ballon |
Boborski | 0:94131475b4c1 | 14 | #define ANGLEBALLON 18000 |
Boborski | 0:94131475b4c1 | 15 | |
Boborski | 0:94131475b4c1 | 16 | //longeur de la trame de la mbed1 vers la mbed2 |
Boborski | 0:94131475b4c1 | 17 | #define LONGTRAME1TO2 6 |
Boborski | 0:94131475b4c1 | 18 | |
Boborski | 0:94131475b4c1 | 19 | |
Boborski | 0:94131475b4c1 | 20 | |
Boborski | 0:94131475b4c1 | 21 | //////////////////////////////////////// Entrées //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 22 | |
Boborski | 0:94131475b4c1 | 23 | |
Boborski | 0:94131475b4c1 | 24 | //////////////////////////////////////// Sorties //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 25 | //Sens des 2 moteurs principaux |
Boborski | 0:94131475b4c1 | 26 | DigitalOut MotGSens (p16); |
Boborski | 0:94131475b4c1 | 27 | DigitalOut MotDSens (p17); |
Boborski | 0:94131475b4c1 | 28 | |
Boborski | 0:94131475b4c1 | 29 | //PWM du servo de perçage, du moteur de perçage et des moteurs principaux |
Boborski | 0:94131475b4c1 | 30 | PwmOut servo(p23); |
Boborski | 0:94131475b4c1 | 31 | |
Boborski | 0:94131475b4c1 | 32 | |
Boborski | 0:94131475b4c1 | 33 | //////////////////////////////////////// Timer/Ticker //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 34 | |
Boborski | 0:94131475b4c1 | 35 | |
Boborski | 0:94131475b4c1 | 36 | //////////////////////////////////////// Prototypes //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 37 | void Percage (void); |
Boborski | 0:94131475b4c1 | 38 | |
Boborski | 0:94131475b4c1 | 39 | |
Boborski | 0:94131475b4c1 | 40 | //////////////////////////////////////// Variables globales //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 41 | //Angle donné au servo, qui est un pulsewidth |
Boborski | 0:94131475b4c1 | 42 | int giAngle= ANGLESERVOARRET; |
Boborski | 0:94131475b4c1 | 43 | |
Boborski | 0:94131475b4c1 | 44 | |
Boborski | 0:94131475b4c1 | 45 | //////////////////////////////////////// Main //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 46 | int main() |
Boborski | 0:94131475b4c1 | 47 | { |
Boborski | 0:94131475b4c1 | 48 | servo.period(PERIODSERVO); |
Boborski | 0:94131475b4c1 | 49 | |
Boborski | 0:94131475b4c1 | 50 | while(1) { |
Boborski | 0:94131475b4c1 | 51 | Percage (); |
Boborski | 0:94131475b4c1 | 52 | wait(1); |
Boborski | 0:94131475b4c1 | 53 | } |
Boborski | 0:94131475b4c1 | 54 | } |
Boborski | 0:94131475b4c1 | 55 | |
Boborski | 0:94131475b4c1 | 56 | |
Boborski | 0:94131475b4c1 | 57 | //////////////////////////////////////// Fonctions //////////////////////////////////////// |
Boborski | 0:94131475b4c1 | 58 | |
Boborski | 0:94131475b4c1 | 59 | |
Boborski | 0:94131475b4c1 | 60 | //Déplacement pré-reglé du servo de perçage et 1/0 moteur de perçage |
Boborski | 0:94131475b4c1 | 61 | void Percage () |
Boborski | 0:94131475b4c1 | 62 | { |
Boborski | 0:94131475b4c1 | 63 | int i; |
Boborski | 0:94131475b4c1 | 64 | |
Boborski | 0:94131475b4c1 | 65 | //Montée du bras |
Boborski | 0:94131475b4c1 | 66 | for(i=ANGLESERVOARRET; i>=ANGLEBALLON; i=i-50) { |
Boborski | 0:94131475b4c1 | 67 | //printf("angle=%d\n\r", i); |
Boborski | 0:94131475b4c1 | 68 | servo.pulsewidth_us(i); |
Boborski | 0:94131475b4c1 | 69 | wait(0.01); |
Boborski | 0:94131475b4c1 | 70 | } |
Boborski | 0:94131475b4c1 | 71 | //Arret en haut |
Boborski | 0:94131475b4c1 | 72 | wait(1); |
Boborski | 0:94131475b4c1 | 73 | for(i=ANGLEBALLON; i<=ANGLESERVOARRET; i=i+25) { |
Boborski | 0:94131475b4c1 | 74 | //printf("angle=%d\n\r", i); |
Boborski | 0:94131475b4c1 | 75 | servo.pulsewidth_us(i); |
Boborski | 0:94131475b4c1 | 76 | wait(0.01); |
Boborski | 0:94131475b4c1 | 77 | } |
Boborski | 0:94131475b4c1 | 78 | } |