You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
7.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
  1. #ifndef __PROTOCOLPTZ_H_INCL__
  2. #define __PROTOCOLPTZ_H_INCL__
  3. // MAVLink Micro Air Vehicle Message Marshalling Library
  4. #include "protocol.h"
  5. #define MAVLINK_CHECK_MESSAGE_LENGTH
  6. //#include "../mavlink/common/mavlink.h"
  7. #include "../mavlink/ardupilotmega/mavlink.h"
  8. #include "../../hardware/uart/serialPort.h"
  9. #include "../../components/base/basicPosition.h"
  10. class objectFlyHunter;
  11. #define TO_UAV_DISCONNECTION_MS 2000
  12. //For Ardupilot custom modes
  13. #define MAV_CMD_DO_SEND_BANNER ((MAV_CMD)42428)
  14. #define MAV_CMD_SET_FACTORY_TEST_MODE ((MAV_CMD)42427)
  15. typedef struct S_MAV_PARAMETER {
  16. uint8_t type;
  17. char name[17];
  18. void * valuePtr;
  19. } MAV_PARAMETER;
  20. typedef std::vector< MAV_PARAMETER*> vectorMAV_PARAMS;
  21. enum Mode {
  22. STABILIZE = 0, // manual airframe angle with manual throttle
  23. ACRO = 1, // manual body-frame angular rate with manual throttle
  24. ALT_HOLD = 2, // manual airframe angle with automatic throttle
  25. AUTO = 3, // fully automatic waypoint control using mission commands
  26. GUIDED = 4, // fully automatic fly to coordinate or fly at velocity/direction using GCS immediate commands
  27. LOITER = 5, // automatic horizontal acceleration with automatic throttle
  28. RTL = 6, // automatic return to launching point
  29. CIRCLE = 7, // automatic circular flight with automatic throttle
  30. LAND = 9, // automatic landing with horizontal position control
  31. DRIFT = 11, // semi-automous position, yaw and throttle control
  32. SPORT = 13, // manual earth-frame angular rate control with manual throttle
  33. FLIP = 14, // automatically flip the vehicle on the roll axis
  34. AUTOTUNE = 15, // automatically tune the vehicle's roll and pitch gains
  35. POSHOLD = 16, // automatic position hold with manual override, with automatic throttle
  36. BRAKE = 17, // full-brake using inertial/GPS system, no pilot input
  37. THROW = 18, // throw to launch mode using inertial/GPS system, no pilot input
  38. AVOID_ADSB = 19, // automatic avoidance of obstacles in the macro scale - e.g. full-sized aircraft
  39. GUIDED_NOGPS = 20, // guided mode but only accepts attitude and altitude
  40. SMART_RTL = 21, // SMART_RTL returns to home by retracing its steps
  41. FLOWHOLD = 22, // FLOWHOLD holds position with optical flow without rangefinder
  42. FOLLOW = 23, // follow attempts to follow another vehicle or ground station
  43. ZIGZAG = 24, // ZIGZAG mode is able to fly in a zigzag manner with predefined point A and point B
  44. SYSTEMID = 25, // System ID mode produces automated system identification signals in the controllers
  45. AUTOROTATE = 26 // Autonomous autorotation
  46. };
  47. /**
  48. * TODO: Add class description
  49. *
  50. * @author gagua
  51. */
  52. class protocolMAVLINK: public protocolParser {
  53. private:
  54. basicLogCollection * m_pLog;
  55. char m_pComPortName[64];
  56. serialPort * m_pUART;
  57. uint32_t m_nComSpeed;
  58. /* Mavlink communication Params */
  59. uint8_t m_bCID; // Channel ID
  60. uint8_t m_bSID; // System ID
  61. uint8_t m_bUAVID; // UAV ID
  62. bool m_bUAV_Online;
  63. bool m_bPendingRequest;
  64. bool m_bPairingFinished;
  65. bool m_bServoDataActual;
  66. bool m_bScaledPressureDataActual;
  67. bool m_bScaledIMU2DataActual;
  68. bool m_bRCChannelsScaledDataActual;
  69. bool m_bRCChannelsRAWDataActual;
  70. bool m_bRCChannelsOverrideDataActual;
  71. bool m_bRCChannelsDataActual;
  72. bool m_bPressureRAWDataActual;
  73. bool m_bIMURAWDataActual;
  74. bool m_bPowerStatusDataActual;
  75. bool m_bNavCtrlOutputDataActual;
  76. bool m_bMissionCurrentDataActual;
  77. bool m_bLocalPositionNEDDataIsActual;
  78. bool m_bGpsStatusDataActual;
  79. bool m_bGpsRawIntDataActual;
  80. bool m_bGlobalPositionIntDataActual;
  81. bool m_bBatteryStatusDataActual;
  82. bool m_bAttitudeDataActual;
  83. bool m_bSystemTimeDataActual;
  84. bool m_bSystemStatusDataActual;
  85. bool m_bHeartBeatDataActual;
  86. bool m_bUAV_PreArmIssues;
  87. uint32_t m_nUAV_PreArmIssues;
  88. mavlink_gps_status_t m_bGPS_SatNfo;
  89. mavlink_global_position_int_t m_sGPS_PositionNfo;
  90. uint64_t m_nTimeOut;
  91. uint8_t m_bPairingSeqID;
  92. uint16_t m_nServoOutput[16];
  93. int32_t m_nIssuedCMD;
  94. uint16_t m_nIssuedCMDStatus;
  95. mavlink_system_time_t m_sSystemTS;
  96. mavlink_sys_status_t m_sSystemStatus;
  97. mavlink_battery_status_t m_sBatteryStatus;
  98. mavlink_rc_channels_t m_sRC_Channels;
  99. mavlink_rc_channels_override_t m_sRC_ChannelsOverride;
  100. mavlink_rc_channels_raw_t m_sRC_ChannelsRaw;
  101. mavlink_rc_channels_scaled_t m_sRC_ChannelsScaled;
  102. mavlink_attitude_t m_sAttitude;
  103. mavlink_raw_imu_t m_sRawIMU;
  104. mavlink_scaled_imu2_t m_sScaledIMU;
  105. mavlink_raw_pressure_t m_sRawPressure;
  106. mavlink_nav_controller_output_t m_sNavCtrlOutput;
  107. mavlink_gps_raw_int_t m_sGpsRaw;
  108. mavlink_scaled_pressure_t m_sScaledPressure;
  109. mavlink_power_status_t m_sPowerStatus;
  110. mavlink_mission_current_t m_sMissionCurrent;
  111. mavlink_heartbeat_t m_sHeartBit;
  112. mavlink_servo_output_raw_t m_sServoOutputRaw;
  113. mavlink_terrain_request_t m_sTerrainRequest;
  114. mavlink_terrain_report_t m_sTerrainReport;
  115. mavlink_vfr_hud_t m_sVFR_Hud;
  116. mavlink_vibration_t m_sVibration;
  117. mavlink_local_position_ned_t m_sLocalPosition;
  118. /// Sends the specified MAV_CMD to the vehicle. If no Ack is received command will be retried. If a sendMavCommand is already in progress
  119. /// the command will be queued and sent when the previous command completes.
  120. /// @param component Component to send to
  121. /// @param command MAV_CMD to send
  122. /// @param showError true: Display error to user if command failed, false: no error shown
  123. /// Signals: mavCommandResult on success or failure
  124. bool sendMavCommand(int component, MAV_CMD command, bool showError, float param1 = 0.0f, float param2 = 0.0f, float param3 = 0.0f, float param4 = 0.0f, float param5 = 0.0f, float param6 = 0.0f, float param7 = 0.0f);
  125. bool sendMavCommandInt(int component, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7);
  126. protected:
  127. virtual int packetChecker(U8* Buffer, size_t BufferSize);
  128. virtual protocolPackage * packetExtractor(U8* Buffer, size_t BufferSize);
  129. virtual bool packetHandler(protocolPackage* Package);
  130. bool setUartDevice(CSTR a);
  131. public:
  132. explicit protocolMAVLINK(config_setting_t* Settings = NULL);
  133. virtual ~protocolMAVLINK();
  134. virtual bool create(void);
  135. CSTR getUartDevice(void) { return (CSTR)m_pComPortName; };
  136. int getLastCmdStatus(void);
  137. /* Protocol Outbond Messages */
  138. bool broadcastReboot(void);
  139. bool broadcastShutdown(void);
  140. bool broadcastProtocolVersionReq(void);
  141. bool broadcastArm(bool stage, bool forced = false);
  142. bool broadcastSetBaseMode(uint8_t bm);
  143. bool broadcastSetCustomMode(uint32_t cm);
  144. bool broadcastFactoryTestMode(bool stage);
  145. bool broadcastTakeoff(float alt = 1.5f);
  146. bool broadcastLand(float lat = 0.f, float lon = 0.f);
  147. bool broadcastLoiter(float lat = 0.f, float lon = 0.f, float alt = 0.f);
  148. bool broadcastCircle(int nTurns, int radius = 0, float lat = 0.f, float lon = 0.f, float alt = 0.f);
  149. bool broadcastBannerRequest(void);
  150. bool broadcastPreflightCalibration(void);
  151. bool setUpdateRate(uint32_t MTYP, uint32_t msec_rate);
  152. bool setTargetPosition(float x, float y, float z, float yaw);
  153. bool setMode(int mode);
  154. bool setMode(uint8_t newBaseMode, uint32_t newCustomMode);
  155. bool setModeArm(uint8_t newBaseMode, uint32_t newCustomMode);
  156. friend objectFlyHunter;
  157. };
  158. #endif // __PROTOCOLPTZ_H_INCL__