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

Added motor/esc protocol settings to configuration tab #25

Merged
merged 1 commit into from
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1626,5 +1626,14 @@
},
"mainHelpLink": {
"message": "Serial Link Status"
},
"configurationEscProtocol": {
"message": "ESC/Motor protocol"
},
"configurationunsyndePwm": {
"message": "Unsynced PWM output"
},
"configurationUnsyncedPWMFreq": {
"message": "Unsynced PWM frequency"
}
}
11 changes: 10 additions & 1 deletion js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var SENSOR_ALIGNMENT;
var RX_CONFIG;
var FAILSAFE_CONFIG;
var RXFAIL_CONFIG;
var PID_ADVANCED_CONFIG;

var FC = {
resetState: function() {
Expand Down Expand Up @@ -235,6 +236,14 @@ var FC = {
align_mag: 0
};

PID_ADVANCED_CONFIG = {
gyro_sync_denom: 0,
pid_process_denom: 0,
use_unsyncedPwm: 0,
fast_pwm_protocol: 0,
motor_pwm_rate: 0
};

RX_CONFIG = {
serialrx_provider: 0,
maxcheck: 0,
Expand All @@ -256,4 +265,4 @@ var FC = {

RXFAIL_CONFIG = [];
}
};
};
21 changes: 19 additions & 2 deletions js/msp.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ var MSP_codes = {
MSP_SET_BLACKBOX_CONFIG: 81,
MSP_TRANSPONDER_CONFIG: 82,
MSP_SET_TRANSPONDER_CONFIG: 83,

MSP_PID_ADVANCED_CONFIG: 90,
MSP_SET_PID_ADVANCED_CONFIG: 91,

// Multiwii MSP commands
MSP_IDENT: 100,
Expand Down Expand Up @@ -868,7 +871,14 @@ var MSP = {
}
break;


case MSP_codes.MSP_PID_ADVANCED_CONFIG:
var offset = 0;
PID_ADVANCED_CONFIG.gyro_sync_denom = data.getUint8(offset++, 1);
PID_ADVANCED_CONFIG.pid_process_denom = data.getUint8(offset++, 1);
PID_ADVANCED_CONFIG.use_unsyncedPwm = data.getUint8(offset++, 1);
PID_ADVANCED_CONFIG.fast_pwm_protocol = data.getUint8(offset++, 1);
PID_ADVANCED_CONFIG.motor_pwm_rate = data.getUint16(offset++, 1);
break;
case MSP_codes.MSP_LED_STRIP_CONFIG:
LED_STRIP = [];

Expand Down Expand Up @@ -1364,7 +1374,14 @@ MSP.crunch = function (code) {
buffer.push(SENSOR_ALIGNMENT.align_acc);
buffer.push(SENSOR_ALIGNMENT.align_mag);
break

case MSP_codes.MSP_SET_PID_ADVANCED_CONFIG:
buffer.push(PID_ADVANCED_CONFIG.gyro_sync_denom);
buffer.push(PID_ADVANCED_CONFIG.pid_process_denom);
buffer.push(PID_ADVANCED_CONFIG.use_unsyncedPwm);
buffer.push(PID_ADVANCED_CONFIG.fast_pwm_protocol);
buffer.push(lowByte(PID_ADVANCED_CONFIG.motor_pwm_rate));
buffer.push(highByte(PID_ADVANCED_CONFIG.motor_pwm_rate));
break;
default:
return false;
}
Expand Down
16 changes: 15 additions & 1 deletion tabs/configuration.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@
font-weight: normal;
}

.tab-configuration .numberwide input {
width: 55px;
padding-left: 3px;
height: 20px;
line-height: 20px;
text-align: left;
border: 1px solid silver;
border-radius: 3px;
margin-right: 11px;
font-size: 12px;
font-weight: normal;
}


.tab-configuration .number .disabled {
width: 43px;
padding: 0px 5px;
Expand Down Expand Up @@ -490,4 +504,4 @@
.tab-configuration .current .gui_box {
float: left;
}
}
}
29 changes: 28 additions & 1 deletion tabs/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,40 @@
<div class="spacer_box_title" i18n="configurationEscFeatures"></div>
</div>
<div class="spacer_box">
<div class="select">
<label>
<select class="escprotocol">
<!-- list generated here -->
</select>
<span i18n="configurationEscProtocol"></span>
</label>
</div>

<div class="checkbox">
<div style="float: left; height: 20px; margin-right: 15px; margin-left: 3px;">
<input type="checkbox" name="unsyncedPWMSwitch" class="toggle" />
</div>
<label for="unsyncedpwmswitch"> <span class="freelabel"
i18n="configurationunsyndePwm"></span>
</label>
</div>
<div class="numberwide unsyncedpwmfreq" style="display: show; margin-top: 5px;">
<label>
<div class="numberspacer">
<input type="number" name="unsyncedpwmfreq" min="200" max="32000" />
</div>
<span i18n="configurationUnsyncedPWMFreq"></span>
</label>
</div>


<table cellpadding="0" cellspacing="0">
<tbody class="features esc">
<!-- table generated here -->
</tbody>
</table>
<!-- -->
<div class="disarm">
<div class="disarm">
<div class="checkbox">
<div style="float: left; height: 20px; margin-right: 15px; margin-left: 3px;">
<input type="checkbox" name="disarmkillswitch" class="toggle" />
Expand Down
68 changes: 66 additions & 2 deletions tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}

function load_3d() {
var next_callback = load_sensor_alignment;
var next_callback = esc_protocol;
if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
MSP.send_message(MSP_codes.MSP_3D, false, false, next_callback);
} else {
next_callback();
}
}

function esc_protocol() {
var next_callback = load_sensor_alignment;
if (semver.gte(CONFIG.apiVersion, "1.16.0")) {
MSP.send_message(MSP_codes.MSP_PID_ADVANCED_CONFIG, false, false, next_callback);
} else {
next_callback();
}
}

function load_sensor_alignment() {
var next_callback = load_html;
Expand All @@ -69,6 +78,9 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
next_callback();
}
}



//Update Analog/Battery Data
function load_analog() {
MSP.send_message(MSP_codes.MSP_ANALOG, false, false, function () {
Expand Down Expand Up @@ -238,9 +250,12 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
'CW 270° flip'
];



var orientation_gyro_e = $('select.gyroalign');
var orientation_acc_e = $('select.accalign');
var orientation_mag_e = $('select.magalign');


if (semver.lt(CONFIG.apiVersion, "1.15.0")) {
$('.tab-configuration .sensoralignment').hide();
Expand All @@ -255,6 +270,32 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
orientation_mag_e.val(SENSOR_ALIGNMENT.align_mag);
}

// ESC protocols

var escprotocols = [
'PWM',
'ONESHOT125',
'ONESHOT42',
'MULTISHOT'
];

var esc_protocol_e = $('select.escprotocol');

for (var i = 0; i < escprotocols.length; i++) {
esc_protocol_e.append('<option value="' + (i+1) + '">'+ escprotocols[i] + '</option>');
}
esc_protocol_e.val(PID_ADVANCED_CONFIG.fast_pwm_protocol+1);


Copy link
Member

Choose a reason for hiding this comment

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

@KiteAnton: Shouldn't this be gated by a check for version > 2.8.1-RC1? Otherwise it will display options not available to users of older firmware.

$('input[name="unsyncedPWMSwitch"]').prop('checked', PID_ADVANCED_CONFIG.use_unsyncedPwm);
$('input[name="unsyncedpwmfreq"]').val(PID_ADVANCED_CONFIG.motor_pwm_rate);
if (PID_ADVANCED_CONFIG.use_unsyncedPwm) {

$('div.unsyncedpwmfreq').show();
}
else {
$('div.unsyncedpwmfreq').hide();
}

// generate GPS
var gpsProtocols = [
Expand Down Expand Up @@ -433,6 +474,16 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
});

$("input[type='checkbox']").change(function() {
var element = $(this),
name = element.attr('name'),
isChecked = element.is(':checked');
if (name == 'unsyncedPWMSwitch') {
if (isChecked) { $('div.unsyncedpwmfreq').show(); }
else { $('div.unsyncedpwmfreq').hide(); }
}
});

// UI hooks
$('input[type="radio"].feature', features_e).change(function () {
var element = $(this),
Expand Down Expand Up @@ -497,6 +548,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
SENSOR_ALIGNMENT.align_gyro = parseInt(orientation_gyro_e.val());
SENSOR_ALIGNMENT.align_acc = parseInt(orientation_acc_e.val());
SENSOR_ALIGNMENT.align_mag = parseInt(orientation_mag_e.val());

PID_ADVANCED_CONFIG.fast_pwm_protocol = parseInt(esc_protocol_e.val()-1);
PID_ADVANCED_CONFIG.use_unsyncedPwm = ~~$('input[name="unsyncedPWMSwitch"]').is(':checked');
PID_ADVANCED_CONFIG.motor_pwm_rate = parseInt($('input[name="unsyncedpwmfreq"]').val());


function save_serial_config() {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
Expand All @@ -520,13 +576,21 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}

function save_sensor_alignment() {
var next_callback = save_acc_trim;
var next_callback = save_esc_protocol;
if(semver.gte(CONFIG.apiVersion, "1.15.0")) {
MSP.send_message(MSP_codes.MSP_SET_SENSOR_ALIGNMENT, MSP.crunch(MSP_codes.MSP_SET_SENSOR_ALIGNMENT), false, next_callback);
} else {
next_callback();
}
}
function save_esc_protocol() {
var next_callback = save_acc_trim;
if(semver.gte(CONFIG.apiVersion, "1.16.0")) {
MSP.send_message(MSP_codes.MSP_SET_PID_ADVANCED_CONFIG, MSP.crunch(MSP_codes.MSP_SET_PID_ADVANCED_CONFIG), false, next_callback);
} else {
next_callback();
}
}

function save_acc_trim() {
MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch(MSP_codes.MSP_SET_ACC_TRIM), false
Expand Down