Skip to content

Commit

Permalink
Add (e)RPM black box field (#640)
Browse files Browse the repository at this point in the history
* Add RPM black box field

* Add RPM to example graphs

* Use same scaling for all RPM fields

* Change name of RPM field to eRPM(/100)
 - Add RPM to enabled/disabled black box fields in header dialog
 - Add escapeRegExp function to tools.js
 - Escape nameRoot before using as regexp for creating [all] fields in graph_config
  • Loading branch information
tbolin authored Jun 19, 2023
1 parent 0b44109 commit 6876aa2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1336,5 +1336,6 @@ FlightLog.prototype.isFieldDisabled = function() {
DEBUG : (disabledFields & (1 << 9))!==0,
MOTORS : (disabledFields & (1 << 10))!==0,
GPS : (disabledFields & (1 << 11))!==0,
RPM : (disabledFields & (1 << 12))!==0,
};
};
21 changes: 21 additions & 0 deletions js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ function FlightLogFieldPresenter() {
'motor[6]': 'Motor [7]',
'motor[7]': 'Motor [8]',

'eRPM(/100)[all]': 'RPM',
'eRPM(/100)[0]': 'RPM [1]',
'eRPM(/100)[1]': 'RPM [2]',
'eRPM(/100)[2]': 'RPM [3]',
'eRPM(/100)[3]': 'RPM [4]',
'eRPM(/100)[4]': 'RPM [5]',
'eRPM(/100)[5]': 'RPM [6]',
'eRPM(/100)[6]': 'RPM [7]',
'eRPM(/100)[7]': 'RPM [8]',

'servo[all]': 'Servos',
'servo[5]': 'Servo Tail',

Expand Down Expand Up @@ -1290,6 +1300,17 @@ function FlightLogFieldPresenter() {
case 'motor[7]':
return `${flightLog.rcMotorRawToPctPhysical(value).toFixed(2)} %`;

case 'eRPM(/100)[0]':
case 'eRPM(/100)[1]':
case 'eRPM(/100)[2]':
case 'eRPM(/100)[3]':
case 'eRPM(/100)[4]':
case 'eRPM(/100)[5]':
case 'eRPM(/100)[6]':
case 'eRPM(/100)[7]':
let motor_poles = flightLog.getSysConfig()['motor_poles'];
return (value * 200 / motor_poles).toFixed(0) + " rpm / " + (value * 3.333 / motor_poles).toFixed(1) + ' hz';

case 'rcCommands[0]':
case 'rcCommands[1]':
case 'rcCommands[2]':
Expand Down
7 changes: 6 additions & 1 deletion js/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function GraphConfig(graphConfig) {
if ((matches = field.name.match(/^(.+)\[all\]$/))) {
var
nameRoot = matches[1],
nameRegex = new RegExp("^" + nameRoot + "\[[0-9]+\]$"),
nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"),
colorIndexOffset = 0;

for (var k = 0; k < logFieldNames.length; k++) {
Expand Down Expand Up @@ -267,6 +267,8 @@ GraphConfig.load = function(config) {
DSHOT_RANGE / 2 : (sysConfig.maxthrottle - sysConfig.minthrottle) / 2,
outputRange: 1.0,
};
} else if (fieldName.match(/^eRPM\(\/100\)\[/)) {
return getCurveForMinMaxFields('eRPM(/100)[0]', 'eRPM(/100)[1]', 'eRPM(/100)[2]', 'eRPM(/100)[3]', 'eRPM(/100)[4]', 'eRPM(/100)[5]', 'eRPM(/100)[6]', 'eRPM(/100)[7]');
} else if (fieldName.match(/^servo\[/)) {
return {
offset: -1500,
Expand Down Expand Up @@ -955,6 +957,9 @@ GraphConfig.load = function(config) {
EXAMPLE_GRAPHS.push({label: "Motors",fields: ["motor[all]", "servo[5]"]});
EXAMPLE_GRAPHS.push({label: "Motors (Legacy)",fields: ["motorLegacy[all]", "servo[5]"]});
}
if (!flightLog.isFieldDisabled().RPM) {
EXAMPLE_GRAPHS.push({label: "RPM",fields: ["eRPM(/100)[all]"]});
}
if (!flightLog.isFieldDisabled().GYRO) {
EXAMPLE_GRAPHS.push({label: "Gyros",fields: ["gyroADC[all]"]});
}
Expand Down
1 change: 1 addition & 0 deletions js/header_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ function HeaderDialog(dialog, onSave) {
{name: 'Debug', description: 'Debug values'},
{name: 'Motors', description: 'Motors and tricopter servo values'},
{name: 'GPS', description: 'All GPS-related values'},
{name: 'RPM', description: 'Angular velocity for all motors'},
];

const fieldsList_e = $('.fields_list');
Expand Down
4 changes: 4 additions & 0 deletions js/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,7 @@ function getManifestVersion(manifest) {
return "-"
}
}

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

0 comments on commit 6876aa2

Please sign in to comment.