@ -36,11 +36,12 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo
@@ -36,11 +36,12 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo
QObject ( parent ) ,
_statusLog ( NULL ) ,
_progressBar ( NULL ) ,
_showGyroCalArea ( false ) ,
_compassButton ( NULL ) ,
_gyroButton ( NULL ) ,
_accelButton ( NULL ) ,
_airspeedButton ( NULL ) ,
_cancelButton ( NULL ) ,
_showOrientationCalArea ( false ) ,
_showCompass0 ( false ) ,
_showCompass1 ( false ) ,
_showCompass2 ( false ) ,
_gyroCalInProgress ( false ) ,
_magCalInProgress ( false ) ,
_accelCalInProgress ( false ) ,
@ -50,18 +51,31 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo
@@ -50,18 +51,31 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo
_orientationCalRightSideDone ( false ) ,
_orientationCalNoseDownSideDone ( false ) ,
_orientationCalTailDownSideDone ( false ) ,
_orientationCalDownSideVisible ( false ) ,
_orientationCalUpsideDownSideVisible ( false ) ,
_orientationCalLeftSideVisible ( false ) ,
_orientationCalRightSideVisible ( false ) ,
_orientationCalNoseDownSideVisible ( false ) ,
_orientationCalTailDownSideVisible ( false ) ,
_orientationCalDownSideInProgress ( false ) ,
_orientationCalUpsideDownSideInProgress ( false ) ,
_orientationCalLeftSideInProgress ( false ) ,
_orientationCalRightSideInProgress ( false ) ,
_orientationCalNoseDownSideInProgress ( false ) ,
_orientationCalTailDownSideInProgress ( false ) ,
_textLoggingStarted ( false ) ,
_orientationCalDownSideRotate ( false ) ,
_orientationCalLeftSideRotate ( false ) ,
_orientationCalNoseDownSideRotate ( false ) ,
_unknownFirmwareVersion ( false ) ,
_waitingForCancel ( false ) ,
_autopilot ( autopilot )
{
Q_ASSERT ( _autopilot ) ;
Q_ASSERT ( _autopilot - > pluginReady ( ) ) ;
_uas = _autopilot - > uas ( ) ;
Q_ASSERT ( _uas ) ;
// Mag rotation parameters are optional
_showCompass0 = _autopilot - > parameterExists ( " CAL_MAG0_ROT " ) & &
_autopilot - > getParameterFact ( " CAL_MAG0_ROT " ) - > value ( ) . toInt ( ) > = 0 ;
@ -84,89 +98,115 @@ void SensorsComponentController::_appendStatusLog(const QString& text)
@@ -84,89 +98,115 @@ void SensorsComponentController::_appendStatusLog(const QString& text)
Q_ARG ( QVariant , varText ) ) ;
}
void SensorsComponentController : : _startCalibration ( void )
void SensorsComponentController : : _startLog Calibration ( void )
{
_beginTextLogging ( ) ;
_unknownFirmwareVersion = false ;
_hideAllCalAreas ( ) ;
connect ( _uas , & UASInterface : : textMessageReceived , this , & SensorsComponentController : : _handleUASTextMessage ) ;
_cancelButton - > setEnabled ( false ) ;
}
void SensorsComponentController : : _startVisualCalibration ( void )
{
_compassButton - > setEnabled ( false ) ;
_gyroButton - > setEnabled ( false ) ;
_accelButton - > setEnabled ( false ) ;
_airspeedButton - > setEnabled ( false ) ;
_cancelButton - > setEnabled ( true ) ;
_progressBar - > setProperty ( " value " , 0 ) ;
}
void SensorsComponentController : : _stopCalibration ( bool failed )
void SensorsComponentController : : _stopCalibration ( SensorsComponentController : : StopCalibrationCode code )
{
_magCalInProgress = false ;
_accelCalInProgress = false ;
disconnect ( _uas , & UASInterface : : textMessageReceived , this , & SensorsComponentController : : _handleUASTextMessage ) ;
_compassButton - > setEnabled ( true ) ;
_gyroButton - > setEnabled ( true ) ;
_accelButton - > setEnabled ( true ) ;
_airspeedButton - > setEnabled ( true ) ;
_cancelButton - > setEnabled ( false ) ;
if ( code = = StopCalibrationSuccess ) {
_orientationCalDownSideDone = true ;
_orientationCalUpsideDownSideDone = true ;
_orientationCalLeftSideDone = true ;
_orientationCalRightSideDone = true ;
_orientationCalTailDownSideDone = true ;
_orientationCalNoseDownSideDone = true ;
_orientationCalDownSideInProgress = false ;
_orientationCalUpsideDownSideInProgress = false ;
_orientationCalLeftSideInProgress = false ;
_orientationCalRightSideInProgress = false ;
_orientationCalNoseDownSideInProgress = false ;
_orientationCalTailDownSideInProgress = false ;
emit orientationCalSidesDoneChanged ( ) ;
emit orientationCalSidesInProgressChanged ( ) ;
_progressBar - > setProperty ( " value " , 1 ) ;
} else {
_progressBar - > setProperty ( " value " , 0 ) ;
}
_progressBar - > setProperty ( " value " , failed ? 0 : 1 ) ;
_updateAndEmitGyroCalInProgress ( false ) ;
_waitingForCancel = false ;
emit waitingForCancelChanged ( ) ;
_refreshParams ( ) ;
if ( failed ) {
QGCMessageBox : : warning ( " Calibration " , " Calibration failed. Calibration log will be displayed. " ) ;
_hideAllCalAreas ( ) ;
switch ( code ) {
case StopCalibrationSuccess :
_orientationCalAreaHelpText - > setProperty ( " text " , " Calibration complete " ) ;
emit resetStatusTextArea ( ) ;
if ( _magCalInProgress ) {
emit setCompassRotations ( ) ;
}
break ;
case StopCalibrationCancelled :
emit resetStatusTextArea ( ) ;
_hideAllCalAreas ( ) ;
break ;
default :
// Assume failed
_hideAllCalAreas ( ) ;
QGCMessageBox : : warning ( " Calibration " , " Calibration failed. Calibration log will be displayed. " ) ;
break ;
}
_magCalInProgress = false ;
_accelCalInProgress = false ;
_gyroCalInProgress = false ;
}
void SensorsComponentController : : calibrateGyro ( void )
{
_startCalibration ( ) ;
UASInterface * uas = _autopilot - > uas ( ) ;
Q_ASSERT ( uas ) ;
uas - > executeCommand ( MAV_CMD_PREFLIGHT_CALIBRATION , 1 , 1.0f , 0.0f , 0.0f , 0.0f , 0.0f , 0.0f , 0.0f , 0 ) ;
_startLogCalibration ( ) ;
_uas - > startCalibration ( UASInterface : : StartCalibrationGyro ) ;
}
void SensorsComponentController : : calibrateCompass ( void )
{
_startCalibration ( ) ;
UASInterface * uas = _autopilot - > uas ( ) ;
Q_ASSERT ( uas ) ;
uas - > executeCommand ( MAV_CMD_PREFLIGHT_CALIBRATION , 1 , 0.0f , 1.0f , 0.0f , 0.0f , 0.0f , 0.0f , 0.0f , 0 ) ;
_startLogCalibration ( ) ;
_uas - > startCalibration ( UASInterface : : StartCalibrationMag ) ;
}
void SensorsComponentController : : calibrateAccel ( void )
{
_startCalibration ( ) ;
UASInterface * uas = _autopilot - > uas ( ) ;
Q_ASSERT ( uas ) ;
uas - > executeCommand ( MAV_CMD_PREFLIGHT_CALIBRATION , 1 , 0.0f , 0.0f , 0.0f , 0.0f , 1.0f , 0.0f , 0.0f , 0 ) ;
_startLogCalibration ( ) ;
_uas - > startCalibration ( UASInterface : : StartCalibrationAccel ) ;
}
void SensorsComponentController : : calibrateAirspeed ( void )
{
_startCalibration ( ) ;
UASInterface * uas = _autopilot - > uas ( ) ;
Q_ASSERT ( uas ) ;
uas - > executeCommand ( MAV_CMD_PREFLIGHT_CALIBRATION , 1 , 0.0f , 0.0f , 0.0f , 0.0f , 0.0f , 1.0f , 0.0f , 0 ) ;
}
void SensorsComponentController : : _beginTextLogging ( void )
{
if ( ! _textLoggingStarted ) {
_textLoggingStarted = true ;
UASInterface * uas = _autopilot - > uas ( ) ;
Q_ASSERT ( uas ) ;
connect ( uas , & UASInterface : : textMessageReceived , this , & SensorsComponentController : : _handleUASTextMessage ) ;
}
_startLogCalibration ( ) ;
_uas - > startCalibration ( UASInterface : : StartCalibrationAirspeed ) ;
}
void SensorsComponentController : : _handleUASTextMessage ( int uasId , int compId , int severity , QString text )
{
QString startingSidePrefix ( " Hold still, starting to measure " ) ;
QString sideDoneSuffix ( " side done, rotate to a different side " ) ;
QString orientationDetectedSuffix ( " orientation detected " ) ;
Q_UNUSED ( compId ) ;
Q_UNUSED ( severity ) ;
@ -176,14 +216,6 @@ void SensorsComponentController::_handleUASTextMessage(int uasId, int compId, in
@@ -176,14 +216,6 @@ void SensorsComponentController::_handleUASTextMessage(int uasId, int compId, in
return ;
}
QStringList ignorePrefixList ;
ignorePrefixList < < " [cmd] " < < " [mavlink pm] " < < " [ekf check] " < < " [pm] " < < " [inav] " < < " IN AIR MODE " < < " LANDED MODE " ;
foreach ( QString ignorePrefix , ignorePrefixList ) {
if ( text . startsWith ( ignorePrefix ) ) {
return ;
}
}
if ( text . contains ( " progress < " ) ) {
QString percent = text . split ( " < " ) . last ( ) . split ( " > " ) . first ( ) ;
bool ok ;
@ -196,138 +228,179 @@ void SensorsComponentController::_handleUASTextMessage(int uasId, int compId, in
@@ -196,138 +228,179 @@ void SensorsComponentController::_handleUASTextMessage(int uasId, int compId, in
}
_appendStatusLog ( text ) ;
qDebug ( ) < < text ;
if ( _unknownFirmwareVersion ) {
// We don't know how to do visual cal with the version of firwmare
return ;
}
// All calibration messages start with [cal]
QString calPrefix ( " [cal] " ) ;
if ( ! text . startsWith ( calPrefix ) ) {
return ;
}
text = text . right ( text . length ( ) - calPrefix . length ( ) ) ;
if ( text = = " gyro calibration: started " ) {
_updateAndEmitShowGyroCalArea ( true ) ;
_updateAndEmitGyroCalInProgress ( true ) ;
} else if ( text = = " accel calibration: started " | | text = = " mag calibration: started " ) {
if ( text = = " accel calibration: started " ) {
_accelCalInProgress = true ;
_updateAndEmitCalInProgressText ( " Hold Still " ) ;
} else {
_updateAndEmitCalInProgressText ( " Rotate " ) ;
_magCalInProgress = true ;
QString calStartPrefix ( " calibration started: " ) ;
if ( text . startsWith ( calStartPrefix ) ) {
text = text . right ( text . length ( ) - calStartPrefix . length ( ) ) ;
// Split version number and cal type
QStringList parts = text . split ( " " ) ;
if ( parts . count ( ) ! = 2 & & parts [ 0 ] . toInt ( ) ! = 1 ) {
_unknownFirmwareVersion = true ;
qDebug ( ) < < " Unknown cal firmware version, using log " ;
return ;
}
_orientationCalDownSideDone = false ;
_orientationCalUpsideDownSideDone = false ;
_orientationCalLeftSideDone = false ;
_orientationCalRightSideDone = false ;
_orientationCalTailDownSideDone = false ;
_orientationCalNoseDownSideDone = false ;
_orientationCalDownSideInProgress = false ;
_orientationCalUpsideDownSideInProgress = false ;
_orientationCalLeftSideInProgress = false ;
_orientationCalRightSideInProgress = false ;
_orientationCalNoseDownSideInProgress = false ;
_orientationCalTailDownSideInProgress = false ;
emit orientationCalSidesDoneChanged ( ) ;
emit orientationCalSidesInProgressChanged ( ) ;
_updateAndEmitShowOrientationCalArea ( true ) ;
} else if ( text . startsWith ( startingSidePrefix ) ) {
QString side = text . right ( text . length ( ) - startingSidePrefix . length ( ) ) . section ( " " , 0 , 0 ) ;
qDebug ( ) < < " Side started " < < side ;
if ( side = = " down " ) {
_orientationCalDownSideInProgress = true ;
} else if ( side = = " up " ) {
_orientationCalUpsideDownSideInProgress = true ;
} else if ( side = = " left " ) {
_orientationCalLeftSideInProgress = true ;
} else if ( side = = " right " ) {
_orientationCalRightSideInProgress = true ;
} else if ( side = = " front " ) {
_orientationCalNoseDownSideInProgress = true ;
} else if ( side = = " back " ) {
_orientationCalTailDownSideInProgress = true ;
_startVisualCalibration ( ) ;
text = parts [ 1 ] ;
if ( text = = " accel " | | text = = " mag " | | text = = " gyro " ) {
// Reset all progress indication
_orientationCalDownSideDone = false ;
_orientationCalUpsideDownSideDone = false ;
_orientationCalLeftSideDone = false ;
_orientationCalRightSideDone = false ;
_orientationCalTailDownSideDone = false ;
_orientationCalNoseDownSideDone = false ;
_orientationCalDownSideInProgress = false ;
_orientationCalUpsideDownSideInProgress = false ;
_orientationCalLeftSideInProgress = false ;
_orientationCalRightSideInProgress = false ;
_orientationCalNoseDownSideInProgress = false ;
_orientationCalTailDownSideInProgress = false ;
// Reset all visibility
_orientationCalDownSideVisible = false ;
_orientationCalUpsideDownSideVisible = false ;
_orientationCalLeftSideVisible = false ;
_orientationCalRightSideVisible = false ;
_orientationCalTailDownSideVisible = false ;
_orientationCalNoseDownSideVisible = false ;
_orientationCalAreaHelpText - > setProperty ( " text " , " Place your vehicle into one of the Incomplete orientations shown below and hold it still " ) ;
if ( text = = " accel " ) {
_accelCalInProgress = true ;
_orientationCalDownSideVisible = true ;
_orientationCalUpsideDownSideVisible = true ;
_orientationCalLeftSideVisible = true ;
_orientationCalRightSideVisible = true ;
_orientationCalTailDownSideVisible = true ;
_orientationCalNoseDownSideVisible = true ;
} else if ( text = = " mag " ) {
_magCalInProgress = true ;
_orientationCalDownSideVisible = true ;
_orientationCalLeftSideVisible = true ;
_orientationCalNoseDownSideVisible = true ;
} else if ( text = = " gyro " ) {
_gyroCalInProgress = true ;
_orientationCalDownSideVisible = true ;
} else {
Q_ASSERT ( false ) ;
}
emit orientationCalSidesDoneChanged ( ) ;
emit orientationCalSidesVisibleChanged ( ) ;
emit orientationCalSidesInProgressChanged ( ) ;
_updateAndEmitShowOrientationCalArea ( true ) ;
}
emit orientationCalSidesInProgressChanged ( ) ;
} else if ( text . endsWith ( orientationDetectedSuffix ) ) {
return ;
}
if ( text . endsWith ( " orientation detected " ) ) {
QString side = text . section ( " " , 0 , 0 ) ;
qDebug ( ) < < " Side started " < < side ;
if ( side = = " down " ) {
_orientationCalDownSideInProgress = true ;
if ( _magCalInProgress ) {
_orientationCalDownSideRotate = true ;
}
} else if ( side = = " up " ) {
_orientationCalUpsideDownSideInProgress = true ;
} else if ( side = = " left " ) {
_orientationCalLeftSideInProgress = true ;
if ( _magCalInProgress ) {
_orientationCalLeftSideRotate = true ;
}
} else if ( side = = " right " ) {
_orientationCalRightSideInProgress = true ;
} else if ( side = = " front " ) {
_orientationCalNoseDownSideInProgress = true ;
if ( _magCalInProgress ) {
_orientationCalNoseDownSideRotate = true ;
}
} else if ( side = = " back " ) {
_orientationCalTailDownSideInProgress = true ;
}
if ( _magCalInProgress ) {
_orientationCalAreaHelpText - > setProperty ( " text " , " Rotate the vehicle continuously as shown in the diagram until marked as Completed " ) ;
} else {
_orientationCalAreaHelpText - > setProperty ( " text " , " Hold still in the current orientation " ) ;
}
emit orientationCalSidesInProgressChanged ( ) ;
} else if ( text . endsWith ( sideDoneSuffix ) ) {
emit orientationCalSidesRotateChanged ( ) ;
return ;
}
if ( text . endsWith ( " side done, rotate to a different side " ) ) {
QString side = text . section ( " " , 0 , 0 ) ;
qDebug ( ) < < " Side finished " < < side ;
if ( side = = " down " ) {
_orientationCalDownSideInProgress = false ;
_orientationCalDownSideDone = true ;
_orientationCalDownSideRotate = false ;
} else if ( side = = " up " ) {
_orientationCalUpsideDownSideInProgress = false ;
_orientationCalUpsideDownSideDone = true ;
} else if ( side = = " left " ) {
_orientationCalLeftSideInProgress = false ;
_orientationCalLeftSideDone = true ;
_orientationCalLeftSideRotate = false ;
} else if ( side = = " right " ) {
_orientationCalRightSideInProgress = false ;
_orientationCalRightSideDone = true ;
} else if ( side = = " front " ) {
_orientationCalNoseDownSideInProgress = false ;
_orientationCalNoseDownSideDone = true ;
_orientationCalNoseDownSideRotate = false ;
} else if ( side = = " back " ) {
_orientationCalTailDownSideInProgress = false ;
_orientationCalTailDownSideDone = true ;
}
_orientationCalAreaHelpText - > setProperty ( " text " , " Place you vehicle into one of the orientations shown below and hold it still " ) ;
emit orientationCalSidesInProgressChanged ( ) ;
emit orientationCalSidesDoneChanged ( ) ;
} else if ( text = = " accel calibration: done " | | text = = " mag calibration: done " ) {
_progressBar - > setProperty ( " value " , 1 ) ;
_orientationCalDownSideDone = true ;
_orientationCalUpsideDownSideDone = true ;
_orientationCalLeftSideDone = true ;
_orientationCalRightSideDone = true ;
_orientationCalTailDownSideDone = true ;
_orientationCalNoseDownSideDone = true ;
_orientationCalDownSideInProgress = false ;
_orientationCalUpsideDownSideInProgress = false ;
_orientationCalLeftSideInProgress = false ;
_orientationCalRightSideInProgress = false ;
_orientationCalNoseDownSideInProgress = false ;
_orientationCalTailDownSideInProgress = false ;
emit orientationCalSidesDoneChanged ( ) ;
emit orientationCalSidesInProgressChanged ( ) ;
_stopCalibration ( false /* success */ ) ;
} else if ( text = = " gyro calibration: done " ) {
_stopCalibration ( false /* success */ ) ;
} else if ( text = = " dpress calibration: done " ) {
_stopCalibration ( false /* success */ ) ;
} else if ( text . endsWith ( " calibration: failed " ) ) {
_stopCalibration ( true /* failed */ ) ;
emit orientationCalSidesRotateChanged ( ) ;
return ;
}
}
void SensorsComponentController : : _refreshParams ( void )
{
// Pull specified params first so red/green indicators update quickly
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " CAL_MAG0_ID " ) ;
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " CAL_GYRO0_ID " ) ;
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " CAL_ACC0_ID " ) ;
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " SENS_DPRES_OFF " ) ;
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " SENS_BOARD_ROT " ) ;
// Mag rotation parameters are optional
if ( _autopilot - > parameterExists ( " CAL_MAG0_ROT " ) ) {
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " CAL_MAG0_ROT " ) ;
}
if ( _autopilot - > parameterExists ( " CAL_MAG1_ROT " ) ) {
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " CAL_MAG1_ROT " ) ;
QString calCompletePrefix ( " calibration done: " ) ;
if ( text . startsWith ( calCompletePrefix ) ) {
_stopCalibration ( StopCalibrationSuccess ) ;
return ;
}
if ( _autopilot - > parameterExists ( " CAL_MAG2_ROT " ) ) {
_autopilot - > refreshParameter ( FactSystem : : defaultComponentId , " CAL_MAG2_ROT " ) ;
if ( text . startsWith ( " calibration cancelled " ) ) {
_stopCalibration ( _waitingForCancel ? StopCalibrationCancelled : StopCalibrationFailed ) ;
return ;
}
if ( text . startsWith ( " calibration failed " ) ) {
_stopCalibration ( StopCalibrationFailed ) ;
return ;
}
}
void SensorsComponentController : : _refreshParams ( void )
{
// Pull full set in order to get all cal values back
_autopilot - > refreshAllParameters ( ) ;
}
@ -339,18 +412,6 @@ bool SensorsComponentController::fixedWing(void)
@@ -339,18 +412,6 @@ bool SensorsComponentController::fixedWing(void)
return uas - > getSystemType ( ) = = MAV_TYPE_FIXED_WING ;
}
void SensorsComponentController : : _updateAndEmitGyroCalInProgress ( bool inProgress )
{
_gyroCalInProgress = inProgress ;
emit gyroCalInProgressChanged ( ) ;
}
void SensorsComponentController : : _updateAndEmitShowGyroCalArea ( bool show )
{
_showGyroCalArea = show ;
emit showGyroCalAreaChanged ( ) ;
}
void SensorsComponentController : : _updateAndEmitShowOrientationCalArea ( bool show )
{
_showOrientationCalArea = show ;
@ -359,12 +420,15 @@ void SensorsComponentController::_updateAndEmitShowOrientationCalArea(bool show)
@@ -359,12 +420,15 @@ void SensorsComponentController::_updateAndEmitShowOrientationCalArea(bool show)
void SensorsComponentController : : _hideAllCalAreas ( void )
{
_updateAndEmitShowGyroCalArea ( false ) ;
_updateAndEmitShowOrientationCalArea ( false ) ;
}
void SensorsComponentController : : _updateAndEmitCalInProgressText ( const QString & text )
void SensorsComponentController : : cancelCalibration ( void )
{
_calInProgressText = text ;
emit calInProgressTextChanged ( text ) ;
}
// The firmware doesn't allow us to cancel calibration. The best we can do is wait
// for it to timeout.
_waitingForCancel = true ;
emit waitingForCancelChanged ( ) ;
_cancelButton - > setEnabled ( false ) ;
_uas - > stopCalibration ( ) ;
}