Test moteur

Dependencies:   Encoder_Nucleo_16_bits PwmIn mbed

Fork of TestBoardv2_boussole_pixi by ilan Sandoz

Committer:
Dvlader
Date:
Sat Jun 10 05:09:17 2017 +0000
Revision:
10:a98764d33fd5
Parent:
9:53dd6df76cf8
A tester !!!; Si ?a fonctionne, ajoutez En = 1 ? la fonction motor_command

Who changed what in which revision?

UserRevisionLine numberNew contents of line
haarkon 0:f00e68bef80c 1 #include "mbed.h"
haarkon 0:f00e68bef80c 2 #include "PwmIn.h"
haarkon 0:f00e68bef80c 3 #include "Nucleo_Encoder_16_bits.h"
haarkon 0:f00e68bef80c 4
Dvlader 10:a98764d33fd5 5 #define Avance_rapide 100, 100
Dvlader 10:a98764d33fd5 6 //#define Vitesse1 1, 50, 1, 50
Dvlader 10:a98764d33fd5 7 //#define Vitesse2 1, 100, 1, 100
haarkon 0:f00e68bef80c 8
haarkon 0:f00e68bef80c 9 PwmOut Pwm_MG (PB_10);
haarkon 0:f00e68bef80c 10 PwmOut Pwm_MD (PB_3);
Dvlader 9:53dd6df76cf8 11 DigitalOut En (PC_9);
Dvlader 9:53dd6df76cf8 12 DigitalOut SensG (PC_8);
Dvlader 9:53dd6df76cf8 13 DigitalOut SensD (PC_6);
haarkon 0:f00e68bef80c 14
Dvlader 10:a98764d33fd5 15 void motor_command(int mg_command, int md_command, float* mg_pwm, float* md_pwm, int* mg_sens, int* md_sens);
Dvlader 10:a98764d33fd5 16
Dvlader 10:a98764d33fd5 17 //Instructions
Dvlader 10:a98764d33fd5 18
Dvlader 10:a98764d33fd5 19 //mg_command et md_command compris entre -100 et 100
Dvlader 10:a98764d33fd5 20 //void moteur_command(double sensD, double pwmD, double sensG, double pwmG);
haarkon 0:f00e68bef80c 21
Dvlader 9:53dd6df76cf8 22 void main (void)
haarkon 6:88b4805d33e1 23 {
Dvlader 10:a98764d33fd5 24 //Variables
Dvlader 10:a98764d33fd5 25 En = 1;
Dvlader 10:a98764d33fd5 26 float md_pwm = 0;
Dvlader 10:a98764d33fd5 27 float mg_pwm = 0;
Dvlader 10:a98764d33fd5 28 int md_sens = 1;
Dvlader 10:a98764d33fd5 29 int mg_sens = 1;
Dvlader 10:a98764d33fd5 30
Dvlader 10:a98764d33fd5 31 while(1)
Dvlader 10:a98764d33fd5 32 {
Dvlader 10:a98764d33fd5 33 //Appel fonction
Dvlader 10:a98764d33fd5 34
Dvlader 10:a98764d33fd5 35 motor_command(Avance_rapide, &mg_pwm, &md_pwm, &mg_sens, &md_sens);
Dvlader 10:a98764d33fd5 36 }
Dvlader 10:a98764d33fd5 37 }
haarkon 2:1d440e938c44 38
Dvlader 10:a98764d33fd5 39 void motor_command(int mg_command, int md_command, float* mg_pwm, float* md_pwm, int* mg_sens, int* md_sens) {
Dvlader 10:a98764d33fd5 40 if(mg_command >= 0) {
Dvlader 10:a98764d33fd5 41 *mg_sens = 0;
Dvlader 10:a98764d33fd5 42 *mg_pwm = ((mg_command%101)/100);
Dvlader 10:a98764d33fd5 43 } else {
Dvlader 10:a98764d33fd5 44 *mg_sens = 1;
Dvlader 10:a98764d33fd5 45 *mg_pwm = ((-mg_command%101)/100);
Dvlader 10:a98764d33fd5 46 }
Dvlader 10:a98764d33fd5 47 if(md_command >= 0) {
Dvlader 10:a98764d33fd5 48 *mg_sens = 0;
Dvlader 10:a98764d33fd5 49 *md_pwm = ((md_command%101)/100);
Dvlader 10:a98764d33fd5 50 } else {
Dvlader 10:a98764d33fd5 51 *md_sens = 1;
Dvlader 10:a98764d33fd5 52 *md_pwm = ((-md_command%101)/100);
Dvlader 10:a98764d33fd5 53 }
Dvlader 9:53dd6df76cf8 54 }