Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PID ADXL345 Camera_LS_Y201 ITG3200 RangeFinder mbos xbee_lib Motor Servo
Module_Mouvement.cpp
00001 /* Copyright (c) 2012 - 2013 AUTHEUR 00002 * 00003 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 00004 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00005 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00006 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00007 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00008 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00009 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00010 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00011 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00012 */ 00013 00014 /* 00015 * Description 00016 * Input 00017 * Output 00018 */ 00019 00020 #include "Module_Mouvement.h" 00021 #include "Module_Communication.h" 00022 #include "os.h" 00023 00024 // Pointeur sur la classe systeme d'exploitation instancié dans le main 00025 extern mbos os; 00026 00027 00028 DigitalOut led1(LED1); 00029 extern Serial pc; 00030 00031 /* CONSRTRUCTEUR(S) */ 00032 ModuleMouvement::ModuleMouvement() 00033 { 00034 m_gyroX = 0; 00035 m_gyroY = 0; 00036 m_gyroZ = 0; 00037 m_gyro = new ITG3200(SDA, SCL); 00038 m_motor = new Motor(PWM, FDW, REV); 00039 } 00040 00041 /* DESTRUCTEUR */ 00042 ModuleMouvement::~ModuleMouvement() 00043 { 00044 delete m_gyro; 00045 delete m_motor; 00046 } 00047 00048 /* Point d'entrée de la tache Module Mouvement */ 00049 void ModuleMouvement_Task(void) 00050 { 00051 ModuleMouvement *mouv = new ModuleMouvement(); 00052 os.SetTimer(TIMER_MOUV_ID, TIMER_MOUV_PERIOD, TIMER_MOUV_PERIOD); 00053 while(1){ 00054 os.WaitEvent(TIMER_EVENT | COMMUNICATION_EVENT); 00055 if(os.GetEvent() & TIMER_EVENT){ 00056 //send gyro information 00057 led1 = 1; 00058 mouv->getGyroValue(); 00059 pc.printf("Gyroscope [x : %d] [y : %d] [z : %d]\n", mouv->m_gyroX, mouv->m_gyroY, mouv->m_gyroZ); 00060 mouv->creerTrame(getEnvoi()); 00061 pc.printf("trame : %s\n", getEnvoi()); 00062 os.SetEvent(COMMUNICATION_EVENT, TASK_ENVOI); 00063 led1 = 0; 00064 00065 } 00066 if(os.GetEvent() & COMMUNICATION_EVENT){ 00067 //traite commande 00068 pc.printf("mouv receive command\n"); 00069 //mouv->traiteCommande(); 00070 } 00071 } 00072 } 00073 00074 void ModuleMouvement::getGyroValue(){ 00075 m_gyroX = m_gyro->getGyroX(); 00076 m_gyroY = m_gyro->getGyroY(); 00077 m_gyroZ = m_gyro->getGyroZ(); 00078 } 00079 00080 void ModuleMouvement::allumMotor(){ 00081 for(float i = 0.0 ; i < 0.90 ; i += 0.05){ 00082 m_motor->speed(i); 00083 } 00084 } 00085 void ModuleMouvement::eteindMotor(){ 00086 for(float i = 0.90 ; i >= 0.0 ; i -= 0.05){ 00087 m_motor->speed(i); 00088 } 00089 } 00090 00091 void ModuleMouvement::creerTrame(char *envoi){ 00092 //creer un trame envoi pour la tache Com 00093 envoi[0] = 'G'; 00094 memcpy(&envoi[1], &m_gyroX, 4); 00095 memcpy(&envoi[5], &m_gyroY, 4); 00096 memcpy(&envoi[9], &m_gyroZ, 4); 00097 envoi[13] = 'F'; 00098 envoi[14] = '\0'; 00099 00100 } 00101 00102 void ModuleMouvement::traiteCommande(){ 00103 //allum // eteind moteur 00104 }
Generated on Wed Jul 13 2022 02:33:40 by
1.7.2