Skip to content

Commit e69a7ad

Browse files
committed
LP-551 Remove BankMode string and use UavObject definitions
1 parent 8932642 commit e69a7ad

2 files changed

Lines changed: 50 additions & 26 deletions

File tree

ground/gcs/src/plugins/config/configoutputwidget.cpp

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#define DEFAULT_MINOUTPUT_RANGE 900
6060
#define DEFAULT_MINOUTPUT_VALUE 1000
6161
#define REVMOTOR_NEUTRAL_TARGET_VALUE 1500
62-
#define REVMOTOR_NEUTRAL_DIFF_VALUE 250
62+
#define REVMOTOR_NEUTRAL_DIFF_VALUE 150
6363

6464
// Servo settings
6565
#define SERVO_MAXOUTPUT_RANGE 2500
@@ -68,6 +68,8 @@
6868
#define SERVO_MINOUTPUT_VALUE 1000
6969
#define SERVO_NEUTRAL_VALUE 1500
7070

71+
#define OUTPUT_WARNING_DISABLED -1
72+
7173
ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(parent)
7274
{
7375
m_ui = new Ui_OutputWidget();
@@ -525,11 +527,14 @@ void ConfigOutputWidget::setChannelLimits(OutputChannelForm *channelForm, Output
525527
case ActuatorSettings::BANKMODE_DSHOT:
526528
// 0 - 2000 UI limits, DShot min value is fixed to zero
527529
if (channelForm->isServoOutput()) {
528-
bank_mode_servo_warning = "DShot";
530+
// Driving a servo using DShot do not make sense: break
531+
bank_mode_servo_warning = ActuatorSettings::BANKMODE_DSHOT;
529532
break;
530533
}
531534
if (channelForm->isReversableMotor()) {
532-
reversable_motor_warning = "DShot";
535+
// Bi-directional DShot not yet supported: apply normal settings
536+
reversable_motor_warning = ActuatorSettings::BANKMODE_DSHOT;
537+
533538
}
534539
channelForm->setLimits(DSHOT_MINTOUTPUT_RANGE, DSHOT_MINTOUTPUT_RANGE, DSHOT_MINTOUTPUT_RANGE, DSHOT_MAXOUTPUT_RANGE);
535540
channelForm->setRange(DSHOT_MINTOUTPUT_RANGE, DSHOT_MAXOUTPUT_RANGE);
@@ -542,8 +547,8 @@ void ConfigOutputWidget::setChannelLimits(OutputChannelForm *channelForm, Output
542547
channelForm->setLimits(DEFAULT_MINOUTPUT_RANGE, PWMSYNC_MAXOUTPUT_RANGE, DEFAULT_MINOUTPUT_RANGE, PWMSYNC_MAXOUTPUT_RANGE);
543548
channelForm->setRange(DEFAULT_MINOUTPUT_VALUE, PWMSYNC_MAXOUTPUT_RANGE);
544549
channelForm->setNeutral(DEFAULT_MINOUTPUT_VALUE);
545-
if (channelForm->isReversableMotor() && (reversable_motor_warning == "")) {
546-
reversable_motor_warning = "PWMSync";
550+
if (channelForm->isReversableMotor() && (reversable_motor_warning == OUTPUT_WARNING_DISABLED)) {
551+
reversable_motor_warning = ActuatorSettings::BANKMODE_PWMSYNC;
547552
}
548553
if (channelForm->isServoOutput()) {
549554
// Servo: Some of them can handle PWMSync, 500 - 1900 UI limits
@@ -554,8 +559,8 @@ void ConfigOutputWidget::setChannelLimits(OutputChannelForm *channelForm, Output
554559
break;
555560
case ActuatorSettings::BANKMODE_PWM:
556561
// PWM motor outputs fall to default
557-
if (channelForm->isReversableMotor() && (reversable_motor_warning == "")) {
558-
reversable_motor_warning = "PWM";
562+
if (channelForm->isReversableMotor() && (reversable_motor_warning == OUTPUT_WARNING_DISABLED)) {
563+
reversable_motor_warning = ActuatorSettings::BANKMODE_PWM;
559564
}
560565
if (channelForm->isServoOutput()) {
561566
// Servo: 500 - 2500 UI limits
@@ -567,31 +572,32 @@ void ConfigOutputWidget::setChannelLimits(OutputChannelForm *channelForm, Output
567572
}
568573
case ActuatorSettings::BANKMODE_ONESHOT125:
569574
if (channelForm->isServoOutput()) {
570-
bank_mode_servo_warning = "OneShot125";
575+
bank_mode_servo_warning = ActuatorSettings::BANKMODE_ONESHOT125;
571576
break;
572577
}
573-
if (channelForm->isReversableMotor() && (reversable_motor_warning == "")) {
574-
reversable_motor_warning = "OneShot125";
578+
if (channelForm->isReversableMotor() && (reversable_motor_warning == OUTPUT_WARNING_DISABLED)) {
579+
reversable_motor_warning = ActuatorSettings::BANKMODE_ONESHOT125;
575580
}
576581
case ActuatorSettings::BANKMODE_ONESHOT42:
577582
if (channelForm->isServoOutput()) {
578-
bank_mode_servo_warning = "OneShot42";
583+
bank_mode_servo_warning = ActuatorSettings::BANKMODE_ONESHOT42;
579584
break;
580585
}
581-
if (channelForm->isReversableMotor() && (reversable_motor_warning == "")) {
582-
reversable_motor_warning = "OneShot42";
586+
if (channelForm->isReversableMotor() && (reversable_motor_warning == OUTPUT_WARNING_DISABLED)) {
587+
reversable_motor_warning = ActuatorSettings::BANKMODE_ONESHOT42;
583588
}
584589
case ActuatorSettings::BANKMODE_MULTISHOT:
585590
if (channelForm->isServoOutput()) {
586-
bank_mode_servo_warning = "MultiShot";
591+
bank_mode_servo_warning = ActuatorSettings::BANKMODE_MULTISHOT;
587592
break;
588593
}
589-
if (channelForm->isReversableMotor() && (reversable_motor_warning == "")) {
590-
reversable_motor_warning = "MultiShot";
594+
if (channelForm->isReversableMotor() && (reversable_motor_warning == OUTPUT_WARNING_DISABLED)) {
595+
reversable_motor_warning = ActuatorSettings::BANKMODE_MULTISHOT;
591596
}
592597
default:
593598
// Motors 900 - 2000 UI limits
594599
// Default values 1000 - 2000, neutral set to min
600+
// This settings are used for PWM, OneShot125, OneShot42 and MultiShot
595601
currentNeutralValue = channelForm->getNeutralValue();
596602
channelForm->setLimits(DEFAULT_MINOUTPUT_RANGE, DEFAULT_MAXOUTPUT_RANGE, DEFAULT_MINOUTPUT_RANGE, DEFAULT_MAXOUTPUT_RANGE);
597603
channelForm->setRange(DEFAULT_MINOUTPUT_VALUE, DEFAULT_MAXOUTPUT_RANGE);
@@ -604,7 +610,7 @@ void ConfigOutputWidget::setChannelLimits(OutputChannelForm *channelForm, Output
604610
int neutralDiff = qAbs(REVMOTOR_NEUTRAL_TARGET_VALUE - currentNeutralValue);
605611
if (neutralDiff < REVMOTOR_NEUTRAL_DIFF_VALUE) {
606612
// Reset warning
607-
reversable_motor_warning = "";
613+
reversable_motor_warning = OUTPUT_WARNING_DISABLED;
608614
}
609615
}
610616
}
@@ -613,8 +619,8 @@ void ConfigOutputWidget::onBankTypeChange()
613619
{
614620
QComboBox *bankModeCombo = qobject_cast<QComboBox *>(sender());
615621

616-
bank_mode_servo_warning = "";
617-
reversable_motor_warning = "";
622+
bank_mode_servo_warning = OUTPUT_WARNING_DISABLED;
623+
reversable_motor_warning = OUTPUT_WARNING_DISABLED;
618624

619625
if (bankModeCombo != NULL) {
620626
int bankNumber = 1;
@@ -658,24 +664,26 @@ void ConfigOutputWidget::updateWarnings(UAVObject *)
658664
}
659665
}
660666

661-
if (reversable_motor_warning != "") {
667+
if (reversable_motor_warning > OUTPUT_WARNING_DISABLED) {
662668
QString revmotor_warning_str;
663-
if (reversable_motor_warning == "DShot") {
669+
if (reversable_motor_warning == ActuatorSettings::BANKMODE_DSHOT) {
664670
// TODO: Implement bi-directional DShot
665671
revmotor_warning_str = "There is at least one reversable motor using <b>DShot</b> in your configuration."
666672
"<p>Bi-directional DShot is not currently supported, you should use PWM, OneShotXXX or MultiShot.</p>";
667673
} else {
668674
revmotor_warning_str = QString("There is at least one reversable motor using <b>%1</b> in your configuration.</b>"
669-
"<p>Be sure you set the appropriate neutral value before saving and applying power to the vehicule.</p>").arg(reversable_motor_warning);
675+
"<p>Be sure you set the appropriate neutral value before saving and applying power to the vehicule.</p>").arg(bankModeName(reversable_motor_warning));
670676
}
671677
setWarning(revmotor_warning_str);
678+
672679
return;
673680
}
674681

675-
if (bank_mode_servo_warning != "") {
682+
if (bank_mode_servo_warning > OUTPUT_WARNING_DISABLED) {
676683
QString servo_warning_str = QString("Bank using <b>%1</b> cannot drive a <b>servo output!</b>"
677-
"<p>You must use PWM for this Bank or move the servo output to another compatible Bank.</p>").arg(bank_mode_servo_warning);
684+
"<p>You must use PWM for this bank or move the servo output to another compatible bank.</p>").arg(bankModeName(bank_mode_servo_warning));
678685
setWarning(servo_warning_str);
686+
679687
return;
680688
}
681689

@@ -689,6 +697,21 @@ void ConfigOutputWidget::setWarning(QString message)
689697
m_ui->txtWarning->setText(message);
690698
}
691699

700+
QString ConfigOutputWidget::bankModeName(int index)
701+
{
702+
UAVDataObject *actuator = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("ActuatorSettings")));
703+
704+
Q_ASSERT(actuator);
705+
UAVObjectField *field = actuator->getField("BankMode");
706+
Q_ASSERT(field);
707+
QStringList bankModeOptions;
708+
709+
if (field) {
710+
bankModeOptions = field->getOptions();
711+
}
712+
713+
return bankModeOptions.at(index);
714+
}
692715

693716
OutputBankControls::OutputBankControls(MixerSettings *mixer, QLabel *label, QColor color, QComboBox *rateCombo, QComboBox *modeCombo) :
694717
m_mixer(mixer), m_label(label), m_color(color), m_rateCombo(rateCombo), m_modeCombo(modeCombo)

ground/gcs/src/plugins/config/configoutputwidget.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class ConfigOutputWidget : public ConfigTaskWidget {
9898
int m_mccDataRate;
9999
UAVObject::Metadata m_accInitialData;
100100
QList<OutputBankControls> m_banks;
101-
QString bank_mode_servo_warning;
102-
QString reversable_motor_warning;
101+
int bank_mode_servo_warning;
102+
int reversable_motor_warning;
103103
int currentNeutralValue;
104104

105105
OutputChannelForm *getOutputChannelForm(const int index) const;
@@ -108,6 +108,7 @@ class ConfigOutputWidget : public ConfigTaskWidget {
108108
void setColor(QWidget *widget, const QColor color);
109109
void sendAllChannelTests();
110110
void setChannelLimits(OutputChannelForm *channelForm, OutputBankControls *bankControls);
111+
QString bankModeName(int index);
111112

112113
private slots:
113114
void updateWarnings(UAVObject *);

0 commit comments

Comments
 (0)