mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
OP-39 Re-factored the configuration code to be implemented in a separate helper class to enable it to be used in a better and more stand alone way. The actual wizard class does not contain any uavo configuration code at all now.
Added an interface that provides all configuration parameters for a vehicle. Changed the default ESC to Rapid instead of Default 50Hz. Default ESC was renamed to Legacy ESC. Started to implement mixer configuration. Started to implement flight mode configuration code. Cleaned up some code and removed warnings.
This commit is contained in:
parent
16d0252d12
commit
98b5bc305b
@ -33,16 +33,7 @@
|
||||
#include <QMutex>
|
||||
|
||||
#include "uavobject.h"
|
||||
|
||||
struct accelGyroBias {
|
||||
float m_accelerometerXBias;
|
||||
float m_accelerometerYBias;
|
||||
float m_accelerometerZBias;
|
||||
|
||||
float m_gyroXBias;
|
||||
float m_gyroYBias;
|
||||
float m_gyroZBias;
|
||||
};
|
||||
#include "vehicleconfigurationsource.h"
|
||||
|
||||
class LevellingUtil : public QObject
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ bool OutputPage::validatePage()
|
||||
getWizard()->setESCType(SetupWizard::ESC_RAPID);
|
||||
}
|
||||
else {
|
||||
getWizard()->setESCType(SetupWizard::ESC_DEFAULT);
|
||||
getWizard()->setESCType(SetupWizard::ESC_LEGACY);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -64,7 +64,7 @@ p, li { white-space: pre-wrap; }
|
||||
<widget class="QPushButton" name="defaultESCButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<x>160</x>
|
||||
<y>40</y>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
@ -74,14 +74,14 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Tricopter, Quadcopter, Hexacopter, Octocopter</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Default ESC
|
||||
<string>Legacy ESC
|
||||
50 Hz</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>true</bool>
|
||||
@ -93,7 +93,7 @@ p, li { white-space: pre-wrap; }
|
||||
<widget class="QPushButton" name="rapidESCButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<x>30</x>
|
||||
<y>40</y>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
@ -109,6 +109,9 @@ p, li { white-space: pre-wrap; }
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -41,11 +41,9 @@
|
||||
#include "pages/flashpage.h"
|
||||
#include "pages/notyetimplementedpage.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "hwsettings.h"
|
||||
#include "actuatorsettings.h"
|
||||
#include "attitudesettings.h"
|
||||
#include "vehicleconfigurationhelper.h"
|
||||
|
||||
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent),
|
||||
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), VehicleConfigurationSource(),
|
||||
m_controllerSelectionMode(CONTROLLER_SELECTION_UNKNOWN), m_controllerType(CONTROLLER_UNKNOWN),
|
||||
m_vehicleType(VEHICLE_UNKNOWN), m_inputType(INPUT_UNKNOWN), m_escType(ESC_UNKNOWN),
|
||||
m_levellingPerformed(false), m_connectionManager(0)
|
||||
@ -179,8 +177,8 @@ QString SetupWizard::getSummaryText()
|
||||
summary.append(tr("ESC type: "));
|
||||
switch (getESCType())
|
||||
{
|
||||
case ESC_DEFAULT:
|
||||
summary.append(tr("Default ESC (50 Hz)"));
|
||||
case ESC_LEGACY:
|
||||
summary.append(tr("Legacy ESC (50 Hz)"));
|
||||
break;
|
||||
case ESC_RAPID:
|
||||
summary.append(tr("Rapid ESC (400 Hz)"));
|
||||
@ -201,239 +199,11 @@ QString SetupWizard::getSummaryText()
|
||||
return summary;
|
||||
}
|
||||
|
||||
void SetupWizard::applyConfiguration()
|
||||
{
|
||||
UAVObjectManager* uavoMgr = getUAVObjectManager();
|
||||
applyHardwareConfiguration(uavoMgr);
|
||||
applyVehicleConfiguration(uavoMgr);
|
||||
applyOutputConfiguration(uavoMgr);
|
||||
applyLevellingConfiguration(uavoMgr);
|
||||
}
|
||||
|
||||
UAVObjectManager* SetupWizard::getUAVObjectManager()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager * uavObjectManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(uavObjectManager);
|
||||
return uavObjectManager;
|
||||
}
|
||||
|
||||
void SetupWizard::applyHardwareConfiguration(UAVObjectManager* uavoMgr)
|
||||
{
|
||||
HwSettings* hwSettings = HwSettings::GetInstance(uavoMgr);
|
||||
HwSettings::DataFields data = hwSettings->getData();
|
||||
switch(getControllerType())
|
||||
{
|
||||
case CONTROLLER_CC:
|
||||
case CONTROLLER_CC3D:
|
||||
// Reset all ports
|
||||
data.CC_RcvrPort = HwSettings::CC_RCVRPORT_DISABLED;
|
||||
data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DISABLED;
|
||||
data.CC_MainPort = HwSettings::CC_MAINPORT_DISABLED;
|
||||
switch(getInputType())
|
||||
{
|
||||
case INPUT_PWM:
|
||||
data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PWM;
|
||||
break;
|
||||
case INPUT_PPM:
|
||||
data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPM;
|
||||
break;
|
||||
case INPUT_SBUS:
|
||||
data.CC_MainPort = HwSettings::CC_MAINPORT_SBUS;
|
||||
break;
|
||||
case INPUT_DSM:
|
||||
// TODO: Handle all of the DSM types ?? Which is most common?
|
||||
data.CC_MainPort = HwSettings::CC_MAINPORT_DSM2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CONTROLLER_REVO:
|
||||
// TODO: Implement Revo settings
|
||||
break;
|
||||
}
|
||||
hwSettings->setData(data);
|
||||
}
|
||||
|
||||
void SetupWizard::applyVehicleConfiguration(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
|
||||
switch(getVehicleType())
|
||||
{
|
||||
case VEHICLE_MULTI:
|
||||
{
|
||||
resetVehicleConfig(uavoMgr);
|
||||
|
||||
switch(getVehicleSubType())
|
||||
{
|
||||
case SetupWizard::MULTI_ROTOR_TRI_Y:
|
||||
setupTriCopter(uavoMgr);
|
||||
break;
|
||||
case SetupWizard::MULTI_ROTOR_QUAD_X:
|
||||
case SetupWizard::MULTI_ROTOR_QUAD_PLUS:
|
||||
setupQuadCopter(uavoMgr);
|
||||
break;
|
||||
case SetupWizard::MULTI_ROTOR_HEXA:
|
||||
case SetupWizard::MULTI_ROTOR_HEXA_COAX_Y:
|
||||
case SetupWizard::MULTI_ROTOR_HEXA_H:
|
||||
setupHexaCopter(uavoMgr);
|
||||
break;
|
||||
case SetupWizard::MULTI_ROTOR_OCTO:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO_COAX_X:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO_COAX_PLUS:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO_V:
|
||||
setupOctoCopter(uavoMgr);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VEHICLE_FIXEDWING:
|
||||
case VEHICLE_HELI:
|
||||
case VEHICLE_SURFACE:
|
||||
// TODO: Implement settings for other vehicle types?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetupWizard::applyOutputConfiguration(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
ActuatorSettings* actSettings = ActuatorSettings::GetInstance(uavoMgr);
|
||||
switch(getVehicleType())
|
||||
{
|
||||
case VEHICLE_MULTI:
|
||||
{
|
||||
ActuatorSettings::DataFields data = actSettings->getData();
|
||||
|
||||
data.ChannelUpdateFreq[0] = DEFAULT_ESC_FREQUENCE;
|
||||
data.ChannelUpdateFreq[1] = DEFAULT_ESC_FREQUENCE;
|
||||
data.ChannelUpdateFreq[3] = DEFAULT_ESC_FREQUENCE;
|
||||
data.ChannelUpdateFreq[4] = DEFAULT_ESC_FREQUENCE;
|
||||
|
||||
qint16 updateFrequence = DEFAULT_ESC_FREQUENCE;
|
||||
switch(getESCType())
|
||||
{
|
||||
case ESC_DEFAULT:
|
||||
updateFrequence = DEFAULT_ESC_FREQUENCE;
|
||||
break;
|
||||
case ESC_RAPID:
|
||||
updateFrequence = RAPID_ESC_FREQUENCE;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(getVehicleSubType())
|
||||
{
|
||||
case SetupWizard::MULTI_ROTOR_TRI_Y:
|
||||
data.ChannelUpdateFreq[0] = updateFrequence;
|
||||
break;
|
||||
case SetupWizard::MULTI_ROTOR_QUAD_X:
|
||||
case SetupWizard::MULTI_ROTOR_QUAD_PLUS:
|
||||
data.ChannelUpdateFreq[0] = updateFrequence;
|
||||
data.ChannelUpdateFreq[1] = updateFrequence;
|
||||
break;
|
||||
case SetupWizard::MULTI_ROTOR_HEXA:
|
||||
case SetupWizard::MULTI_ROTOR_HEXA_COAX_Y:
|
||||
case SetupWizard::MULTI_ROTOR_HEXA_H:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO_COAX_X:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO_COAX_PLUS:
|
||||
case SetupWizard::MULTI_ROTOR_OCTO_V:
|
||||
data.ChannelUpdateFreq[0] = updateFrequence;
|
||||
data.ChannelUpdateFreq[1] = updateFrequence;
|
||||
data.ChannelUpdateFreq[3] = updateFrequence;
|
||||
data.ChannelUpdateFreq[4] = updateFrequence;
|
||||
break;
|
||||
}
|
||||
actSettings->setData(data);
|
||||
break;
|
||||
}
|
||||
case VEHICLE_FIXEDWING:
|
||||
case VEHICLE_HELI:
|
||||
case VEHICLE_SURFACE:
|
||||
// TODO: Implement settings for other vehicle types?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetupWizard::applyLevellingConfiguration(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
if(isLevellingPerformed())
|
||||
{
|
||||
accelGyroBias bias = getLevellingBias();
|
||||
AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(uavoMgr)->getData();
|
||||
attitudeSettingsData.AccelBias[0] += bias.m_accelerometerXBias;
|
||||
attitudeSettingsData.AccelBias[1] += bias.m_accelerometerYBias;
|
||||
attitudeSettingsData.AccelBias[2] += bias.m_accelerometerZBias;
|
||||
attitudeSettingsData.GyroBias[0] = -bias.m_gyroXBias;
|
||||
attitudeSettingsData.GyroBias[1] = -bias.m_gyroYBias;
|
||||
attitudeSettingsData.GyroBias[2] = -bias.m_gyroZBias;
|
||||
AttitudeSettings::GetInstance(uavoMgr)->setData(attitudeSettingsData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SetupWizard::resetVehicleConfig(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
// Reset all mixers
|
||||
MixerSettings* mSettings = MixerSettings::GetInstance(uavoMgr);
|
||||
|
||||
QString mixerTypePattern = "Mixer%1Type";
|
||||
QString mixerVectorPattern = "Mixer%1Vector";
|
||||
for(int i = 1; i <= 10; i++) {
|
||||
UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i));
|
||||
Q_ASSERT(field);
|
||||
field->setValue(field->getOptions().at(0));
|
||||
|
||||
field = mSettings->getField(mixerVectorPattern.arg(i));
|
||||
Q_ASSERT(field);
|
||||
for(int i = 0; i < field->getNumElements(); i++){
|
||||
field->setValue(0, i);
|
||||
}
|
||||
}
|
||||
mSettings->setData(mSettings->getData());
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SetupWizard::setupTriCopter(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
// Typical vehicle setup
|
||||
// 1. Setup and apply mixer
|
||||
// 2. Setup GUI data
|
||||
|
||||
double mixer [8][3] = {
|
||||
{ 0.5, 1, 0},
|
||||
{ 0.5, -1, 0},
|
||||
{ -1, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void SetupWizard::setupQuadCopter(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
}
|
||||
|
||||
void SetupWizard::setupHexaCopter(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
}
|
||||
|
||||
void SetupWizard::setupOctoCopter(UAVObjectManager *uavoMgr)
|
||||
{
|
||||
}
|
||||
|
||||
void SetupWizard::exportConfiguration()
|
||||
{
|
||||
applyConfiguration();
|
||||
// Call export configuration function...
|
||||
}
|
||||
|
||||
void SetupWizard::writeConfiguration()
|
||||
{
|
||||
applyConfiguration();
|
||||
// Call Save UAVOs to controller
|
||||
VehicleConfigurationHelper *helper = new VehicleConfigurationHelper(this);
|
||||
Q_ASSERT(helper);
|
||||
helper->setupVehicle();
|
||||
}
|
||||
|
||||
void SetupWizard::createPages()
|
||||
|
@ -32,26 +32,16 @@
|
||||
#include "levellingutil.h"
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/connectionmanager.h>
|
||||
#include "uavobjectmanager.h"
|
||||
#include "mixersettings.h"
|
||||
#include "vehicleconfigurationsource.h"
|
||||
|
||||
|
||||
class SetupWizard : public QWizard
|
||||
class SetupWizard : public QWizard, public VehicleConfigurationSource
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SetupWizard(QWidget *parent = 0);
|
||||
int nextId() const;
|
||||
enum CONTROLLER_SELECTION_MODE {CONTROLLER_SELECTION_AUTOMATIC, CONTROLLER_SELECTION_MANUAL, CONTROLLER_SELECTION_UNKNOWN};
|
||||
enum CONTROLLER_TYPE {CONTROLLER_UNKNOWN, CONTROLLER_CC, CONTROLLER_CC3D, CONTROLLER_REVO, CONTROLLER_PIPX};
|
||||
enum VEHICLE_TYPE {VEHICLE_UNKNOWN, VEHICLE_MULTI, VEHICLE_FIXEDWING, VEHICLE_HELI, VEHICLE_SURFACE};
|
||||
enum VEHICLE_SUB_TYPE {MULTI_ROTOR_UNKNOWN, MULTI_ROTOR_TRI_Y, MULTI_ROTOR_QUAD_X, MULTI_ROTOR_QUAD_PLUS,
|
||||
MULTI_ROTOR_HEXA, MULTI_ROTOR_HEXA_H, MULTI_ROTOR_HEXA_COAX_Y, MULTI_ROTOR_OCTO,
|
||||
MULTI_ROTOR_OCTO_V, MULTI_ROTOR_OCTO_COAX_X, MULTI_ROTOR_OCTO_COAX_PLUS, FIXED_WING_AILERON,
|
||||
FIXED_WING_VTAIL, HELI_CCPM};
|
||||
enum ESC_TYPE {ESC_DEFAULT, ESC_RAPID, ESC_UNKNOWN};
|
||||
enum INPUT_TYPE {INPUT_PWM, INPUT_PPM, INPUT_SBUS, INPUT_DSM, INPUT_UNKNOWN};
|
||||
|
||||
void setControllerSelectionMode(SetupWizard::CONTROLLER_SELECTION_MODE mode) { m_controllerSelectionMode = mode; }
|
||||
SetupWizard::CONTROLLER_SELECTION_MODE getControllerSelectionMode() const { return m_controllerSelectionMode; }
|
||||
@ -86,13 +76,9 @@ public:
|
||||
return m_connectionManager;
|
||||
}
|
||||
public slots:
|
||||
void exportConfiguration();
|
||||
void writeConfiguration();
|
||||
|
||||
private:
|
||||
static const qint16 DEFAULT_ESC_FREQUENCE = 50;
|
||||
static const qint16 RAPID_ESC_FREQUENCE = 400;
|
||||
|
||||
enum {PAGE_START, PAGE_CONTROLLER, PAGE_VEHICLES, PAGE_MULTI, PAGE_FIXEDWING,
|
||||
PAGE_HELI, PAGE_SURFACE, PAGE_INPUT, PAGE_OUTPUT, PAGE_LEVELLING,
|
||||
PAGE_FLASH, PAGE_SUMMARY, PAGE_NOTYETIMPLEMENTED, PAGE_END};
|
||||
@ -108,22 +94,6 @@ private:
|
||||
accelGyroBias m_levellingBias;
|
||||
|
||||
Core::ConnectionManager *m_connectionManager;
|
||||
|
||||
UAVObjectManager *getUAVObjectManager();
|
||||
|
||||
void applyConfiguration();
|
||||
void applyHardwareConfiguration(UAVObjectManager *uavoMgr);
|
||||
void applyVehicleConfiguration(UAVObjectManager *uavoMgr);
|
||||
void applyOutputConfiguration(UAVObjectManager *uavoMgr);
|
||||
void applyLevellingConfiguration(UAVObjectManager *uavoMgr);
|
||||
|
||||
void resetVehicleConfig(UAVObjectManager *uavoMgr);
|
||||
void resetMixerVectors(MixerSettings::DataFields data, qint8 channelIndex);
|
||||
|
||||
void setupTriCopter(UAVObjectManager *uavoMgr);
|
||||
void setupQuadCopter(UAVObjectManager *uavoMgr);
|
||||
void setupHexaCopter(UAVObjectManager *uavoMgr);
|
||||
void setupOctoCopter(UAVObjectManager *uavoMgr);
|
||||
};
|
||||
|
||||
#endif // SETUPWIZARD_H
|
||||
|
@ -25,7 +25,9 @@ HEADERS += setupwizardplugin.h \
|
||||
pages/summarypage.h \
|
||||
pages/flashpage.h \
|
||||
pages/levellingpage.h \
|
||||
levellingutil.h
|
||||
levellingutil.h \
|
||||
vehicleconfigurationsource.h \
|
||||
vehicleconfigurationhelper.h
|
||||
|
||||
SOURCES += setupwizardplugin.cpp \
|
||||
setupwizard.cpp \
|
||||
@ -44,7 +46,9 @@ SOURCES += setupwizardplugin.cpp \
|
||||
pages/summarypage.cpp \
|
||||
pages/flashpage.cpp \
|
||||
pages/levellingpage.cpp \
|
||||
levellingutil.cpp
|
||||
levellingutil.cpp \
|
||||
vehicleconfigurationsource.cpp \
|
||||
vehicleconfigurationhelper.cpp
|
||||
|
||||
OTHER_FILES += SetupWizard.pluginspec
|
||||
|
||||
|
@ -0,0 +1,298 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file vehicleconfigurationhelper.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup VehicleConfigurationHelper
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "vehicleconfigurationhelper.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "hwsettings.h"
|
||||
#include "actuatorsettings.h"
|
||||
#include "attitudesettings.h"
|
||||
#include "mixersettings.h"
|
||||
#include "systemsettings.h"
|
||||
|
||||
VehicleConfigurationHelper::VehicleConfigurationHelper(VehicleConfigurationSource *configSource)
|
||||
: m_configSource(configSource), m_uavoManager(0)
|
||||
{
|
||||
Q_ASSERT(m_configSource);
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
m_uavoManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(m_uavoManager);
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::setupVehicle()
|
||||
{
|
||||
applyHardwareConfiguration();
|
||||
applyVehicleConfiguration();
|
||||
applyOutputConfiguration();
|
||||
applyFlighModeConfiguration();
|
||||
applyLevellingConfiguration();
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::applyHardwareConfiguration()
|
||||
{
|
||||
HwSettings* hwSettings = HwSettings::GetInstance(m_uavoManager);
|
||||
HwSettings::DataFields data = hwSettings->getData();
|
||||
switch(m_configSource->getControllerType())
|
||||
{
|
||||
case VehicleConfigurationSource::CONTROLLER_CC:
|
||||
case VehicleConfigurationSource::CONTROLLER_CC3D:
|
||||
// Reset all ports
|
||||
data.CC_RcvrPort = HwSettings::CC_RCVRPORT_DISABLED;
|
||||
data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DISABLED;
|
||||
data.CC_MainPort = HwSettings::CC_MAINPORT_DISABLED;
|
||||
switch(m_configSource->getInputType())
|
||||
{
|
||||
case VehicleConfigurationSource::INPUT_PWM:
|
||||
data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PWM;
|
||||
break;
|
||||
case VehicleConfigurationSource::INPUT_PPM:
|
||||
data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPM;
|
||||
break;
|
||||
case VehicleConfigurationSource::INPUT_SBUS:
|
||||
data.CC_MainPort = HwSettings::CC_MAINPORT_SBUS;
|
||||
break;
|
||||
case VehicleConfigurationSource::INPUT_DSM:
|
||||
// TODO: Handle all of the DSM types ?? Which is most common?
|
||||
data.CC_MainPort = HwSettings::CC_MAINPORT_DSM2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VehicleConfigurationSource::CONTROLLER_REVO:
|
||||
// TODO: Implement Revo settings
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
hwSettings->setData(data);
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::applyVehicleConfiguration()
|
||||
{
|
||||
|
||||
switch(m_configSource->getVehicleType())
|
||||
{
|
||||
case VehicleConfigurationSource::VEHICLE_MULTI:
|
||||
{
|
||||
resetGUIData();
|
||||
resetVehicleConfig();
|
||||
|
||||
switch(m_configSource->getVehicleSubType())
|
||||
{
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
|
||||
setupTriCopter();
|
||||
break;
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
|
||||
setupQuadCopter();
|
||||
break;
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
|
||||
setupHexaCopter();
|
||||
break;
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
|
||||
setupOctoCopter();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VehicleConfigurationSource::VEHICLE_FIXEDWING:
|
||||
case VehicleConfigurationSource::VEHICLE_HELI:
|
||||
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
||||
// TODO: Implement settings for other vehicle types?
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::applyOutputConfiguration()
|
||||
{
|
||||
ActuatorSettings* actSettings = ActuatorSettings::GetInstance(m_uavoManager);
|
||||
switch(m_configSource->getVehicleType())
|
||||
{
|
||||
case VehicleConfigurationSource::VEHICLE_MULTI:
|
||||
{
|
||||
ActuatorSettings::DataFields data = actSettings->getData();
|
||||
|
||||
data.ChannelUpdateFreq[0] = LEGACY_ESC_FREQUENCE;
|
||||
data.ChannelUpdateFreq[1] = LEGACY_ESC_FREQUENCE;
|
||||
data.ChannelUpdateFreq[3] = LEGACY_ESC_FREQUENCE;
|
||||
data.ChannelUpdateFreq[4] = LEGACY_ESC_FREQUENCE;
|
||||
|
||||
qint16 updateFrequence = LEGACY_ESC_FREQUENCE;
|
||||
switch(m_configSource->getESCType())
|
||||
{
|
||||
case VehicleConfigurationSource::ESC_LEGACY:
|
||||
updateFrequence = LEGACY_ESC_FREQUENCE;
|
||||
break;
|
||||
case VehicleConfigurationSource::ESC_RAPID:
|
||||
updateFrequence = RAPID_ESC_FREQUENCE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch(m_configSource->getVehicleSubType())
|
||||
{
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
|
||||
data.ChannelUpdateFreq[0] = updateFrequence;
|
||||
break;
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
|
||||
data.ChannelUpdateFreq[0] = updateFrequence;
|
||||
data.ChannelUpdateFreq[1] = updateFrequence;
|
||||
break;
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
|
||||
case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
|
||||
data.ChannelUpdateFreq[0] = updateFrequence;
|
||||
data.ChannelUpdateFreq[1] = updateFrequence;
|
||||
data.ChannelUpdateFreq[3] = updateFrequence;
|
||||
data.ChannelUpdateFreq[4] = updateFrequence;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
actSettings->setData(data);
|
||||
break;
|
||||
}
|
||||
case VehicleConfigurationSource::VEHICLE_FIXEDWING:
|
||||
case VehicleConfigurationSource::VEHICLE_HELI:
|
||||
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
||||
// TODO: Implement settings for other vehicle types?
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::applyFlighModeConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::applyLevellingConfiguration()
|
||||
{
|
||||
if(m_configSource->isLevellingPerformed())
|
||||
{
|
||||
accelGyroBias bias = m_configSource->getLevellingBias();
|
||||
AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(m_uavoManager)->getData();
|
||||
attitudeSettingsData.AccelBias[0] += bias.m_accelerometerXBias;
|
||||
attitudeSettingsData.AccelBias[1] += bias.m_accelerometerYBias;
|
||||
attitudeSettingsData.AccelBias[2] += bias.m_accelerometerZBias;
|
||||
attitudeSettingsData.GyroBias[0] = -bias.m_gyroXBias;
|
||||
attitudeSettingsData.GyroBias[1] = -bias.m_gyroYBias;
|
||||
attitudeSettingsData.GyroBias[2] = -bias.m_gyroZBias;
|
||||
AttitudeSettings::GetInstance(m_uavoManager)->setData(attitudeSettingsData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VehicleConfigurationHelper::resetVehicleConfig()
|
||||
{
|
||||
// Reset all vehicle data
|
||||
MixerSettings* mSettings = MixerSettings::GetInstance(m_uavoManager);
|
||||
|
||||
// Reset feed forward, accel times etc
|
||||
mSettings->setFeedForward(0.0f);
|
||||
mSettings->setMaxAccel(1000.0f);
|
||||
mSettings->setAccelTime(0.0f);
|
||||
mSettings->setDecelTime(0.0f);
|
||||
|
||||
// Reset throttle curves
|
||||
QString throttlePattern = "ThrottleCurve%1";
|
||||
for(int i = 1; i <= 2; i++) {
|
||||
UAVObjectField *field = mSettings->getField(throttlePattern.arg(i));
|
||||
Q_ASSERT(field);
|
||||
for(int i = 0; i < field->getNumElements(); i++){
|
||||
field->setValue(i * ( 1.0f / field->getNumElements()), i);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset Mixer types and values
|
||||
QString mixerTypePattern = "Mixer%1Type";
|
||||
QString mixerVectorPattern = "Mixer%1Vector";
|
||||
for(int i = 1; i <= 10; i++) {
|
||||
UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i));
|
||||
Q_ASSERT(field);
|
||||
field->setValue(field->getOptions().at(0));
|
||||
|
||||
field = mSettings->getField(mixerVectorPattern.arg(i));
|
||||
Q_ASSERT(field);
|
||||
for(int i = 0; i < field->getNumElements(); i++){
|
||||
field->setValue(0, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply updates
|
||||
mSettings->setData(mSettings->getData());
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::resetGUIData()
|
||||
{
|
||||
SystemSettings * sSettings = SystemSettings::GetInstance(m_uavoManager);
|
||||
Q_ASSERT(sSettings);
|
||||
SystemSettings::DataFields data = sSettings->getData();
|
||||
data.AirframeType = SystemSettings::AIRFRAMETYPE_CUSTOM;
|
||||
for(int i = 0; i < SystemSettings::GUICONFIGDATA_NUMELEM; i++)
|
||||
{
|
||||
data.GUIConfigData[i] = 0;
|
||||
}
|
||||
sSettings->setData(data);
|
||||
}
|
||||
|
||||
|
||||
void VehicleConfigurationHelper::setupTriCopter()
|
||||
{
|
||||
// Typical vehicle setup
|
||||
// 1. Setup and apply mixer
|
||||
// 2. Setup GUI data
|
||||
mixerSettings mixer;
|
||||
mixer.channels[0].type = 0;
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::setupQuadCopter()
|
||||
{
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::setupHexaCopter()
|
||||
{
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::setupOctoCopter()
|
||||
{
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file vehicleconfigurationhelper.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup VehicleConfigurationHelper
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef VEHICLECONFIGURATIONHELPER_H
|
||||
#define VEHICLECONFIGURATIONHELPER_H
|
||||
|
||||
#include "vehicleconfigurationsource.h"
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
struct channelSettings {
|
||||
int type;
|
||||
int throttle1;
|
||||
int throttle2;
|
||||
int roll;
|
||||
int pitch;
|
||||
int yaw;
|
||||
|
||||
channelSettings() : type(), throttle1(), throttle2(), roll(), pitch(), yaw() {}
|
||||
|
||||
channelSettings(int t, int th1, int th2, int r, int p, int y)
|
||||
: type(t), throttle1(th1), throttle2(th2), roll(r), pitch(p), yaw(y) {}
|
||||
};
|
||||
|
||||
struct mixerSettings {
|
||||
channelSettings channels[10];
|
||||
};
|
||||
|
||||
class VehicleConfigurationHelper
|
||||
{
|
||||
public:
|
||||
VehicleConfigurationHelper(VehicleConfigurationSource* configSource);
|
||||
void setupVehicle();
|
||||
private:
|
||||
static const qint16 LEGACY_ESC_FREQUENCE = 50;
|
||||
static const qint16 RAPID_ESC_FREQUENCE = 400;
|
||||
|
||||
VehicleConfigurationSource *m_configSource;
|
||||
UAVObjectManager *m_uavoManager;
|
||||
|
||||
void applyHardwareConfiguration();
|
||||
void applyVehicleConfiguration();
|
||||
void applyOutputConfiguration();
|
||||
void applyFlighModeConfiguration();
|
||||
void applyLevellingConfiguration();
|
||||
|
||||
void resetVehicleConfig();
|
||||
void resetGUIData();
|
||||
|
||||
void setupTriCopter();
|
||||
void setupQuadCopter();
|
||||
void setupHexaCopter();
|
||||
void setupOctoCopter();
|
||||
|
||||
};
|
||||
|
||||
#endif // VEHICLECONFIGURATIONHELPER_H
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file vehicleconfigurationsource.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup VehicleConfigurationSource
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "vehicleconfigurationsource.h"
|
||||
|
||||
VehicleConfigurationSource::VehicleConfigurationSource()
|
||||
{
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file vehicleconfigurationsource.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup VehicleConfigurationSource
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef VEHICLECONFIGURATIONSOURCE_H
|
||||
#define VEHICLECONFIGURATIONSOURCE_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct accelGyroBias {
|
||||
float m_accelerometerXBias;
|
||||
float m_accelerometerYBias;
|
||||
float m_accelerometerZBias;
|
||||
|
||||
float m_gyroXBias;
|
||||
float m_gyroYBias;
|
||||
float m_gyroZBias;
|
||||
};
|
||||
|
||||
class VehicleConfigurationSource
|
||||
{
|
||||
public:
|
||||
VehicleConfigurationSource();
|
||||
|
||||
enum CONTROLLER_SELECTION_MODE {CONTROLLER_SELECTION_AUTOMATIC, CONTROLLER_SELECTION_MANUAL, CONTROLLER_SELECTION_UNKNOWN};
|
||||
enum CONTROLLER_TYPE {CONTROLLER_UNKNOWN, CONTROLLER_CC, CONTROLLER_CC3D, CONTROLLER_REVO, CONTROLLER_PIPX};
|
||||
enum VEHICLE_TYPE {VEHICLE_UNKNOWN, VEHICLE_MULTI, VEHICLE_FIXEDWING, VEHICLE_HELI, VEHICLE_SURFACE};
|
||||
enum VEHICLE_SUB_TYPE {MULTI_ROTOR_UNKNOWN, MULTI_ROTOR_TRI_Y, MULTI_ROTOR_QUAD_X, MULTI_ROTOR_QUAD_PLUS,
|
||||
MULTI_ROTOR_HEXA, MULTI_ROTOR_HEXA_H, MULTI_ROTOR_HEXA_COAX_Y, MULTI_ROTOR_OCTO,
|
||||
MULTI_ROTOR_OCTO_V, MULTI_ROTOR_OCTO_COAX_X, MULTI_ROTOR_OCTO_COAX_PLUS, FIXED_WING_AILERON,
|
||||
FIXED_WING_VTAIL, HELI_CCPM};
|
||||
enum ESC_TYPE {ESC_RAPID, ESC_LEGACY, ESC_UNKNOWN};
|
||||
enum INPUT_TYPE {INPUT_PWM, INPUT_PPM, INPUT_SBUS, INPUT_DSM, INPUT_UNKNOWN};
|
||||
|
||||
virtual VehicleConfigurationSource::CONTROLLER_SELECTION_MODE getControllerSelectionMode() const = 0;
|
||||
virtual VehicleConfigurationSource::CONTROLLER_TYPE getControllerType() const = 0;
|
||||
virtual VehicleConfigurationSource::VEHICLE_TYPE getVehicleType() const = 0;
|
||||
virtual VehicleConfigurationSource::VEHICLE_SUB_TYPE getVehicleSubType() const = 0;
|
||||
virtual VehicleConfigurationSource::INPUT_TYPE getInputType() const = 0;
|
||||
virtual VehicleConfigurationSource::ESC_TYPE getESCType() const = 0;
|
||||
|
||||
virtual bool isLevellingPerformed() = 0;
|
||||
virtual accelGyroBias getLevellingBias() const = 0;
|
||||
|
||||
virtual QString getSummaryText() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // VEHICLECONFIGURATIONSOURCE_H
|
Loading…
x
Reference in New Issue
Block a user