Skip to content

Commit

Permalink
Show the limit in motors graph
Browse files Browse the repository at this point in the history
  • Loading branch information
McGiverGim committed Oct 23, 2020
1 parent a063ae5 commit ae5f7db
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
11 changes: 10 additions & 1 deletion js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,16 @@ FlightLog.prototype.rcCommandRawToThrottle = function(value) {

FlightLog.prototype.rcMotorRawToPct = function(value) {
// Motor displayed as percentage
return Math.min(Math.max(((value - this.getSysConfig().motorOutput[0]) / (this.getSysConfig().motorOutput[1] - this.getSysConfig().motorOutput[0])) * 100.0, 0.0),100.0);
let motorPct;
if (this.getSysConfig().fast_pwm_protocol < FAST_PROTOCOL.indexOf('DSHOT150')) {
// Analog protocol
const ANALOG_RANGE = this.getSysConfig().maxthrottle - ANALOG_MIN_VALUE;
motorPct = ((value - ANALOG_MIN_VALUE) / ANALOG_RANGE) * 100;
} else {
// Digital protocol
motorPct = ((value - DSHOT_MIN_VALUE) / DSHOT_RANGE) * 100;
}
return Math.min(Math.max(motorPct, 0.0), 100.0);
};

FlightLog.prototype.getPIDPercentage = function(value) {
Expand Down
7 changes: 7 additions & 0 deletions js/flightlog_fielddefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ function makeReadOnly(x) {
return x;
}

// Some constants used at different places
const DSHOT_MIN_VALUE = 48;
const DSHOT_MAX_VALUE = 2047;
const DSHOT_RANGE = DSHOT_MAX_VALUE - DSHOT_MIN_VALUE;
const ANALOG_MIN_VALUE = 1000;

// Fields definitions for lists
var
FlightLogEvent = makeReadOnly({
SYNC_BEEP: 0,
Expand Down
2 changes: 1 addition & 1 deletion js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ function FlightLogFieldPresenter() {
case 'motor[5]':
case 'motor[6]':
case 'motor[7]':
return Math.round(flightLog.rcMotorRawToPct(value)) + " %";
return `${Math.round(flightLog.rcMotorRawToPct(value))} %`;

case 'rcCommands[0]':
case 'rcCommands[1]':
Expand Down
1 change: 1 addition & 0 deletions js/flightlog_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ var FlightLogParser = function(logData) {
case "rates_type":
case "vbat_sag_compensation":
case "fields_disabled_mask":
case "motor_pwm_protocol":
that.sysConfig[fieldName] = parseInt(fieldValue, 10);
break;
case "rc_expo":
Expand Down
7 changes: 4 additions & 3 deletions js/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ GraphConfig.load = function(config) {
try {
if (fieldName.match(/^motor\[/)) {
return {
offset: -(sysConfig.motorOutput[1] + sysConfig.motorOutput[0]) / 2,
offset: sysConfig.fast_pwm_protocol < FAST_PROTOCOL.indexOf('DSHOT150') ?
-(ANALOG_MIN_VALUE + (sysConfig.maxthrottle - ANALOG_MIN_VALUE) / 2) : -(DSHOT_MIN_VALUE + DSHOT_RANGE / 2),
power: 1.0,
inputRange: (sysConfig.motorOutput[1] - sysConfig.motorOutput[0]) / 2,
outputRange: 1.0
inputRange: sysConfig.fast_pwm_protocol < FAST_PROTOCOL.indexOf('DSHOT150') ? (sysConfig.maxthrottle - ANALOG_MIN_VALUE) / 2 : DSHOT_RANGE / 2,
outputRange: 1.0,
};
} else if (fieldName.match(/^servo\[/)) {
return {
Expand Down

0 comments on commit ae5f7db

Please sign in to comment.