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.

182 lines
7.2 KiB

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