HummingBirdUavComm.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00032 
00033 #ifndef __HUMMING_BIRD_UAV_COMM_H__
00034 #define __HUMMING_BIRD_UAV_COMM_H__
00035 
00036 #ifdef MIP_HOST_APPLE
00037 #include <applePatch.h>
00038 #endif
00039 
00040 // --- Included to manage serial communication
00041 #include <termios.h>
00042 #include <unistd.h>
00043 
00044 #include <sys/types.h>
00045 #include <sys/stat.h>
00046 #include <fcntl.h>
00047 // ---
00048 
00049 #include "HBstructs.h"
00050 // #include "baselib.h"
00051 #include <iostream>
00052 
00053 #define CHARSIZE sizeof(char)
00054 #define LABDATASIZE sizeof(LABROB_FLIGHT_DATA)
00055 
00056 using namespace std;
00057 
00058 namespace MipResources {
00060  /* @{ */
00061  
00070  
00071  class HummingBirdUavComm {
00072  private:
00073  char  recC;
00074  bool  WaitSeq;
00075  int  state;
00076  int  nTry;
00077  // Wait for init sequence
00078  int BytesRead;
00079  unsigned short  struct_l;   
00080  unsigned char  struct_d;   
00081  unsigned short  crc_chksum;  
00082 
00083  const char *portName;      
00084  uint port;                 
00085  struct termios pOptions;   
00086  int   startstring_size;
00087 
00090  void InitializeComPort(const char *portname = "/dev/ttyUSB0");
00091 
00094  void updateChksum(LABROB_CTRL_INPUT &ctr) {
00095  ctr.chksum = ctr.pitch + ctr.roll + ctr.yaw + ctr.thrust + ctr.ctrl + ctr.height_ref + 0xAAAA;
00096  };
00097 
00102  void updateChksum(LABROB_CTRL_FLAGS &ctr) {
00103  ctr.chksum = ctr.send + ctr.controllers + ctr.flight_data_delay + ctr.ctrl_flags_delay + ctr.ctrl_input_delay + ctr.height_control_delay + 0xAAAA;
00104  };
00105 
00108  void updateChksum(LABROB_CONTROLLERS_GAINS &ctr) {
00109  ctr.chksum = ctr.height_pid[0] + ctr.height_pid[1] + ctr.height_pid[2] + 0xAAAA;
00110  };
00111 
00114  void updateChksum(LABROB_FILTERS_GAINS &ctr) {
00115  ctr.chksum = ctr.sonar_height_filter[0] + ctr.sonar_height_filter[1] + 0xAAAA;
00116  };
00117 
00120  void updateChksum(LABROB_POSE_INPUT &ctr) {
00121  ctr.chksum = ctr.pos_x + ctr.pos_y + ctr.pos_z + ctr.ori_x + ctr.ori_y + ctr.ori_z + ctr.time[0] + ctr.time[1] + 0xAAAA;
00122  };
00123 
00127  unsigned short crc_update(unsigned short crc, unsigned char data);
00128  public:
00130  string getObjectName() const {
00131  return "HummingBirdUavComm";
00132  }
00133 
00136  HummingBirdUavComm(int argc, const char *argv[]);
00137 
00140  HummingBirdUavComm(const char *portname);
00141 
00143  ~HummingBirdUavComm();
00144 
00147  uint getPort() { return port; };
00148 
00152  int send(void *msg, unsigned short size);
00153 
00158  int receive(void *buffer, unsigned short numChar);
00159 
00163  int requestData(unsigned short dataType);
00164 
00169  int waitForData(void * dataP, int &packet_descriptor);
00170 
00174  int transmitControl(struct LABROB_CTRL_INPUT &ctrl);
00175 
00179  int transmitControlFlags(struct LABROB_CTRL_FLAGS &ctrl);
00180 
00184  int transmitControlGains(struct LABROB_CONTROLLERS_GAINS &ctrl);
00185 
00189  int transmitFilterGains(struct LABROB_FILTERS_GAINS &ctrl);
00190 
00194  int transmitPoseInput(struct LABROB_POSE_INPUT &ctrl);
00195 
00200  unsigned short crc16(void *data, unsigned short cnt);
00201  };
00202 
00203 }; // end of namespace MipResources
00204 
00205 
00206 #endif
00207 
00208 /* @} */

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6