ajout module_mouvement
Dependencies: mbed xbee_lib ADXL345_I2C IMUfilter ITG3200 Motor RangeFinder Servo mbos PID
Fork of Labo_TRSE_Drone by
Module_Communication.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 : Cette classe contient les fonctionnalités du module communication. 00016 Le module communication gère la communication entre les modules présents sur le drône et le PC. 00017 * Input 00018 * Output 00019 */ 00020 00021 #include "Module_Communication.h" 00022 00023 // Pointeur sur la classe systeme d'exploitation instancié dans le main 00024 extern mbos *os; 00025 extern unsigned int COMMANDE_TRAJECTOIRE; 00026 extern bool STOP; 00027 extern bool EN_MOUVEMENT; 00028 extern position COORDONNEE_DRONE; 00029 00030 00031 /* CONSRTRUCTEUR(S) */ 00032 C_ModuleCommunication::C_ModuleCommunication() 00033 { 00034 m_xbee = new xbee(p9, p10, p11); 00035 m_trameRxBuffer = C_FrameBuffer(); 00036 m_trameTxBuffer = C_FrameBuffer(); 00037 m_charRxBuffer = new char[17]; 00038 m_charTxBuffer = new char[17]; 00039 } 00040 00041 /* DESTRUCTEUR */ 00042 C_ModuleCommunication::~C_ModuleCommunication() 00043 { 00044 delete [] m_charRxBuffer; 00045 delete [] m_charTxBuffer; 00046 delete m_xbee; 00047 } 00048 00049 /* Point d'entrée de la tache Module Video */ 00050 void C_ModuleCommunication::moduleCommunicationTask(void) 00051 { 00052 while(1){ 00053 // Code 00054 } 00055 } 00056 00057 void C_ModuleCommunication::envoiDeTrame(void) 00058 { 00059 frame newFrame = m_trameTxBuffer.frameBuffer(); 00060 m_charTxBuffer[0] = 0x02; 00061 m_charTxBuffer[1] = newFrame.systemIdentifier; 00062 m_charTxBuffer[2] = newFrame.moduleIdentifier; 00063 m_charTxBuffer[3] = newFrame.messageIdentifier; 00064 m_charTxBuffer[16] = 0x03; 00065 00066 for(int i = 0; i < 12; i++) { 00067 m_charTxBuffer[i+4] = newFrame.data[i]; 00068 } 00069 00070 m_xbee->SendData(m_charTxBuffer); 00071 } 00072 00073 void C_ModuleCommunication::receptionDeTrame(void) 00074 { 00075 Serial pc(USBTX, USBRX); 00076 m_xbee->RecieveData(m_charRxBuffer, 0); 00077 pc.printf("You said:%s \n",m_charRxBuffer); 00078 00079 00080 frame newFrame; 00081 newFrame.systemIdentifier = m_charRxBuffer[1]; 00082 newFrame.moduleIdentifier = m_charRxBuffer[2]; 00083 newFrame.messageIdentifier = m_charRxBuffer[3]; 00084 00085 for(int i = 0; i < 12; i++) { 00086 newFrame.data[i] = m_charRxBuffer[i+4]; 00087 } 00088 00089 m_trameRxBuffer.frameBuffer(newFrame); 00090 } 00091 00092 void C_ModuleCommunication::traitementTrame(void) 00093 { 00094 if(m_trameRxBuffer.numberMessage() <= 0) return; 00095 00096 frame newFrame = m_trameRxBuffer.frameBuffer(); 00097 00098 switch(newFrame.moduleIdentifier) { 00099 case 0x31 : consigneModuleTrajectoire(newFrame); 00100 break; 00101 case 0x32 : consigneModuleVideo(newFrame); 00102 break; 00103 00104 default : creerTrameSpeciale(0x99); 00105 break; 00106 00107 } 00108 } 00109 00110 void C_ModuleCommunication::consigneModuleTrajectoire(frame newFrame) 00111 { 00112 switch(newFrame.messageIdentifier) { 00113 case 0x11 : COMMANDE_TRAJECTOIRE = newFrame.data[0]; 00114 EN_MOUVEMENT = true; 00115 while(EN_MOUVEMENT != false); 00116 creerTrameModuleTrajectoire(0x12); 00117 break; 00118 case 0x13 : STOP = true; 00119 EN_MOUVEMENT = true; 00120 while(EN_MOUVEMENT != false); 00121 creerTrameModuleTrajectoire(0x14); 00122 break; 00123 case 0x15 : creerTrameModuleTrajectoire(0x16); 00124 break; 00125 00126 default : creerTrameSpeciale(0x99); 00127 break; 00128 } 00129 } 00130 00131 void C_ModuleCommunication::creerTrameModuleTrajectoire(unsigned char idMessage) 00132 { 00133 frame newFrame; 00134 newFrame.moduleIdentifier = 0x31; 00135 00136 switch(idMessage) { 00137 case 0x12 : newFrame.messageIdentifier = 0x12; 00138 break; 00139 case 0x14 : newFrame.messageIdentifier = 0x14; 00140 break; 00141 case 0x16 : newFrame.messageIdentifier = 0x16; 00142 union conversionCharFloat conv1; 00143 conv1.f = COORDONNEE_DRONE.x; 00144 newFrame.data[0] = conv1.ch[0]; 00145 newFrame.data[1] = conv1.ch[1]; 00146 newFrame.data[2] = conv1.ch[2]; 00147 newFrame.data[3] = conv1.ch[3]; 00148 conv1.f = 0; 00149 conv1.f = COORDONNEE_DRONE.y; 00150 newFrame.data[4] = conv1.ch[0]; 00151 newFrame.data[5] = conv1.ch[1]; 00152 newFrame.data[6] = conv1.ch[2]; 00153 newFrame.data[7] = conv1.ch[3]; 00154 conv1.f = 0; 00155 conv1.f = COORDONNEE_DRONE.z; 00156 newFrame.data[8] = conv1.ch[0]; 00157 newFrame.data[9] = conv1.ch[1]; 00158 newFrame.data[10] = conv1.ch[2]; 00159 newFrame.data[11] = conv1.ch[3]; 00160 break; 00161 } 00162 00163 m_trameTxBuffer.frameBuffer(newFrame); 00164 } 00165 00166 void C_ModuleCommunication::creerTrameSpeciale(unsigned char idMessage) { 00167 frame newFrame; 00168 00169 switch(idMessage) { 00170 case 0x00 : newFrame.moduleIdentifier = 0x00; 00171 newFrame.messageIdentifier = 0x00; 00172 break; 00173 case 0x99 : newFrame.moduleIdentifier = 0x99; 00174 newFrame.messageIdentifier = 0x99; 00175 break; 00176 } 00177 m_trameTxBuffer.frameBuffer(newFrame); 00178 } 00179 00180 void C_ModuleCommunication::consigneModuleVideo(frame newFrame) 00181 { 00182 }
Generated on Wed Jul 13 2022 00:16:44 by 1.7.2