mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-15 04:15:28 +03:00
saving of PID tunings is fully working now
This commit is contained in:
parent
b064b11740
commit
37c576bd24
2 changed files with 66 additions and 25 deletions
|
@ -46,13 +46,14 @@ var CONFIG = {
|
||||||
cycleTime: 0,
|
cycleTime: 0,
|
||||||
i2cError: 0,
|
i2cError: 0,
|
||||||
activeSensors: 0,
|
activeSensors: 0,
|
||||||
mode: 0,
|
mode: 0
|
||||||
gyroscope: [0, 0, 0],
|
|
||||||
accelerometer: [0, 0, 0],
|
|
||||||
magnetometer: [0, 0, 0],
|
|
||||||
altitude: 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var PIDs = new Array(10);
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
PIDs[i] = new Array(3);
|
||||||
|
}
|
||||||
|
|
||||||
var RC = {
|
var RC = {
|
||||||
roll: 0,
|
roll: 0,
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
|
@ -64,10 +65,12 @@ var RC = {
|
||||||
AUX4: 0
|
AUX4: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var PIDs = new Array(10);
|
var SENSOR_DATA = {
|
||||||
for (var i = 0; i < 10; i++) {
|
gyroscope: [0, 0, 0],
|
||||||
PIDs[i] = new Array(3);
|
accelerometer: [0, 0, 0],
|
||||||
}
|
magnetometer: [0, 0, 0],
|
||||||
|
altitude: 0
|
||||||
|
};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
port_picker = $('div#port-picker .port select');
|
port_picker = $('div#port-picker .port select');
|
||||||
|
@ -258,8 +261,8 @@ function onCharRead(readInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_message(code, data, bytes_n) {
|
function send_message(code, data, bytes_n) {
|
||||||
if (typeof data === 'array') { // array portion of this code is untested TODO: test ?
|
if (typeof data === 'object') {
|
||||||
var size = 6 + data.length;
|
var size = 6 + bytes_n;
|
||||||
var checksum = 0;
|
var checksum = 0;
|
||||||
|
|
||||||
var bufferOut = new ArrayBuffer(size);
|
var bufferOut = new ArrayBuffer(size);
|
||||||
|
@ -318,17 +321,17 @@ function process_message(code, data) {
|
||||||
sensor_status(CONFIG.activeSensors);
|
sensor_status(CONFIG.activeSensors);
|
||||||
break;
|
break;
|
||||||
case MSP_codes.MSP_RAW_IMU:
|
case MSP_codes.MSP_RAW_IMU:
|
||||||
CONFIG.accelerometer[0] = view.getInt16(0, 1);
|
SENSOR_DATA.accelerometer[0] = view.getInt16(0, 1);
|
||||||
CONFIG.accelerometer[1] = view.getInt16(2, 1);
|
SENSOR_DATA.accelerometer[1] = view.getInt16(2, 1);
|
||||||
CONFIG.accelerometer[2] = view.getInt16(4, 1);
|
SENSOR_DATA.accelerometer[2] = view.getInt16(4, 1);
|
||||||
|
|
||||||
CONFIG.gyroscope[0] = view.getInt16(6, 1) / 8;
|
SENSOR_DATA.gyroscope[0] = view.getInt16(6, 1) / 8;
|
||||||
CONFIG.gyroscope[1] = view.getInt16(8, 1) / 8;
|
SENSOR_DATA.gyroscope[1] = view.getInt16(8, 1) / 8;
|
||||||
CONFIG.gyroscope[2] = view.getInt16(10, 1) / 8;
|
SENSOR_DATA.gyroscope[2] = view.getInt16(10, 1) / 8;
|
||||||
|
|
||||||
CONFIG.magnetometer[0] = view.getInt16(12, 1) / 3;
|
SENSOR_DATA.magnetometer[0] = view.getInt16(12, 1) / 3;
|
||||||
CONFIG.magnetometer[1] = view.getInt16(14, 1) / 3;
|
SENSOR_DATA.magnetometer[1] = view.getInt16(14, 1) / 3;
|
||||||
CONFIG.magnetometer[2] = view.getInt16(16, 1) / 3;
|
SENSOR_DATA.magnetometer[2] = view.getInt16(16, 1) / 3;
|
||||||
break;
|
break;
|
||||||
case MSP_codes.MSP_SERVO:
|
case MSP_codes.MSP_SERVO:
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
@ -357,7 +360,7 @@ function process_message(code, data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
break;
|
break;
|
||||||
case MSP_codes.MSP_ALTITUDE:
|
case MSP_codes.MSP_ALTITUDE:
|
||||||
CONFIG.altitude = view.getUint32(0, 1);
|
SENSOR_DATA.altitude = view.getUint32(0, 1);
|
||||||
break;
|
break;
|
||||||
case MSP_codes.MSP_BAT:
|
case MSP_codes.MSP_BAT:
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
@ -419,7 +422,7 @@ function process_message(code, data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
break;
|
break;
|
||||||
case MSP_codes.MSP_SET_PID:
|
case MSP_codes.MSP_SET_PID:
|
||||||
console.log(data);
|
console.log('PID settings saved');
|
||||||
break;
|
break;
|
||||||
case MSP_codes.MSP_SET_BOX:
|
case MSP_codes.MSP_SET_BOX:
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
|
@ -92,8 +92,46 @@ function tab_initialize_pid_tuning() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send over the changes
|
var PID_buffer_out = new Array();
|
||||||
|
var PID_buffer_needle = 0;
|
||||||
|
for (var i = 0; i < PIDs.length; i++) {
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 7:
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
|
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10);
|
||||||
|
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 1000);
|
||||||
|
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 100);
|
||||||
|
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100);
|
||||||
|
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
case 6:
|
||||||
|
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10);
|
||||||
|
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100);
|
||||||
|
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2] * 1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PID_buffer_needle += 3;
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (var ii = 0; ii < PIDs[i].length; ii++) {
|
||||||
|
PID_buffer_out[PID_buffer_needle] = PIDs[i][ii];
|
||||||
|
PID_buffer_needle++;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log(PID_buffer_out);
|
||||||
|
// Send over the changes
|
||||||
|
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out, PID_buffer_out.length);
|
||||||
|
|
||||||
// remove the active status
|
// remove the active status
|
||||||
$(this).removeClass('active');
|
$(this).removeClass('active');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue