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.
 
 
 
 
 
 

175 lines
7.7 KiB

#ifndef __PROTOCOLPTZ_H_INCL__
#define __PROTOCOLPTZ_H_INCL__
// MAVLink Micro Air Vehicle Message Marshalling Library
#include "protocol.h"
#define MAVLINK_CHECK_MESSAGE_LENGTH
//#include "../mavlink/common/mavlink.h"
#include "../mavlink/ardupilotmega/mavlink.h"
#include "../../hardware/uart/serialPort.h"
#include "../../components/base/basicPosition.h"
class objectFlyHunter;
#define TO_UAV_DISCONNECTION_MS 2000
//For Ardupilot custom modes
#define MAV_CMD_DO_SEND_BANNER ((MAV_CMD)42428)
#define MAV_CMD_SET_FACTORY_TEST_MODE ((MAV_CMD)42427)
typedef struct S_MAV_PARAMETER {
uint8_t type;
char name[17];
void * valuePtr;
} MAV_PARAMETER;
typedef std::vector< MAV_PARAMETER*> vectorMAV_PARAMS;
enum Mode {
STABILIZE = 0, // manual airframe angle with manual throttle
ACRO = 1, // manual body-frame angular rate with manual throttle
ALT_HOLD = 2, // manual airframe angle with automatic throttle
AUTO = 3, // fully automatic waypoint control using mission commands
GUIDED = 4, // fully automatic fly to coordinate or fly at velocity/direction using GCS immediate commands
LOITER = 5, // automatic horizontal acceleration with automatic throttle
RTL = 6, // automatic return to launching point
CIRCLE = 7, // automatic circular flight with automatic throttle
LAND = 9, // automatic landing with horizontal position control
DRIFT = 11, // semi-automous position, yaw and throttle control
SPORT = 13, // manual earth-frame angular rate control with manual throttle
FLIP = 14, // automatically flip the vehicle on the roll axis
AUTOTUNE = 15, // automatically tune the vehicle's roll and pitch gains
POSHOLD = 16, // automatic position hold with manual override, with automatic throttle
BRAKE = 17, // full-brake using inertial/GPS system, no pilot input
THROW = 18, // throw to launch mode using inertial/GPS system, no pilot input
AVOID_ADSB = 19, // automatic avoidance of obstacles in the macro scale - e.g. full-sized aircraft
GUIDED_NOGPS = 20, // guided mode but only accepts attitude and altitude
SMART_RTL = 21, // SMART_RTL returns to home by retracing its steps
FLOWHOLD = 22, // FLOWHOLD holds position with optical flow without rangefinder
FOLLOW = 23, // follow attempts to follow another vehicle or ground station
ZIGZAG = 24, // ZIGZAG mode is able to fly in a zigzag manner with predefined point A and point B
SYSTEMID = 25, // System ID mode produces automated system identification signals in the controllers
AUTOROTATE = 26, // Autonomous autorotation
};
/**
* TODO: Add class description
*
* @author gagua
*/
class protocolMAVLINK: public protocolParser {
private:
char m_pComPortName[64];
serialPort * m_pUART;
uint32_t m_nComSpeed;
/* Mavlink communication Params */
uint8_t m_bCID; // Channel ID
uint8_t m_bSID; // System ID
uint8_t m_bUAVID; // UAV ID
bool m_bUAV_Online;
bool m_bPendingRequest;
bool m_bPairingFinished;
bool m_bServoDataActual;
bool m_bScaledPressureDataActual;
bool m_bScaledIMU2DataActual;
bool m_bRCChannelsScaledDataActual;
bool m_bRCChannelsRAWDataActual;
bool m_bRCChannelsOverrideDataActual;
bool m_bRCChannelsDataActual;
bool m_bPressureRAWDataActual;
bool m_bIMURAWDataActual;
bool m_bPowerStatusDataActual;
bool m_bNavCtrlOutputDataActual;
bool m_bMissionCurrentDataActual;
bool m_bLocalPositionNEDDataIsActual;
bool m_bGpsStatusDataActual;
bool m_bGpsRawIntDataActual;
bool m_bGlobalPositionIntDataActual;
bool m_bBatteryStatusDataActual;
bool m_bAttitudeDataActual;
bool m_bSystemTimeDataActual;
bool m_bSystemStatusDataActual;
bool m_bHeartBeatDataActual;
bool m_bUAV_PreArmIssues;
uint32_t m_nUAV_PreArmIssues;
mavlink_gps_status_t m_bGPS_SatNfo;
mavlink_global_position_int_t m_sGPS_PositionNfo;
uint64_t m_nTimeOut;
uint8_t m_bPairingSeqID;
uint16_t m_nServoOutput[16];
int32_t m_nIssuedCMD;
uint16_t m_nIssuedCMDStatus;
mavlink_system_time_t m_sSystemTS;
mavlink_sys_status_t m_sSystemStatus;
mavlink_battery_status_t m_sBatteryStatus;
mavlink_rc_channels_t m_sRC_Channels;
mavlink_rc_channels_override_t m_sRC_ChannelsOverride;
mavlink_rc_channels_raw_t m_sRC_ChannelsRaw;
mavlink_rc_channels_scaled_t m_sRC_ChannelsScaled;
mavlink_attitude_t m_sAttitude;
mavlink_raw_imu_t m_sRawIMU;
mavlink_scaled_imu2_t m_sScaledIMU;
mavlink_raw_pressure_t m_sRawPressure;
mavlink_nav_controller_output_t m_sNavCtrlOutput;
mavlink_gps_raw_int_t m_sGpsRaw;
mavlink_scaled_pressure_t m_sScaledPressure;
mavlink_power_status_t m_sPowerStatus;
mavlink_mission_current_t m_sMissionCurrent;
mavlink_heartbeat_t m_sHeartBit;
mavlink_servo_output_raw_t m_sServoOutputRaw;
mavlink_terrain_request_t m_sTerrainRequest;
mavlink_terrain_report_t m_sTerrainReport;
mavlink_vfr_hud_t m_sVFR_Hud;
mavlink_vibration_t m_sVibration;
mavlink_local_position_ned_t m_sLocalPosition;
/// Sends the specified MAV_CMD to the vehicle. If no Ack is received command will be retried. If a sendMavCommand is already in progress
/// the command will be queued and sent when the previous command completes.
/// @param component Component to send to
/// @param command MAV_CMD to send
/// @param showError true: Display error to user if command failed, false: no error shown
/// Signals: mavCommandResult on success or failure
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);
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);
protected:
virtual int packetChecker(U8* Buffer, size_t BufferSize);
virtual protocolPackage * packetExtractor(U8* Buffer, size_t BufferSize);
virtual bool packetHandler(protocolPackage* Package);
bool setUartDevice(CSTR a);
public:
explicit protocolMAVLINK(config_setting_t* Settings = NULL);
virtual ~protocolMAVLINK();
virtual bool create(void);
CSTR getUartDevice(void) { return (CSTR)m_pComPortName; };
int getLastCmdStatus(void);
/* Protocol Outbond Messages */
bool broadcastReboot(void);
bool broadcastShutdown(void);
bool broadcastProtocolVersionReq(void);
bool broadcastArm(bool stage, bool forced = false);
bool broadcastSetBaseMode(uint8_t bm);
bool broadcastSetCustomMode(uint32_t cm);
bool broadcastFactoryTestMode(bool stage);
bool broadcastTakeoff(float alt = 1.5f);
bool broadcastLand(float lat = 0.f, float lon = 0.f);
bool broadcastLoiter(float lat = 0.f, float lon = 0.f, float alt = 0.f);
bool broadcastCircle(int nTurns, int radius = 0, float lat = 0.f, float lon = 0.f, float alt = 0.f);
bool broadcastBannerRequest(void);
bool broadcastPreflightCalibration(void);
bool setUpdateRate(uint32_t MTYP, uint32_t msec_rate);
bool setTargetPosition(float x, float y, float z, float yaw);
bool setMode(int mode);
bool setMode(uint8_t newBaseMode, uint32_t newCustomMode);
bool setModeArm(uint8_t newBaseMode, uint32_t newCustomMode);
friend objectFlyHunter;
};
#endif // __PROTOCOLPTZ_H_INCL__