ajout module_mouvement
Dependencies: mbed xbee_lib ADXL345_I2C IMUfilter ITG3200 Motor RangeFinder Servo mbos PID
Fork of Labo_TRSE_Drone by
Revision 30:8374d1017296, committed 2013-04-22
- Comitter:
- arnaudsuire
- Date:
- Mon Apr 22 19:09:53 2013 +0000
- Parent:
- 29:f8bda24002f6
- Commit message:
- lundi 22
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Librairies/FastPWM.lib Mon Apr 22 19:09:53 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/FastPWM/#3094d3806cfc
--- a/Module_Asservissement/Sous_Module_Mouvement/Module_Mouvement.cpp Wed Apr 17 10:10:51 2013 +0000 +++ b/Module_Asservissement/Sous_Module_Mouvement/Module_Mouvement.cpp Mon Apr 22 19:09:53 2013 +0000 @@ -22,14 +22,19 @@ // Pointeur sur la classe systeme d'exploitation instancié dans le main extern mbos *os; + //communication série USB + Serial pc1(USBTX,USBRX); + + + /* CONSRTRUCTEUR(S) */ ModuleMouvement::ModuleMouvement() { - m_motor1 = new Motor(p21, p6, p5); - m_motor2 = new Motor(p22, p6, p5); - m_motor3 = new Motor(p23, p6, p5); - m_motor4 = new Motor(p24, p6, p5); + m_motor1 = new PwmOut (p21); + m_motor2 = new PwmOut (p22); + m_motor3 = new PwmOut (p23); + m_motor4 = new PwmOut (p24); } /* DESTRUCTEUR */ @@ -49,7 +54,7 @@ int ModuleMouvement::GetuiCommand() { return m_uiCommand; } - int ModuleMouvement::GetuiDistance() + float ModuleMouvement::GetuiDistance() { return m_uiDistance; } @@ -60,7 +65,7 @@ void ModuleMouvement::SetuiCommand(int n) { m_uiCommand = n ; } - void ModuleMouvement::SetuiDistance(int o) + void ModuleMouvement::SetuiDistance(float o) { m_uiDistance = o ; } @@ -68,32 +73,42 @@ /* Point d'entrée de la tache Module Mouvement */ void ModuleMouvement::ModuleMouvement_Task(void) { + //init moteurs + InitMotor(); + + //décollage + m_uiCommand = 0; + m_uiDistance = 0.6; //60cm + GestionVitesseMotors(m_uiCommand, m_uiDistance); + + //vol stationnaire + VolStationnaire(); + + while(1){ + // recuperation commande provenant de trajectoire, comment recup, quel format, quel taille? // gestion motors + // gestion stabilisation, get services? } } void ModuleMouvement::VolStationnaire(void) { - m_motor1.speed(0.2); // a def - m_motor2.speed(0.2); // a def - m_motor3.speed(0.2); // a def - m_motor4.speed(0.2); // a def - while ( /*pas de nouvelle commande*/ ) + m_motor1->write(0.68); // a def + m_motor2->write(0.68); // a def + m_motor3->write(0.68); // a def + m_motor4->write(0.68); // a def + /*while ( pas de nouvelle commande ) { wait(0.1); - } - m_motor1.stop(); - m_motor2.stop(); - m_motor3.stop(); - m_motor4.stop(); - wait(0.01); + }*/ + return; } - void ModuleMouvement::GestionVitesseMotors(int m_uiCommand, int m_uiDistance) + void ModuleMouvement::GestionVitesseMotors(int m_uiCommand, float m_uiDistance) { bool CommandFin = false; @@ -139,8 +154,12 @@ //Liste infos break; - CommandFin = true; + default : + /*erreur pas de commande*/ + + } + CommandFin = true; } void ModuleMouvement::GestionStabilisation(void) @@ -148,37 +167,58 @@ } - void ModuleMouvement:TestMotor(void) + void ModuleMouvement::TestMotor(void) { - for (float s= -1.0; s < 1.0 ; s += 0.01) + + //frequence à 500Hz (init à 0.40 PWMmax = 0.99) + m_motor1->period(0.002); + + //initialisation, attends du premier bip + for (float s= 0; s < 0.40; s += 0.01) { - m_motor1.speed(s); - wait(0.02); - } - m_motor1.stop(); - - - - for (float s= -1.0; s < 1.0 ; s += 0.01) - { - m_motor2.speed(s); - wait(0.02); + m_motor1->write(s); + wait(0.2); + pc1.printf("%f", s); } - m_motor2.stop(); - + wait(2); + + m_motor1->write(0.96); + pc1.printf("test motor"); + - for (float s= -1.0; s < 1.0 ; s += 0.01) + } + + + void ModuleMouvement::InitMotor(void) + { + //frequence à 500Hz (init à 0.40 PWMmax = 0.99) + m_motor1->period(0.002); + m_motor2->period(0.002); + m_motor3->period(0.002); + m_motor4->period(0.002); + + //frequence à 400HZ (attention : init à 0.30 et PWMmax=0.85, trés rapide à l'acceleration ) + //m_motor1->period(0.0025); + + //initialisation, attends du premier bip + for (float s= 0; s < 0.40; s += 0.01) { - m_motor3.speed(s); - wait(0.02); + m_motor1->write(s); + wait(0.2); + pc1.printf("%f", s); } - m_motor3.stop(); - - - for (float s= -1.0; s < 1.0 ; s += 0.01) + wait(1); + } + + + void ModuleMouvement::DeconnexionMotor(void) + { + //deconnexion + for(float s= 0.40; s > 0; s-= 0.01) { - m_motor4.speed(s); - wait(0.02); + m_motor1->write(s); + wait(0.01); + pc1.printf("%f", s); } - m_motor4.stop(); - } \ No newline at end of file + wait(1); + } \ No newline at end of file
--- a/Module_Asservissement/Sous_Module_Mouvement/Module_Mouvement.h Wed Apr 17 10:10:51 2013 +0000 +++ b/Module_Asservissement/Sous_Module_Mouvement/Module_Mouvement.h Mon Apr 22 19:09:53 2013 +0000 @@ -22,22 +22,25 @@ #include "mbos.h" #include "Service.h" - #include "Motor.h" + #include "mbed.h" + + class ModuleMouvement { private : /* ATTRIBUTS */ - Motor * m_motor1; - Motor * m_motor2; - Motor * m_motor3; - Motor * m_motor4; + PwmOut * m_motor1; + PwmOut * m_motor2; + PwmOut * m_motor3; + PwmOut * m_motor4; + /*Parametres*/ int pVitesseFonctionnement; /*commande*/ int m_uiCommand; - int m_uiDistance; + float m_uiDistance; public : @@ -45,12 +48,14 @@ /* Get param*/ int GetpVitesseFonctionnement(); int GetuiCommand(); - int GetuiDistance(); + float GetuiDistance(); + + /*Set param*/ void SetpVitesseFonctionnement(int); void SetuiCommand(int); - void SetuiDistance(int); + void SetuiDistance(float); /* CONSTRUCTEUR(S) */ ModuleMouvement(); @@ -62,10 +67,12 @@ /* METHODES */ /* Point d'entrée de la tache du Module Mouvement */ void ModuleMouvement_Task(void); - void GestionVitesseMotors(int m_uiCommand, int m_uiDistance); + void GestionVitesseMotors(int m_uiCommand, float m_uiDistance); void GestionStabilisation(void); void VolStationnaire(void); void TestMotor(void); + void InitMotor(void); + void DeconnexionMotor(void); /* FONCTIONS */
--- a/main.cpp Wed Apr 17 10:10:51 2013 +0000 +++ b/main.cpp Mon Apr 22 19:09:53 2013 +0000 @@ -34,6 +34,7 @@ }*/ #include "mbed.h" #include "mbos.h" +#include "Module_Mouvement.h" #define TASK1_ID 1 // Id for task 1 (idle task is 0) #define TASK1_PRIO 50 // priority for task 1 @@ -52,16 +53,27 @@ DigitalOut led1(LED1); DigitalOut led2(LED2); mbos os(2, 1); // Instantiate mbos with 2 tasks & 1 timer + + + +//ModuleMouvement toto; +//ModuleMouvement toto1; +ModuleMouvement toto2; + int main(void) { // Configure tasks and timers - os.CreateTask(TASK1_ID, TASK1_PRIO, TASK1_STACK_SZ, task1); + /* os.CreateTask(TASK1_ID, TASK1_PRIO, TASK1_STACK_SZ, task1); os.CreateTask(TASK2_ID, TASK2_PRIO, TASK2_STACK_SZ, task2); os.CreateTimer(TIMER0_ID, TIMER0_EVENT, TASK1_ID); // Start mbos - os.Start(); + os.Start();*/ // never return! + + //test motor + toto2.TestMotor(); + } void task1(void)