Commit 7dba86d0 authored by LM's avatar LM

Working on HIL

parent 05143aa7
...@@ -262,11 +262,17 @@ bool QGCFlightGearLink::disconnectSimulation() ...@@ -262,11 +262,17 @@ bool QGCFlightGearLink::disconnectSimulation()
disconnect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t))); disconnect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t)));
disconnect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t))); disconnect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)));
process->close(); if (process)
delete process; {
process = NULL; process->close();
delete socket; delete process;
socket = NULL; process = NULL;
}
if (socket)
{
delete socket;
socket = NULL;
}
connectState = false; connectState = false;
...@@ -288,15 +294,15 @@ bool QGCFlightGearLink::connectSimulation() ...@@ -288,15 +294,15 @@ bool QGCFlightGearLink::connectSimulation()
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
process = new QProcess(this); // process = new QProcess(this);
connect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t))); // connect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t)));
connect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t))); // connect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)));
//connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(sendUAVUpdate())); // //connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(sendUAVUpdate()));
// Catch process error // // Catch process error
QObject::connect( process, SIGNAL(error(QProcess::ProcessError)), // QObject::connect( process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(processError(QProcess::ProcessError))); // this, SLOT(processError(QProcess::ProcessError)));
// Start Flightgear // Start Flightgear
QStringList processCall; QStringList processCall;
QString processFgfs; QString processFgfs;
...@@ -352,16 +358,18 @@ bool QGCFlightGearLink::connectSimulation() ...@@ -352,16 +358,18 @@ bool QGCFlightGearLink::connectSimulation()
// Add new argument with this: processCall << ""; // Add new argument with this: processCall << "";
processCall << QString("--aircraft=%2").arg(aircraft); processCall << QString("--aircraft=%2").arg(aircraft);
process->start(processFgfs, processCall); // process->start(processFgfs, processCall);
qDebug() << "STARTING: " << processFgfs << processCall;
emit flightGearConnected(connectState);
if (connectState) { // emit flightGearConnected(connectState);
emit flightGearConnected(); // if (connectState) {
connectionStartTime = QGC::groundTimeUsecs()/1000; // emit flightGearConnected();
} // connectionStartTime = QGC::groundTimeUsecs()/1000;
qDebug() << "STARTING SIM"; // }
// qDebug() << "STARTING SIM";
qDebug() << "STARTING: " << processFgfs << processCall;
start(LowPriority); start(LowPriority);
return connectState; return connectState;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#define WITH_TEXT_TO_SPEECH 1 #define WITH_TEXT_TO_SPEECH 1
#define QGC_APPLICATION_NAME "QGroundControl" #define QGC_APPLICATION_NAME "QGroundControl"
#define QGC_APPLICATION_VERSION "v. 1.0.0 (Alpha RC17)" #define QGC_APPLICATION_VERSION "v. 1.0.0 (Alpha RC18)"
namespace QGC namespace QGC
......
...@@ -337,10 +337,14 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) ...@@ -337,10 +337,14 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
mavlink_msg_sys_status_decode(&message, &state); mavlink_msg_sys_status_decode(&message, &state);
emit loadChanged(this,state.load/10.0f); emit loadChanged(this,state.load/10.0f);
// FIXME REMOVE LATER emit valueChanged(uasId, "Load", "%", ((float)state.load)/10.0f, getUnixTime());
currentVoltage = state.voltage_battery/1000.0f; currentVoltage = state.voltage_battery/1000.0f;
lpVoltage = filterVoltage(currentVoltage); lpVoltage = filterVoltage(currentVoltage);
qDebug() << "BATT VOLTAGE:" << currentVoltage << "RAW" << state.voltage_battery;
if (startVoltage == 0) startVoltage = currentVoltage; if (startVoltage == 0) startVoltage = currentVoltage;
timeRemaining = calculateTimeRemaining(); timeRemaining = calculateTimeRemaining();
if (!batteryRemainingEstimateEnabled && chargeLevel != -1) if (!batteryRemainingEstimateEnabled && chargeLevel != -1)
...@@ -1194,18 +1198,11 @@ QList<int> UAS::getComponentIds() ...@@ -1194,18 +1198,11 @@ QList<int> UAS::getComponentIds()
void UAS::setMode(int mode) void UAS::setMode(int mode)
{ {
if (mode >= (int)MAV_MODE_PREFLIGHT && mode < (int)MAV_MODE_ENUM_END) //this->mode = mode; //no call assignament, update receive message from UAS
{ mavlink_message_t msg;
//this->mode = mode; //no call assignament, update receive message from UAS mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, (uint8_t)uasId, (uint8_t)mode, (uint16_t)navMode);
mavlink_message_t msg; sendMessage(msg);
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, (uint8_t)uasId, (uint8_t)mode, (uint16_t)navMode); qDebug() << "SENDING REQUEST TO SET MODE TO SYSTEM" << uasId << ", REQUEST TO SET MODE " << (uint8_t)mode;
sendMessage(msg);
qDebug() << "SENDING REQUEST TO SET MODE TO SYSTEM" << uasId << ", REQUEST TO SET MODE " << (uint8_t)mode;
}
else
{
qDebug() << "uas Mode not assign: " << mode;
}
} }
void UAS::sendMessage(mavlink_message_t message) void UAS::sendMessage(mavlink_message_t message)
...@@ -1923,7 +1920,8 @@ void UAS::setManualControlCommands(double roll, double pitch, double yaw, double ...@@ -1923,7 +1920,8 @@ void UAS::setManualControlCommands(double roll, double pitch, double yaw, double
manualYawAngle = yaw * yawScaling; manualYawAngle = yaw * yawScaling;
manualThrust = thrust * thrustScaling; manualThrust = thrust * thrustScaling;
if(mode == (int)MAV_MODE_MANUAL_ARMED) // If system has manual inputs enabled and is armed
if((mode & MAV_MODE_FLAG_DECODE_POSITION_MANUAL) && (mode & MAV_MODE_FLAG_DECODE_POSITION_SAFETY))
{ {
mavlink_message_t message; mavlink_message_t message;
mavlink_msg_manual_control_pack(mavlink->getSystemId(), mavlink->getComponentId(), &message, this->uasId, (float)manualRollAngle, (float)manualPitchAngle, (float)manualYawAngle, (float)manualThrust, controlRollManual, controlPitchManual, controlYawManual, controlThrustManual); mavlink_msg_manual_control_pack(mavlink->getSystemId(), mavlink->getComponentId(), &message, this->uasId, (float)manualRollAngle, (float)manualPitchAngle, (float)manualYawAngle, (float)manualThrust, controlRollManual, controlPitchManual, controlYawManual, controlThrustManual);
...@@ -2083,7 +2081,7 @@ void UAS::startHil() ...@@ -2083,7 +2081,7 @@ void UAS::startHil()
// Connect Flight Gear Link // Connect Flight Gear Link
simulation->connectSimulation(); simulation->connectSimulation();
mavlink_message_t msg; mavlink_message_t msg;
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode, navMode | MAV_MODE_FLAG_HIL_ENABLED); mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode | MAV_MODE_FLAG_HIL_ENABLED, navMode);
sendMessage(msg); sendMessage(msg);
} }
...@@ -2091,7 +2089,7 @@ void UAS::stopHil() ...@@ -2091,7 +2089,7 @@ void UAS::stopHil()
{ {
simulation->disconnectSimulation(); simulation->disconnectSimulation();
mavlink_message_t msg; mavlink_message_t msg;
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode, navMode & !MAV_MODE_FLAG_HIL_ENABLED); mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode & !MAV_MODE_FLAG_HIL_ENABLED, navMode);
sendMessage(msg); sendMessage(msg);
} }
...@@ -2153,44 +2151,50 @@ const QString& UAS::getShortState() const ...@@ -2153,44 +2151,50 @@ const QString& UAS::getShortState() const
QString UAS::getShortModeTextFor(int id) QString UAS::getShortModeTextFor(int id)
{ {
QString mode; QString mode;
uint8_t modeid = id;
qDebug() << "MODE:" << modeid;
switch (id) { // BASE MODE DECODING
case (uint8_t)MAV_MODE_PREFLIGHT: if (modeid & MAV_MODE_FLAG_DECODE_POSITION_AUTO)
{
mode = "AUTO";
}
else if (modeid & MAV_MODE_FLAG_DECODE_POSITION_GUIDED)
{
mode = "GUIDED";
}
else if (modeid & MAV_MODE_FLAG_DECODE_POSITION_STABILIZE)
{
mode = "STABILIZED";
}
else if (modeid & MAV_MODE_FLAG_DECODE_POSITION_TEST)
{
mode = "TEST";
}
else if (modeid & MAV_MODE_FLAG_DECODE_POSITION_MANUAL)
{
mode = "MANUAL";
}
else
{
mode = "PREFLIGHT"; mode = "PREFLIGHT";
break; }
case (uint8_t)MAV_MODE_MANUAL_ARMED:
mode = "A|MANUAL"; // ARMED STATE DECODING
break; if (modeid & MAV_MODE_FLAG_DECODE_POSITION_SAFETY)
case (uint8_t)MAV_MODE_MANUAL_DISARMED: {
mode = "D|MANUAL"; mode.prepend("A|");
break; }
case (uint8_t)MAV_MODE_AUTO_ARMED: else
mode = "A|AUTO"; {
break; mode.prepend("D|");
case (uint8_t)MAV_MODE_AUTO_DISARMED: }
mode = "D|AUTO";
break; // HARDWARE IN THE LOOP DECODING
case (uint8_t)MAV_MODE_GUIDED_ARMED: if (modeid & MAV_MODE_FLAG_DECODE_POSITION_HIL)
mode = "A|GUIDED"; {
break; mode.prepend("HIL:");
case (uint8_t)MAV_MODE_GUIDED_DISARMED:
mode = "D|GUIDED";
break;
case (uint8_t)MAV_MODE_STABILIZE_ARMED:
mode = "A|STABILIZED";
break;
case (uint8_t)MAV_MODE_STABILIZE_DISARMED:
mode = "D|STABILIZED";
break;
case (uint8_t)MAV_MODE_TEST_ARMED:
mode = "A|TEST";
break;
case (uint8_t)MAV_MODE_TEST_DISARMED:
mode = "D|TEST";
break;
default:
mode = "UNKNOWN";
break;
} }
return mode; return mode;
......
...@@ -165,7 +165,7 @@ protected: //COMMENTS FOR TEST UNIT ...@@ -165,7 +165,7 @@ protected: //COMMENTS FOR TEST UNIT
bool batteryRemainingEstimateEnabled; ///< If the estimate is enabled, QGC will try to estimate the remaining battery life bool batteryRemainingEstimateEnabled; ///< If the estimate is enabled, QGC will try to estimate the remaining battery life
float chargeLevel; ///< Charge level of battery, in percent float chargeLevel; ///< Charge level of battery, in percent
int timeRemaining; ///< Remaining time calculated based on previous and current int timeRemaining; ///< Remaining time calculated based on previous and current
int mode; ///< The current mode of the MAV uint8_t mode; ///< The current mode of the MAV
int status; ///< The current status of the MAV int status; ///< The current status of the MAV
uint32_t navMode; ///< The current navigation mode of the MAV uint32_t navMode; ///< The current navigation mode of the MAV
quint64 onboardTimeOffset; quint64 onboardTimeOffset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment