Skip to content

Commit e36f00c

Browse files
Merge pull request #759 from iNavFlight/de_opflow_calibration
[OPFLOW] Initial cut on optic flow calibration
2 parents 79c3948 + 5916100 commit e36f00c

File tree

6 files changed

+102
-2
lines changed

6 files changed

+102
-2
lines changed

_locales/en/messages.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@
463463
"initialSetupMagCalibEnded": {
464464
"message": "Magnetometer calibration <span style=\"color: #37a8db\">finished</span>"
465465
},
466+
"initialSetupOpflowCalibStarted": {
467+
"message": "Optic flow calibration started"
468+
},
469+
"initialSetupOpflowCalibEnded": {
470+
"message": "Optic flow calibration <span style=\"color: #37a8db\">finished</span>"
471+
},
466472
"initialSetupSettingsRestored": {
467473
"message": "Settings restored to <strong>default</strong>"
468474
},
@@ -2068,6 +2074,15 @@
20682074
"calibrationHead4": {
20692075
"message": "Compass Calibration"
20702076
},
2077+
"calibrationHead5": {
2078+
"message": "Optic Flow Calibration"
2079+
},
2080+
"OpflowCalText": {
2081+
"message": "After pressing the button you have 30 seconds to hold the copter in the air and tilt it to sides without moving it horizontally. Note that optic flow sensor needs to observe the surface at all times."
2082+
},
2083+
"OpflowCalBtn": {
2084+
"message": "Calibrate Optic Flow sensor"
2085+
},
20712086
"accZero": {
20722087
"message": "Acc Zero"
20732088
},

js/fc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ var FC = {
400400
X: null,
401401
Y: null,
402402
Z: null
403+
},
404+
opflow: {
405+
Scale: null
403406
}
404407
};
405408

js/msp/MSPCodes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,7 @@ var MSPCodes = {
209209
MSP2_INAV_SET_LOGIC_CONDITIONS: 0x2023,
210210

211211
MSP2_PID: 0x2030,
212-
MSP2_SET_PID: 0x2031
212+
MSP2_SET_PID: 0x2031,
213+
214+
MSP2_INAV_OPFLOW_CALIBRATION: 0x2032
213215
};

js/msp/MSPHelper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@ var mspHelper = (function (gui) {
642642
case MSPCodes.MSP_MAG_CALIBRATION:
643643
console.log('Mag calibration executed');
644644
break;
645+
case MSPCodes.MSP2_INAV_OPFLOW_CALIBRATION:
646+
console.log('Optic flow calibration executed');
647+
break;
645648
case MSPCodes.MSP_SET_MISC:
646649
console.log('MISC Configuration saved');
647650
break;
@@ -1293,6 +1296,11 @@ var mspHelper = (function (gui) {
12931296
CALIBRATION_DATA.magZero.X = data.getInt16(13, true);
12941297
CALIBRATION_DATA.magZero.Y = data.getInt16(15, true);
12951298
CALIBRATION_DATA.magZero.Z = data.getInt16(17, true);
1299+
1300+
if (semver.gte(CONFIG.flightControllerVersion, "2.2.0")) {
1301+
CALIBRATION_DATA.opflow.Scale = (data.getInt16(19, true) / 256.0);
1302+
}
1303+
12961304
break;
12971305

12981306
case MSPCodes.MSP_SET_CALIBRATION_DATA:
@@ -1945,6 +1953,11 @@ var mspHelper = (function (gui) {
19451953

19461954
buffer.push(lowByte(CALIBRATION_DATA.magZero.Z));
19471955
buffer.push(highByte(CALIBRATION_DATA.magZero.Z));
1956+
1957+
if (semver.gte(CONFIG.flightControllerVersion, "2.2.0")) {
1958+
buffer.push(lowByte(Math.round(CALIBRATION_DATA.opflow.Scale * 256)));
1959+
buffer.push(highByte(Math.round(CALIBRATION_DATA.opflow.Scale * 256)));
1960+
}
19481961
break;
19491962

19501963
case MSPCodes.MSP_SET_POSITION_ESTIMATION_CONFIG:

tabs/calibration.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@
115115
</table>
116116
</div>
117117
</div>
118+
<div class="gui_box grey">
119+
<div class="gui_box_titlebar">
120+
<div class="spacer_box_title" data-i18n="calibrationHead5"></div>
121+
</div>
122+
<div class="spacer_box">
123+
<span data-i18n="OpflowCalText">text</span>
124+
<div class="default_btn">
125+
<div id="opflow_btn">
126+
<a class="calibrateopflow" href="#" data-i18n="OpflowCalBtn"></a>
127+
</div>
128+
</div>
129+
<table id="opflow-calibrated-data" class="cf_table">
130+
<tr>
131+
<td><label for="OpflowScale"><span>Scale</span></label></td>
132+
<td><input type="number" name="OpflowScale" min="0" max="10000"></td>
133+
</tr>
134+
</table>
135+
</div>
136+
</div>
118137
</div>
119138
</div>
120139
</div>
@@ -155,3 +174,10 @@ <h1 class="modal__title modal__title--center" data-i18n="accCalibrationProcessin
155174
<div id="modal-compass-countdown" class="modal__text"></div>
156175
</div>
157176
</div>
177+
178+
<div id="modal-opflow-processing" class="is-hidden">
179+
<div class="modal__content">
180+
<h1 class="modal__title modal__title--center" data-i18n="accCalibrationProcessing"></h1>
181+
<div id="modal-opflow-countdown" class="modal__text"></div>
182+
</div>
183+
</div>

tabs/calibration.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ TABS.calibration.initialize = function (callback) {
6161
loadChainer.execute();
6262

6363
saveChainer.setChain([
64-
mspHelper.saveCalibrationData
64+
mspHelper.saveCalibrationData,
65+
mspHelper.saveToEeprom
6566
]);
6667
saveChainer.setExitPoint(reboot);
6768

@@ -105,6 +106,7 @@ TABS.calibration.initialize = function (callback) {
105106
$('[name=accZero' + item + ']').val(CALIBRATION_DATA.accZero[item]);
106107
$('[name=Mag' + item + ']').val(CALIBRATION_DATA.magZero[item]);
107108
});
109+
$('[name=OpflowScale]').val(CALIBRATION_DATA.opflow.Scale);
108110
updateCalibrationSteps();
109111
}
110112

@@ -176,6 +178,7 @@ TABS.calibration.initialize = function (callback) {
176178

177179
function processHtml() {
178180
$('#calibrateButtonSave').on('click', function () {
181+
CALIBRATION_DATA.opflow.Scale = parseFloat($('[name=OpflowScale]').val());
179182
saveChainer.execute();
180183
});
181184

@@ -184,6 +187,11 @@ TABS.calibration.initialize = function (callback) {
184187
$('#mag_btn, #mag-calibrated-data').css('pointer-events', 'none').css('opacity', '0.4');
185188
}
186189

190+
if (SENSOR_CONFIG.opflow === 0) {
191+
//Comment for test
192+
$('#opflow_btn, #opflow-calibrated-data').css('pointer-events', 'none').css('opacity', '0.4');
193+
}
194+
187195
$('#mag_btn').on('click', function () {
188196
MSP.send_message(MSPCodes.MSP_MAG_CALIBRATION, false, false, function () {
189197
GUI.log(chrome.i18n.getMessage('initialSetupMagCalibStarted'));
@@ -217,6 +225,39 @@ TABS.calibration.initialize = function (callback) {
217225
}, 1000);
218226
});
219227

228+
$('#opflow_btn').on('click', function () {
229+
MSP.send_message(MSPCodes.MSP2_INAV_OPFLOW_CALIBRATION, false, false, function () {
230+
GUI.log(chrome.i18n.getMessage('initialSetupOpflowCalibStarted'));
231+
});
232+
233+
var button = $(this);
234+
235+
$(button).addClass('disabled');
236+
237+
modalProcessing = new jBox('Modal', {
238+
width: 400,
239+
height: 100,
240+
animation: false,
241+
closeOnClick: false,
242+
closeOnEsc: false,
243+
content: $('#modal-opflow-processing')
244+
}).open();
245+
246+
var countdown = 30;
247+
helper.interval.add('opflow_calibration_interval', function () {
248+
countdown--;
249+
$('#modal-opflow-countdown').text(countdown);
250+
if (countdown === 0) {
251+
$(button).removeClass('disabled');
252+
253+
modalProcessing.close();
254+
GUI.log(chrome.i18n.getMessage('initialSetupOpflowCalibEnded'));
255+
MSP.send_message(MSPCodes.MSP_CALIBRATION_DATA, false, false, updateSensorData);
256+
helper.interval.remove('opflow_calibration_interval');
257+
}
258+
}, 1000);
259+
});
260+
220261
$('#modal-start-button').click(function () {
221262
modalStart.close();
222263
TABS.calibration.model.next();

0 commit comments

Comments
 (0)