|
|
#include "objectFlyHunter.h"
#define LOG( X ) m_pLog->Log( "FlyHunter", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "FlyHunter", this, _LOG_ERROR, X )
objectFlyHunter::objectFlyHunter(config_setting_t* Settings):basicObject(){ m_pLog = basicLogCollection::getInstance(); updateOrientation = NULL; m_bArmed = false; m_eCurrentMode = FH_NO_CONNECTION; m_bUAV_type = -1; m_bUAV_ctrl = -1; m_bUAV_bMODE = 0; m_nUAV_cMODE = 0; m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, (CSTR)"FLY_HUNTER"); m_pProtocol = new protocolMAVLINK(m_pSettings); if (m_pSettings != NULL) { config_setting_t * pSetting; double tVal1, tVal2, tVal3; pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_LAT"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_LAT", CONFIG_TYPE_FLOAT); tVal1 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal1); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal1 = config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_LON"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_LON", CONFIG_TYPE_FLOAT); tVal2 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal2); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal2 = config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_ALT"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_ALT", CONFIG_TYPE_FLOAT); tVal3 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal3); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal3 = config_setting_get_float(pSetting); }; m_oPosition.setPositionWGS84(tVal1, tVal2, tVal3); pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_ROLL"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_ROLL", CONFIG_TYPE_FLOAT); tVal1 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal1); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal1 = config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_PITCH"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_PITCH", CONFIG_TYPE_FLOAT); tVal2 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal2); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal2 = config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_YAW"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_YAW", CONFIG_TYPE_FLOAT); tVal3 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal3); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal3 = config_setting_get_float(pSetting); }; m_oPosition.setOrientationDeg(tVal1, tVal2, tVal3); pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_SPEED"); if (pSetting == NULL) { pSetting = config_setting_add(m_pSettings, "LAST_POSITION_SPEED", CONFIG_TYPE_FLOAT); tVal1 = 0.; if (pSetting != NULL) { config_setting_set_float(pSetting, tVal1); basicSettingsProvider::getInstance()->compromise(); }; } else { tVal1 = config_setting_get_float(pSetting); }; m_oPosition.setSpeed(tVal1); basicSettingsProvider::getInstance()->validate(); } else { // Set Default settings
m_oPosition.setPositionWGS84(0.f, 0.f); m_oPosition.setOrientationDeg(0.f, 0.f, 0.f); m_oPosition.setSpeed(0.f); };};
objectFlyHunter::~objectFlyHunter() { basicThread::waitThreadEnd(true);};
bool objectFlyHunter::cerate() { bool rV = false; m_mAccessProtector.lock(); if( m_pProtocol->create() ) rV = basicThread::init(); m_mAccessProtector.unlock(); return rV;};
bool objectFlyHunter::flyToWGS84(float lat, float lon, float alt) { return true;};
bool objectFlyHunter::isVehicleAttached() { bool rV = false; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { rV = m_pProtocol->m_bUAV_Online; }; m_mAccessProtector.unlock(); return rV;};bool objectFlyHunter::isPairingDone() { bool rV = false; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { rV = m_pProtocol->m_bPairingFinished; }; m_mAccessProtector.unlock(); return rV;};bool objectFlyHunter::connectVia(CSTR a) { bool rV = false; m_mAccessProtector.lock(); if (m_pProtocol->setUartDevice(a)) { delete(m_pProtocol); m_pProtocol = new protocolMAVLINK(m_pSettings); if (m_pProtocol != NULL) { rV = m_pProtocol->create(); }; }; m_mAccessProtector.unlock(); return rV;};
bool objectFlyHunter::isRadiosConnected(void) { return (m_eCurrentMode > FH_NO_CONNECTION);};
/**
* @param value battery voltage */double objectFlyHunter::filterVoltage(double value) const { return m_dLpfVoltage * 0.6f + value * 0.4f;};
void objectFlyHunter::m_fThreadProc(void) { FH_COMMAND * pCMD = NULL;
m_bThreadStatus = TH_WORKING; while (m_bThreadStatus < TH_ENDED) { if (m_qQueuedCommands.size()) { pCMD = m_qQueuedCommands.front(); } else pCMD = NULL; if (m_pProtocol->getConnectionStatus() == CS_DISCONNECTED) { m_eCurrentMode = FH_CONNECTION_ERROR; }; switch (m_eCurrentMode) { case FH_CONNECTION_ERROR: break; case FH_NO_CONNECTION: if (m_pProtocol->getConnectionStatus() == CS_CONNECTED) m_eCurrentMode = FH_WAIT_FOR_UAV; break; case FH_WAIT_FOR_UAV: if (m_pProtocol->m_bPairingFinished) m_eCurrentMode = FH_MODE_PREFLIGHT; break; case FH_MODE_PREFLIGHT: if (pCMD != NULL) { switch (pCMD->type) { case FH_CMD_SET_BASE_MODE: if (pCMD->data != NULL) { uint8_t tMode; tMode = m_bUAV_bMODE | *((uint8_t*)pCMD->data); m_pProtocol->broadcastSetBaseMode(tMode); }; break; case FH_CMD_SET_AP_MODE: if (pCMD->data != NULL) { uint32_t tMode; tMode = m_bUAV_bMODE | *((uint32_t*)pCMD->data); m_pProtocol->broadcastSetCustomMode(tMode); }; break; case FH_CMD_FORCE_ARM: { m_pProtocol->broadcastArm(true,true); m_eCurrentMode = FH_MODE_ARMING; break; }; case FH_CMD_ARM: { m_pProtocol->broadcastArm(true); m_eCurrentMode = FH_MODE_ARMING; break; }; case FH_CMD_DISARM: { //?? Why at preflight mode!!
m_pProtocol->broadcastArm(false); m_eCurrentMode = FH_MODE_DISARMING; break; }; }; }; break; case FH_MODE_ARMING: if (m_pProtocol->getLastCmdStatus() > -1) { if (m_pProtocol->getLastCmdStatus() == MAV_RESULT_ACCEPTED) { m_eCurrentMode = FH_MODE_ARMED; } else { m_eCurrentMode = FH_MODE_PREFLIGHT; }; }; break; case FH_MODE_ARMED: if (pCMD != NULL) { switch (pCMD->type) { case FH_CMD_SET_BASE_MODE: if (pCMD->data != NULL) { uint8_t tMode; tMode = m_bUAV_bMODE | *((uint8_t*)pCMD->data); m_pProtocol->setMode(tMode); }; break; case FH_CMD_SET_AP_MODE: if (pCMD->data != NULL) { uint32_t tMode; tMode = m_bUAV_bMODE | *((uint32_t*)pCMD->data); m_pProtocol->broadcastSetCustomMode(tMode); }; break; case FH_CMD_ARM: { //?? Why at ARMED mode!!
m_pProtocol->broadcastArm(true); m_eCurrentMode = FH_MODE_ARMING; break; }; case FH_CMD_DISARM: { m_pProtocol->broadcastArm(false); m_eCurrentMode = FH_MODE_DISARMING; break; }; }; }; break; case FH_MODE_DISARMING: break; }; if (m_eCurrentMode > FH_WAIT_FOR_UAV) { // Update statuses
m_bUAV_type = m_pProtocol->m_sHeartBit.type; m_bUAV_ctrl = m_pProtocol->m_sHeartBit.autopilot; m_bUAV_bMODE = m_pProtocol->m_sHeartBit.base_mode; m_nUAV_cMODE = m_pProtocol->m_sHeartBit.custom_mode; // if Position Accurate
float roll = 0.f, pitch = 0.f, yaw = 0.f; roll = m_pProtocol->m_sAttitude.roll; pitch = m_pProtocol->m_sAttitude.pitch; yaw = m_pProtocol->m_sAttitude.yaw; m_oPosition.setOrientationRad(roll, pitch, yaw); if (updateOrientation != NULL) updateOrientation(m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg()); }; if (pCMD != NULL) { if (pCMD->data != NULL)free(pCMD->data); m_qQueuedCommands.pop(); }; //Update Data FROM UAV
if ( m_pProtocol->m_bSystemStatusDataActual ) { m_pProtocol->m_bSystemStatusDataActual = false; // Prepare for sending data to the realtime plotter, which is every field excluding onboard_control_sensors_present.
//quint64 time = getUnixTime();
//emit valueChanged(uasId, statusName().arg("Sensors Enabled"), "bits", state.onboard_control_sensors_enabled, time);
//emit valueChanged(uasId, statusName().arg("Sensors Health"), "bits", state.onboard_control_sensors_health, time);
//emit valueChanged(uasId, statusName().arg("Comms Errors"), "-", state.errors_comm, time);
//emit valueChanged(uasId, statusName().arg("Errors Count 1"), "-", state.errors_count1, time);
//emit valueChanged(uasId, statusName().arg("Errors Count 2"), "-", state.errors_count2, time);
//emit valueChanged(uasId, statusName().arg("Errors Count 3"), "-", state.errors_count3, time);
//emit valueChanged(uasId, statusName().arg("Errors Count 4"), "-", state.errors_count4, time);
// Process CPU load.
//emit loadChanged(this, m_sSystemStatus.load / 10.0);
//emit valueChanged(uasId, statusName().arg("CPU Load"), "%", m_sSystemStatus.load / 10.0, time);
// Battery charge/time remaining/voltage calculations
double currentVoltage = m_pProtocol->m_sSystemStatus.voltage_battery / 1000.0; double lpVoltage = filterVoltage(currentVoltage);// tickLowpassVoltage = tickLowpassVoltage * 0.8 + 0.2 * currentVoltage;
// We don't want to tick above the threshold
// if (tickLowpassVoltage > tickVoltage) {
// lastTickVoltageValue = tickLowpassVoltage;
// };
// if ((startVoltage > 0.0) && (tickLowpassVoltage < tickVoltage) && (fabs(lastTickVoltageValue - tickLowpassVoltage) > 0.1)
/* warn if lower than treshold */// && (lpVoltage < tickVoltage)
/* warn only if we have at least the voltage of an empty LiPo cell, else we're sampling something wrong */// && (currentVoltage > 3.3)
/* warn only if current voltage is really still lower by a reasonable amount */// && ((currentVoltage - 0.2) < tickVoltage)
/* warn only every 12 seconds */// && (QGC::groundTimeUsecs() - lastVoltageWarning) > 12000000)
// {
//GAudioOutput::instance()->say(QString("voltage warning: %1 volts").arg(lpVoltage, 0, 'f', 1, QChar(' ')));
// lastVoltageWarning = QGC::groundTimeUsecs();
// lastTickVoltageValue = tickLowpassVoltage;
// }
// if (startVoltage == -1.0 && currentVoltage > 0.1) startVoltage = currentVoltage;
// timeRemaining = calculateTimeRemaining();
// if (!batteryRemainingEstimateEnabled && chargeLevel != -1)
// {
// chargeLevel = m_pProtocol->m_sSystemStatus.battery_remaining;
// }
//emit batteryChanged(this, lpVoltage, currentCurrent, getChargeLevel(), timeRemaining);
// emit voltageChanged(message.sysid, currentVoltage);
//emit valueChanged(uasId, statusName().arg("Battery"), "%", m_sSystemStatus.battery_remaining, time);
//emit valueChanged(uasId, statusName().arg("Voltage"), "V", m_sSystemStatus.voltage_battery / 1000.0, time);
// And if the battery current draw is measured, log that also.
// if (m_sSystemStatus.current_battery != -1)
// {
// currentCurrent = ((double)m_sSystemStatus.current_battery) / 100.0;
//emit valueChanged(uasId, statusName().arg("Current"), "A", currentCurrent, time);
// }
// LOW BATTERY ALARM
// if (lpVoltage < warnVoltage && (currentVoltage - 0.2) < warnVoltage && (currentVoltage > 3.3))
// {
// An audio alarm. Does not generate any signals.
// startLowBattAlarm();
// }
// else
// {
// stopLowBattAlarm();
// }
// control_sensors_enabled:
// relevant bits: 11: attitude stabilization, 12: yaw position, 13: z/altitude control, 14: x/y position control
//emit attitudeControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 11));
//emit positionYawControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 12));
//emit positionZControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 13));
//emit positionXYControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 14));
// Trigger drop rate updates as needed. Here we convert the incoming
// drop_rate_comm value from 1/100 of a percent in a uint16 to a true
// percentage as a float. We also cap the incoming value at 100% as defined
// by the MAVLink specifications.
// if (m_sSystemStatus.drop_rate_comm > 10000) {
// m_sSystemStatus.drop_rate_comm = 10000;
// };
//emit dropRateChanged(this->getUASID(), m_sSystemStatus.drop_rate_comm / 100.0);
//emit valueChanged(uasId, statusName().arg("Comms Drop Rate"), "%", m_sSystemStatus.drop_rate_comm / 100.0, time);
} SLEEP(20); };};
CSTR objectFlyHunter::getVehicleName() { if ( m_eCurrentMode > FH_WAIT_FOR_UAV ) { switch (m_bUAV_type) { case MAV_TYPE_GENERIC: return (CSTR)"Generic micro air vehicle"; case MAV_TYPE_FIXED_WING: return (CSTR)"Fixed wing aircraft."; case MAV_TYPE_QUADROTOR: return (CSTR)"Quadrotor"; case MAV_TYPE_COAXIAL: return (CSTR)"Coaxial helicopter"; case MAV_TYPE_HELICOPTER: return (CSTR)"Normal helicopter with tail rotor."; case MAV_TYPE_ANTENNA_TRACKER: return (CSTR)"Ground installation"; case MAV_TYPE_GCS: return (CSTR)"Operator control unit / ground control station"; case MAV_TYPE_AIRSHIP: return (CSTR)"Airship, controlled"; case MAV_TYPE_FREE_BALLOON: return (CSTR)"Free balloon, uncontrolled"; case MAV_TYPE_ROCKET: return (CSTR)"Rocket"; case MAV_TYPE_GROUND_ROVER: return (CSTR)"Ground rover"; case MAV_TYPE_SURFACE_BOAT: return (CSTR)"Surface vessel, boat, ship"; case MAV_TYPE_SUBMARINE: return (CSTR)"Submarine"; case MAV_TYPE_HEXAROTOR: return (CSTR)"Hexarotor"; case MAV_TYPE_OCTOROTOR: return (CSTR)"Octorotor"; case MAV_TYPE_TRICOPTER: return (CSTR)"Tricopter"; case MAV_TYPE_FLAPPING_WING: return (CSTR)"Flapping wing"; case MAV_TYPE_KITE: return (CSTR)"Kite"; case MAV_TYPE_ONBOARD_CONTROLLER: return (CSTR)"Onboard companion controller"; case MAV_TYPE_VTOL_DUOROTOR: return (CSTR)"Two-rotor VTOL using control surfaces in vertical operation in addition. Tailsitter."; case MAV_TYPE_VTOL_QUADROTOR: return (CSTR)"Quad-rotor VTOL using a V-shaped quad config in vertical operation. Tailsitter."; case MAV_TYPE_VTOL_TILTROTOR: return (CSTR)"Tiltrotor VTOL"; case MAV_TYPE_VTOL_RESERVED2: return (CSTR)"VTOL reserved 2"; case MAV_TYPE_VTOL_RESERVED3: return (CSTR)"VTOL reserved 3"; case MAV_TYPE_VTOL_RESERVED4: return (CSTR)"VTOL reserved 4"; case MAV_TYPE_VTOL_RESERVED5: return (CSTR)"VTOL reserved 5"; case MAV_TYPE_GIMBAL: return (CSTR)"Gimbal"; case MAV_TYPE_ADSB: return (CSTR)"ADSB system"; case MAV_TYPE_PARAFOIL: return (CSTR)"Steerable, nonrigid airfoil"; case MAV_TYPE_DODECAROTOR: return (CSTR)"Dodecarotor"; case MAV_TYPE_CAMERA: return (CSTR)"Camera"; case MAV_TYPE_CHARGING_STATION: return (CSTR)"Charging station"; case MAV_TYPE_FLARM: return (CSTR)"FLARM collision avoidance system"; case MAV_TYPE_SERVO: return (CSTR)"Servo"; }; return (CSTR)"Unknown Type"; }; return (CSTR)"Not Connected";};
CSTR objectFlyHunter::getCtrlName() { if (m_eCurrentMode > FH_WAIT_FOR_UAV) { switch (m_bUAV_ctrl) { case MAV_AUTOPILOT_GENERIC: return (CSTR)"Generic autopilot, full support for everything"; case MAV_AUTOPILOT_RESERVED: return (CSTR)"Reserved for future use."; case MAV_AUTOPILOT_SLUGS: return (CSTR)"SLUGS autopilot"; case MAV_AUTOPILOT_ARDUPILOTMEGA: return (CSTR)"ArduPilot - Plane/Copter/Rover/Sub/Tracker"; case MAV_AUTOPILOT_OPENPILOT: return (CSTR)"OpenPilot"; case MAV_AUTOPILOT_GENERIC_WAYPOINTS_ONLY: return (CSTR)"Generic autopilot only supporting simple waypoints"; case MAV_AUTOPILOT_GENERIC_WAYPOINTS_AND_SIMPLE_NAVIGATION_ONLY: return (CSTR)"Generic autopilot supporting waypoints and other simple navigation commands"; case MAV_AUTOPILOT_GENERIC_MISSION_FULL: return (CSTR)"Generic autopilot supporting the full mission command set"; case MAV_AUTOPILOT_INVALID: return (CSTR)"No valid autopilot, e.g. a GCS or other MAVLink component"; case MAV_AUTOPILOT_PPZ: return (CSTR)"PPZ UAV"; case MAV_AUTOPILOT_UDB: return (CSTR)"UAV Dev Board"; case MAV_AUTOPILOT_FP: return (CSTR)"FlexiPilot"; case MAV_AUTOPILOT_PX4: return (CSTR)"PX4 Autopilot"; case MAV_AUTOPILOT_SMACCMPILOT: return (CSTR)"SMACCMPilot"; case MAV_AUTOPILOT_AUTOQUAD: return (CSTR)"AutoQuad"; case MAV_AUTOPILOT_ARMAZILA: return (CSTR)"Armazila"; case MAV_AUTOPILOT_AEROB: return (CSTR)"Aerob"; case MAV_AUTOPILOT_ASLUAV: return (CSTR)"ASLUAV autopilot"; case MAV_AUTOPILOT_SMARTAP: return (CSTR)"SmartAP Autopilot"; case MAV_AUTOPILOT_AIRRAILS: return (CSTR)"AirRails"; }; return (CSTR)"Unknown Control Module"; }; return (CSTR)"Not Connected";};
bool objectFlyHunter::arm() { FH_COMMAND * tPtr; tPtr = (FH_COMMAND*)malloc(sizeof(FH_COMMAND)); if (tPtr != NULL) { tPtr->data = NULL; tPtr->type = FH_CMD_ARM; m_qQueuedCommands.push(tPtr); return true; }; return false;};bool objectFlyHunter::forceArm() { FH_COMMAND* tPtr; tPtr = (FH_COMMAND*)malloc(sizeof(FH_COMMAND)); if (tPtr != NULL) { tPtr->data = NULL; tPtr->type = FH_CMD_FORCE_ARM; m_qQueuedCommands.push(tPtr); return true; }; return false;};bool objectFlyHunter::disarm() { FH_COMMAND* tPtr; tPtr = (FH_COMMAND*)malloc(sizeof(FH_COMMAND)); if (tPtr != NULL) { tPtr->data = NULL; tPtr->type = FH_CMD_DISARM; m_qQueuedCommands.push(tPtr); return true; }; return false;};
bool objectFlyHunter::reset() { FH_COMMAND* tPtr; tPtr = (FH_COMMAND*)malloc(sizeof(FH_COMMAND)); if (tPtr != NULL) { tPtr->data = NULL; tPtr->type = FH_CMD_RESET; m_qQueuedCommands.push(tPtr); return true; }; return false;};
bool objectFlyHunter::takeOff() { FH_COMMAND* tPtr; tPtr = (FH_COMMAND*)malloc(sizeof(FH_COMMAND)); if (tPtr != NULL) { tPtr->data = NULL; tPtr->type = FH_CMD_TAKEOFF; m_qQueuedCommands.push(tPtr); return true; }; return false;};
bool objectFlyHunter::land() { FH_COMMAND* tPtr; tPtr = (FH_COMMAND*)malloc(sizeof(FH_COMMAND)); if (tPtr != NULL) { tPtr->data = NULL; tPtr->type = FH_CMD_LAND; m_qQueuedCommands.push(tPtr); return true; }; return false;};
uint8_t objectFlyHunter::getVehicleSystemMode() { return m_bUAV_bMODE;};
uint32_t objectFlyHunter::getVehicleAutoPilotMode() { return m_nUAV_cMODE;};
CSTR objectFlyHunter::getVehicleSystemModeName() { if (m_eCurrentMode > FH_WAIT_FOR_UAV) { char tBuffer[256]; sprintf(tBuffer, "%s%s%s%s%s%s%s%s", ((m_bUAV_bMODE & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) ? "CUS_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_MANUAL_INPUT_ENABLED) ? "MAN_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_HIL_ENABLED) ? "HIL_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_STABILIZE_ENABLED) ? "STB_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_GUIDED_ENABLED) ? "GID_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_AUTO_ENABLED) ? "AUT_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_TEST_ENABLED) ? "TST_" : ""), ((m_bUAV_bMODE & MAV_MODE_FLAG_SAFETY_ARMED) ? "ARM" : "") ); return _strdup(tBuffer); }; return NULL;};
CSTR objectFlyHunter::getVehicleAutoPilotModeName( int32_t c_mode ) { if (m_eCurrentMode > FH_WAIT_FOR_UAV) { switch (m_nUAV_cMODE) { case STABILIZE: return (CSTR)"STABILIZE: hold level position"; case ACRO: return (CSTR)"ACRO: hold rate control"; case ALT_HOLD: return (CSTR)"ALT_HOLD: hold altitude"; case AUTO: return (CSTR)"AUTO: RC"; case GUIDED: return (CSTR)"GUIDED: auto"; case LOITER: return (CSTR)"LOITER: hold a single location"; case RTL: return (CSTR)"RTL: auto"; case CIRCLE: return (CSTR)"CIRCLE: auto"; //case POSITION: return (CSTR)"POSITION: deprecated";
case LAND: return (CSTR)"LAND: auto"; //case OF_LOITER: return (CSTR)"OF_LOITER: deprecated";
case DRIFT: return (CSTR)"DRIFT: drift 'Car Like' mode"; //case RESERVED_12: return (CSTR)"RESERVED_12: FU";
case SPORT: return (CSTR)"SPORT: auto"; case FLIP: return (CSTR)"FLIP: auto"; case AUTOTUNE: return (CSTR)"AUTOTUNE: auto"; //case POS_HOLD: return (CSTR)"POS_HOLD: HYBRID LOITER";
case BRAKE: return (CSTR)"BRAKE: auto"; case THROW: return (CSTR)"THROW: auto"; case AVOID_ADSB: return (CSTR)"AVOID_ADSB: auto"; case GUIDED_NOGPS: return (CSTR)"GUIDED_NOGPS: auto"; case SMART_RTL: return (CSTR)"SMART_RTL: returns to home by retracing its steps"; case FLOWHOLD: return (CSTR)"FLOWHOLD: holds position with optical flow without rangefinder"; case FOLLOW: return (CSTR)"FOLLOW: attempts to follow another vehicle or ground station"; case ZIGZAG: return (CSTR)"ZIGZAG: auto"; }; }; return NULL;};
bool objectFlyHunter::isGpsPresent() { bool rV = false; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { if(m_pProtocol->m_bUAV_Online) rV = m_pProtocol->m_bGpsStatusDataActual || m_pProtocol->m_bGpsRawIntDataActual; }; m_mAccessProtector.unlock(); return rV;};bool objectFlyHunter::isPositionAccurate() { bool rV = false; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual) { rV = m_pProtocol->m_sGpsRaw.fix_type > GPS_FIX_TYPE_NO_FIX; }; }; m_mAccessProtector.unlock(); return rV;};bool objectFlyHunter::isPositionIs3D() { bool rV = false; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual) { rV = m_pProtocol->m_sGpsRaw.fix_type > GPS_FIX_TYPE_2D_FIX; }; }; m_mAccessProtector.unlock(); return rV;};mavlink_vfr_hud_t *objectFlyHunter::getVFRData() { mavlink_vfr_hud_t *rV = NULL; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual) { rV = &m_pProtocol->m_sVFR_Hud; }; }; m_mAccessProtector.unlock(); return rV;};mavlink_power_status_t* objectFlyHunter::getPowerStatusData() { mavlink_power_status_t* rV = NULL; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual) { rV = &m_pProtocol->m_sPowerStatus; }; }; m_mAccessProtector.unlock(); return rV;};float objectFlyHunter::getBodyRoll() { float rV = 0.f; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { //rV = m_pProtocol->m_sRawIMU.xgyro;
rV = m_pProtocol->m_sScaledIMU.xgyro / 1000.f; }; m_mAccessProtector.unlock(); return rV;};
float objectFlyHunter::getBodyPitch() { float rV = 0.f; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { //rV = m_pProtocol->m_sRawIMU.ygyro;
rV = m_pProtocol->m_sScaledIMU.ygyro / 1000.f; }; m_mAccessProtector.unlock(); return rV;};
float objectFlyHunter::getBodyYaw() { float rV = 0.f; m_mAccessProtector.lock(); if (m_pProtocol != NULL) { //rV = m_pProtocol->m_sRawIMU.zgyro;
rV = m_pProtocol->m_sScaledIMU.zgyro / 1000.f; }; m_mAccessProtector.unlock(); return rV;};
void objectFlyHunter::setJoystickRoll(int16_t value) {};
void objectFlyHunter::setJoystickPitch(int16_t value) {};
void objectFlyHunter::setJoystickYaw(int16_t value) {};
void objectFlyHunter::setJoistickThrottle(int16_t value) {};
#undef LOG
#undef LOG_ERROR
|