1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

OP-1216 fixes as suggested in OPReview-645

This commit is contained in:
Corvus Corax 2014-03-03 18:58:09 +01:00
parent 696baff1e2
commit dbbb8d5e0d
4 changed files with 67 additions and 67 deletions

View File

@ -125,11 +125,13 @@ int32_t ActuatorInitialize()
MixerSettingsConnectCallback(MixerSettingsUpdatedCb); MixerSettingsConnectCallback(MixerSettingsUpdatedCb);
// Listen for ActuatorDesired updates (Primary input to this module) // Listen for ActuatorDesired updates (Primary input to this module)
AccessoryDesiredInitialize();
ActuatorDesiredInitialize(); ActuatorDesiredInitialize();
queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent)); queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent));
ActuatorDesiredConnectQueue(queue); ActuatorDesiredConnectQueue(queue);
// Register AccessoryDesired (Secondary input to this module)
AccessoryDesiredInitialize();
// Primary output of this module // Primary output of this module
ActuatorCommandInitialize(); ActuatorCommandInitialize();

View File

@ -228,7 +228,7 @@ void armHandler(bool newinit)
case ARM_STATE_DISARMING_MANUAL: case ARM_STATE_DISARMING_MANUAL:
// arming switch disarms immediately, // arming switch disarms immediately,
if (manualDisarm && (armSwitch || (timeDifferenceMs(armedDisarmStart, sysTime) > settings.DisarmingSequenceTime))) { if (manualDisarm && (timeDifferenceMs(armedDisarmStart, sysTime) > settings.DisarmingSequenceTime)) {
armState = ARM_STATE_DISARMED; armState = ARM_STATE_DISARMED;
} else if (!manualDisarm) { } else if (!manualDisarm) {
armState = ARM_STATE_ARMED; armState = ARM_STATE_ARMED;

View File

@ -94,12 +94,12 @@ ManualControlCommand *GCSControlGadget::getManualControlCommand()
return dynamic_cast<ManualControlCommand *>(objManager->getObject(QString("ManualControlCommand"))); return dynamic_cast<ManualControlCommand *>(objManager->getObject(QString("ManualControlCommand")));
} }
void GCSControlGadget::manualControlCommandUpdated(UAVObject *obj) void GCSControlGadget::manualControlCommandUpdated(UAVObject *manualControlCommand)
{ {
double roll = obj->getField("Roll")->getDouble(); double roll = manualControlCommand->getField("Roll")->getDouble();
double pitch = obj->getField("Pitch")->getDouble(); double pitch = manualControlCommand->getField("Pitch")->getDouble();
double yaw = obj->getField("Yaw")->getDouble(); double yaw = manualControlCommand->getField("Yaw")->getDouble();
double throttle = obj->getField("Throttle")->getDouble(); double throttle = manualControlCommand->getField("Throttle")->getDouble();
// necessary against having the wrong joystick profile chosen, which shows weird values // necessary against having the wrong joystick profile chosen, which shows weird values
if (throttle > -1.0 && throttle <= 1.0) { if (throttle > -1.0 && throttle <= 1.0) {
@ -140,11 +140,11 @@ void GCSControlGadget::manualControlCommandUpdated(UAVObject *obj)
*/ */
void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double rightX, double rightY) void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double rightX, double rightY)
{ {
ManualControlCommand *obj = getManualControlCommand(); ManualControlCommand *manualControlCommand = getManualControlCommand();
double oldRoll = obj->getField("Roll")->getDouble(); double oldRoll = manualControlCommand->getField("Roll")->getDouble();
double oldPitch = obj->getField("Pitch")->getDouble(); double oldPitch = manualControlCommand->getField("Pitch")->getDouble();
double oldYaw = obj->getField("Yaw")->getDouble(); double oldYaw = manualControlCommand->getField("Yaw")->getDouble();
double oldThrottle = obj->getField("Throttle")->getDouble(); double oldThrottle = manualControlCommand->getField("Throttle")->getDouble();
double newRoll; double newRoll;
double newPitch; double newPitch;
@ -221,20 +221,20 @@ void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double r
if ((newThrottle != oldThrottle) || (newPitch != oldPitch) || (newYaw != oldYaw) || (newRoll != oldRoll)) { if ((newThrottle != oldThrottle) || (newPitch != oldPitch) || (newYaw != oldYaw) || (newRoll != oldRoll)) {
if (buttonRollControl == 0) { if (buttonRollControl == 0) {
obj->getField("Roll")->setDouble(newRoll); manualControlCommand->getField("Roll")->setDouble(newRoll);
} }
if (buttonPitchControl == 0) { if (buttonPitchControl == 0) {
obj->getField("Pitch")->setDouble(newPitch); manualControlCommand->getField("Pitch")->setDouble(newPitch);
} }
if (buttonYawControl == 0) { if (buttonYawControl == 0) {
obj->getField("Yaw")->setDouble(newYaw); manualControlCommand->getField("Yaw")->setDouble(newYaw);
} }
if (buttonThrottleControl == 0) { if (buttonThrottleControl == 0) {
obj->getField("Throttle")->setDouble(newThrottle); manualControlCommand->getField("Throttle")->setDouble(newThrottle);
obj->getField("Thrust")->setDouble(newThrottle); manualControlCommand->getField("Thrust")->setDouble(newThrottle);
} }
obj->getField("Connected")->setValue("True"); manualControlCommand->getField("Connected")->setValue("True");
obj->updated(); manualControlCommand->updated();
} }
} }
@ -293,29 +293,29 @@ void GCSControlGadget::readUDPCommand()
} }
} }
if (!badPack && ((GCSControlGadgetWidget *)m_widget)->getUDPControl()) { if (!badPack && ((GCSControlGadgetWidget *)m_widget)->getUDPControl()) {
ManualControlCommand *obj = getManualControlCommand(); ManualControlCommand *manualControlCommand = getManualControlCommand();
bool update = false; bool update = false;
if (pitch != obj->getField("Pitch")->getDouble()) { if (pitch != manualControlCommand->getField("Pitch")->getDouble()) {
obj->getField("Pitch")->setDouble(constrain(pitch)); manualControlCommand->getField("Pitch")->setDouble(constrain(pitch));
update = true; update = true;
} }
if (yaw != obj->getField("Yaw")->getDouble()) { if (yaw != manualControlCommand->getField("Yaw")->getDouble()) {
obj->getField("Yaw")->setDouble(constrain(yaw)); manualControlCommand->getField("Yaw")->setDouble(constrain(yaw));
update = true; update = true;
} }
if (roll != obj->getField("Roll")->getDouble()) { if (roll != manualControlCommand->getField("Roll")->getDouble()) {
obj->getField("Roll")->setDouble(constrain(roll)); manualControlCommand->getField("Roll")->setDouble(constrain(roll));
update = true; update = true;
} }
if (throttle != obj->getField("Throttle")->getDouble()) { if (throttle != manualControlCommand->getField("Throttle")->getDouble()) {
obj->getField("Throttle")->setDouble(constrain(throttle)); manualControlCommand->getField("Throttle")->setDouble(constrain(throttle));
obj->getField("Thrust")->setDouble(constrain(throttle)); manualControlCommand->getField("Thrust")->setDouble(constrain(throttle));
update = true; update = true;
} }
if (update) { if (update) {
obj->getField("Connected")->setValue("True"); manualControlCommand->getField("Connected")->setValue("True");
obj->updated(); manualControlCommand->updated();
} }
} }
} }
@ -337,9 +337,9 @@ double GCSControlGadget::constrain(double value)
void GCSControlGadget::buttonState(ButtonNumber number, bool pressed) void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
{ {
if ((buttonSettings[number].ActionID > 0) && (buttonSettings[number].FunctionID > 0) && (pressed)) { // this button is configured if ((buttonSettings[number].ActionID > 0) && (buttonSettings[number].FunctionID > 0) && (pressed)) { // this button is configured
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand"))); UAVDataObject *manualControlCommand = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand")));
bool currentCGSControl = ((GCSControlGadgetWidget *)m_widget)->getGCSControl(); bool currentCGSControl = ((GCSControlGadgetWidget *)m_widget)->getGCSControl();
bool currentUDPControl = ((GCSControlGadgetWidget *)m_widget)->getUDPControl(); bool currentUDPControl = ((GCSControlGadgetWidget *)m_widget)->getUDPControl();
@ -348,17 +348,17 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
if (currentCGSControl) { if (currentCGSControl) {
switch (buttonSettings[number].FunctionID) { switch (buttonSettings[number].FunctionID) {
case 1: // Roll case 1: // Roll
obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble() + buttonSettings[number].Amount)); manualControlCommand->getField("Roll")->setValue(bound(manualControlCommand->getField("Roll")->getValue().toDouble() + buttonSettings[number].Amount));
break; break;
case 2: // Pitch case 2: // Pitch
obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble() + buttonSettings[number].Amount)); manualControlCommand->getField("Pitch")->setValue(bound(manualControlCommand->getField("Pitch")->getValue().toDouble() + buttonSettings[number].Amount));
break; break;
case 3: // Yaw case 3: // Yaw
obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble() + buttonSettings[number].Amount)); manualControlCommand->getField("Yaw")->setValue(wrap(manualControlCommand->getField("Yaw")->getValue().toDouble() + buttonSettings[number].Amount));
break; break;
case 4: // Throttle case 4: // Throttle
obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble() + buttonSettings[number].Amount)); manualControlCommand->getField("Throttle")->setValue(bound(manualControlCommand->getField("Throttle")->getValue().toDouble() + buttonSettings[number].Amount));
obj->getField("Thrust")->setValue(bound(obj->getField("Thrust")->getValue().toDouble() + buttonSettings[number].Amount)); manualControlCommand->getField("Thrust")->setValue(bound(manualControlCommand->getField("Thrust")->getValue().toDouble() + buttonSettings[number].Amount));
break; break;
} }
} }
@ -367,17 +367,17 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
if (currentCGSControl) { if (currentCGSControl) {
switch (buttonSettings[number].FunctionID) { switch (buttonSettings[number].FunctionID) {
case 1: // Roll case 1: // Roll
obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble() - buttonSettings[number].Amount)); manualControlCommand->getField("Roll")->setValue(bound(manualControlCommand->getField("Roll")->getValue().toDouble() - buttonSettings[number].Amount));
break; break;
case 2: // Pitch case 2: // Pitch
obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble() - buttonSettings[number].Amount)); manualControlCommand->getField("Pitch")->setValue(bound(manualControlCommand->getField("Pitch")->getValue().toDouble() - buttonSettings[number].Amount));
break; break;
case 3: // Yaw case 3: // Yaw
obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble() - buttonSettings[number].Amount)); manualControlCommand->getField("Yaw")->setValue(wrap(manualControlCommand->getField("Yaw")->getValue().toDouble() - buttonSettings[number].Amount));
break; break;
case 4: // Throttle case 4: // Throttle
obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble() - buttonSettings[number].Amount)); manualControlCommand->getField("Throttle")->setValue(bound(manualControlCommand->getField("Throttle")->getValue().toDouble() - buttonSettings[number].Amount));
obj->getField("Thrust")->setValue(bound(obj->getField("Thrust")->getValue().toDouble() - buttonSettings[number].Amount)); manualControlCommand->getField("Thrust")->setValue(bound(manualControlCommand->getField("Thrust")->getValue().toDouble() - buttonSettings[number].Amount));
break; break;
} }
} }
@ -409,8 +409,8 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
break; break;
} }
obj->getField("Connected")->setValue("True"); manualControlCommand->getField("Connected")->setValue("True");
obj->updated(); manualControlCommand->updated();
} }
// buttonSettings[number].ActionID NIDT // buttonSettings[number].ActionID NIDT
// buttonSettings[number].FunctionID -RPYTAC // buttonSettings[number].FunctionID -RPYTAC

View File

@ -46,10 +46,10 @@ GCSControlGadgetWidget::GCSControlGadgetWidget(QWidget *parent) : QLabel(parent)
m_gcscontrol->setupUi(this); m_gcscontrol->setupUi(this);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand"))); UAVDataObject *manualControlCommand = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand")));
UAVObject::Metadata mdata = obj->getMetadata(); UAVObject::Metadata mdata = manualControlCommand->getMetadata();
m_gcscontrol->checkBoxGcsControl->setChecked(UAVObject::GetFlightAccess(mdata) == UAVObject::ACCESS_READONLY); m_gcscontrol->checkBoxGcsControl->setChecked(UAVObject::GetFlightAccess(mdata) == UAVObject::ACCESS_READONLY);
// Set up the drop down box for the flightmode // Set up the drop down box for the flightmode
@ -73,7 +73,7 @@ GCSControlGadgetWidget::GCSControlGadgetWidget(QWidget *parent) : QLabel(parent)
connect(m_gcscontrol->checkBoxUDPControl, SIGNAL(stateChanged(int)), this, SLOT(toggleUDPControl(int))); // UDP control checkbox connect(m_gcscontrol->checkBoxUDPControl, SIGNAL(stateChanged(int)), this, SLOT(toggleUDPControl(int))); // UDP control checkbox
// Connect object updated event from UAVObject to also update check boxes and dropdown // Connect object updated event from UAVObject to also update check boxes and dropdown
connect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(mccChanged(UAVObject *))); connect(manualControlCommand, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(mccChanged(UAVObject *)));
leftX = 0; leftX = 0;
leftY = 0; leftY = 0;
@ -120,12 +120,12 @@ void GCSControlGadgetWidget::rightStickClicked(double X, double Y)
*/ */
void GCSControlGadgetWidget::toggleControl(int state) void GCSControlGadgetWidget::toggleControl(int state)
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand"))); UAVDataObject *manualControlCommand = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand")));
UAVDataObject *obj2 = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("AccessoryDesired"), 0)); UAVDataObject *accessoryDesired = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("AccessoryDesired"), 0));
UAVObject::Metadata mdata = obj->getMetadata(); UAVObject::Metadata mdata = manualControlCommand->getMetadata();
if (state) { if (state) {
mccInitialData = mdata; mccInitialData = mdata;
@ -140,29 +140,27 @@ void GCSControlGadgetWidget::toggleControl(int state)
toggleUDPControl(false); toggleUDPControl(false);
m_gcscontrol->checkBoxUDPControl->setEnabled(false); m_gcscontrol->checkBoxUDPControl->setEnabled(false);
} }
obj->setMetadata(mdata); manualControlCommand->setMetadata(mdata);
obj2->setMetadata(mdata); accessoryDesired->setMetadata(mdata);
} }
void GCSControlGadgetWidget::toggleArmed(int state) void GCSControlGadgetWidget::toggleArmed(int state)
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("AccessoryDesired"), 0)); UAVDataObject *accessoryDesired = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("AccessoryDesired"), 0));
if (state) { if (state) {
obj->getField("AccessoryVal")->setValue(1); accessoryDesired->getField("AccessoryVal")->setValue(1);
} else { } else {
obj->getField("AccessoryVal")->setValue(-1); accessoryDesired->getField("AccessoryVal")->setValue(-1);
} }
obj->updated(); accessoryDesired->updated();
} }
void GCSControlGadgetWidget::mccChanged(UAVObject *obj) void GCSControlGadgetWidget::mccChanged(UAVObject *manualControlCommand)
{ {
Q_UNUSED(obj); m_gcscontrol->comboBoxFlightMode->setCurrentIndex(manualControlCommand->getField("FlightModeSwitchPosition")->getValue().toInt());
m_gcscontrol->comboBoxFlightMode->setCurrentIndex(obj->getField("FlightModeSwitchPosition")->getValue().toInt());
} }
void GCSControlGadgetWidget::toggleUDPControl(int state) void GCSControlGadgetWidget::toggleUDPControl(int state)
@ -179,12 +177,12 @@ void GCSControlGadgetWidget::toggleUDPControl(int state)
*/ */
void GCSControlGadgetWidget::selectFlightMode(int state) void GCSControlGadgetWidget::selectFlightMode(int state)
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand"))); UAVDataObject *manualControlCommand = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ManualControlCommand")));
obj->getField("FlightModeSwitchPosition")->setValue(state); manualControlCommand->getField("FlightModeSwitchPosition")->setValue(state);
obj->updated(); manualControlCommand->updated();
} }
void GCSControlGadgetWidget::setGCSControl(bool newState) void GCSControlGadgetWidget::setGCSControl(bool newState)