Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mag cal values #3603

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3097,7 +3097,7 @@
"message": "Accelerometer - g (deg)"
},
"sensorsMagTitle": {
"message": "Magnetometer - Ga"
"message": "Magnetometer"
},
"sensorsAltitudeTitle": {
"message": "Altitude - meters"
Expand Down
6 changes: 3 additions & 3 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ MspHelper.prototype.process_data = function(dataHandler) {
FC.SENSOR_DATA.gyroscope[2] = data.read16() * (4 / 16.4);

// no clue about scaling factor
FC.SENSOR_DATA.magnetometer[0] = data.read16() / 1090;
FC.SENSOR_DATA.magnetometer[1] = data.read16() / 1090;
FC.SENSOR_DATA.magnetometer[2] = data.read16() / 1090;
FC.SENSOR_DATA.magnetometer[0] = data.read16();
FC.SENSOR_DATA.magnetometer[1] = data.read16();
FC.SENSOR_DATA.magnetometer[2] = data.read16();
break;
case MSPCodes.MSP_SERVO:
const servoCount = data.byteLength / 2;
Expand Down
49 changes: 46 additions & 3 deletions src/js/tabs/sensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ sensors.initialize = function (callback) {
}
}

let magMaxX = 0;
let magMinX = 0;
let magMaxY = 0;
let magMinY = 0;
let magMaxZ = 0;
let magMinZ = 0;
function magCalX(newData) {
magMaxX = Math.max(magMaxX, newData);
magMinX = Math.min(magMinX, newData);
return ((magMaxX + magMinX)/2).toFixed(0);
}
function magCalY(newData) {
magMaxY = Math.max(magMaxY, newData);
magMinY = Math.min(magMinY, newData);
return ((magMaxY + magMinY)/2).toFixed(0);
}
function magCalZ(newData) {
magMaxZ = Math.max(magMaxZ, newData);
magMinZ = Math.min(magMinZ, newData);
return ((magMaxZ + magMinZ)/2).toFixed(0);
}


$('#content').load("./tabs/sensors.html", function load_html() {
// translate to user-selected language
i18n.localizePage();
Expand Down Expand Up @@ -429,9 +452,29 @@ sensors.initialize = function (callback) {

samples_mag_i = addSampleToData(mag_data, samples_mag_i, FC.SENSOR_DATA.magnetometer);
drawGraph(magHelpers, mag_data, samples_mag_i);
raw_data_text_ements.x[2].text(FC.SENSOR_DATA.magnetometer[0].toFixed(2));
raw_data_text_ements.y[2].text(FC.SENSOR_DATA.magnetometer[1].toFixed(2));
raw_data_text_ements.z[2].text(FC.SENSOR_DATA.magnetometer[2].toFixed(2));

const magX = FC.SENSOR_DATA.magnetometer[0];
const magY = FC.SENSOR_DATA.magnetometer[1];
const magZ = FC.SENSOR_DATA.magnetometer[2];
const magXSquared = Math.pow(FC.SENSOR_DATA.magnetometer[0], 2);
const magYSquared = Math.pow(FC.SENSOR_DATA.magnetometer[1], 2);
const magZSquared = Math.pow(FC.SENSOR_DATA.magnetometer[2], 2);
const magSumSqR = Math.sqrt(magXSquared + magYSquared + magZSquared).toFixed(0);
const magCalibrationX = magCalX(magX);
const magCalibrationY = magCalY(magY);
const magCalibrationZ = magCalZ(magZ);

samples_mag_i = addSampleToData(mag_data, samples_mag_i, FC.SENSOR_DATA.magnetometer);
drawGraph(magHelpers, mag_data, samples_mag_i);

// raw_data_text_ements.x[2].text(FC.SENSOR_DATA.magnetometer[0].toFixed(2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these comments here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not really, they can go away. Just kept them to remember the original code.
I'll remove them when the consensus is to merge or not merge.
What we really need is a dedicated 'Mag' tab, similar in concept to the dedicated 'GPS' tab, where we can perform calibrations, check raw values, etc.

raw_data_text_ements.x[2].text(`${magX} C${magCalibrationX}`);
// raw_data_text_ements.y[2].text(FC.SENSOR_DATA.magnetometer[1].toFixed(2));
raw_data_text_ements.y[2].text(`${magY} C${magCalibrationY}`);
// raw_data_text_ements.z[2].text(FC.SENSOR_DATA.magnetometer[2].toFixed(2));
// raw_data_text_ements.z[2].text(`${magZ} R${magSumSqR}`);
raw_data_text_ements.z[2].text(`${magZ} C${magCalibrationZ}`);

}
}

Expand Down
9 changes: 7 additions & 2 deletions src/tabs/sensors.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@
<dt i18n="sensorsScale"></dt>
<dd class="scale">
<select name="mag_scale">
<option value="0.5">0.5</option>
<option value="1" selected="selected">1</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="2000" selected="selected">2000</option>
<option value="5000">5000</option>
<option value="10000">10000</option>
</select>
</dd>
<dt>X:</dt>
Expand Down