31 #include "sdlgamepad/sdlgamepad.h"
34 #define CHANNEL_MAX 9000
35 #define CHANNEL_NEUTRAL 5000
36 #define CHANNEL_THROTNEUTRAL 1800
37 #define CHANNEL_MIN 1000
39 bool GCSControl::firstInstance =
true;
41 GCSControl::GCSControl()
44 Q_ASSERT(firstInstance);
45 firstInstance =
false;
46 receiverActivity.setInterval(100);
47 connect(&receiverActivity, &QTimer::timeout,
this, &GCSControl::receiverActivitySlot);
50 void GCSControl::extensionsInitialized()
56 manControlSettingsUAVO = ManualControlSettings::GetInstance(objMngr);
57 Q_ASSERT(manControlSettingsUAVO);
59 m_gcsReceiver = UAVTalkReceiver::GetInstance(objMngr);
60 Q_ASSERT(m_gcsReceiver);
63 GCSControl::~GCSControl()
69 bool GCSControl::initialize(
const QStringList &arguments, QString *errorString)
72 Q_UNUSED(errorString);
75 sdlGamepad =
new SDLGamepad();
76 if (sdlGamepad->init()) {
78 qRegisterMetaType<QListInt16>(
"QListInt16");
79 qRegisterMetaType<ButtonNumber>(
"ButtonNumber");
91 void GCSControl::shutdown()
103 dataBackup = manControlSettingsUAVO->getData();
104 metaBackup = manControlSettingsUAVO->getMetadata();
105 ManualControlSettings::Metadata meta = manControlSettingsUAVO->getDefaultMetadata();
110 manControlSettingsUAVO->setChannelGroups(ManualControlSettings::CHANNELGROUPS_FLIGHTMODE,
111 ManualControlSettings::CHANNELGROUPS_NONE);
115 const int NUM_CHANNELS = 5;
116 const quint8 channels[NUM_CHANNELS] = { ManualControlSettings::CHANNELGROUPS_THROTTLE,
117 ManualControlSettings::CHANNELGROUPS_ROLL,
118 ManualControlSettings::CHANNELGROUPS_PITCH,
119 ManualControlSettings::CHANNELGROUPS_YAW,
120 ManualControlSettings::CHANNELGROUPS_ARMING };
122 for (quint8
i = 0;
i < NUM_CHANNELS; ++
i) {
123 quint8
x = channels[
i];
125 inverseMapping[
x] =
i;
128 manControlSettingsUAVO->setChannelGroups(x, ManualControlSettings::CHANNELGROUPS_UAVTALK);
131 manControlSettingsUAVO->setChannelNumber(x,
i + 1);
132 manControlSettingsUAVO->setChannelMax(x, CHANNEL_MAX);
134 if (x == ManualControlSettings::CHANNELGROUPS_THROTTLE) {
135 manControlSettingsUAVO->setChannelNeutral(x, CHANNEL_THROTNEUTRAL);
137 manControlSettingsUAVO->setChannelNeutral(x, CHANNEL_NEUTRAL);
140 manControlSettingsUAVO->setChannelMin(x, CHANNEL_MIN);
143 manControlSettingsUAVO->setDeadband(0);
144 manControlSettingsUAVO->setFlightModeNumber(1);
145 manControlSettingsUAVO->setFlightModePosition(
146 0, ManualControlSettings::FLIGHTMODEPOSITION_STABILIZED1);
147 manControlSettingsUAVO->updated();
151 for (quint8
x = 0;
x < NUM_CHANNELS; ++
x) {
155 setChannel(ManualControlSettings::CHANNELGROUPS_ARMING, -1);
156 receiverActivity.start();
168 &GCSControl::objectsUpdated);
169 manControlSettingsUAVO->setData(dataBackup);
170 manControlSettingsUAVO->setMetadata(metaBackup);
171 manControlSettingsUAVO->updated();
173 receiverActivity.stop();
181 manControlSettingsUAVO->setFlightModePosition(0, flightMode);
182 manControlSettingsUAVO->updated();
183 m_gcsReceiver->setChannel(ManualControlSettings::CHANNELGROUPS_FLIGHTMODE, CHANNEL_MIN);
184 m_gcsReceiver->updated();
190 return setChannel(ManualControlSettings::CHANNELGROUPS_THROTTLE, value);
195 return setChannel(ManualControlSettings::CHANNELGROUPS_ROLL, value);
200 return setChannel(ManualControlSettings::CHANNELGROUPS_PITCH, value);
205 return setChannel(ManualControlSettings::CHANNELGROUPS_YAW, value);
210 return setChannel(ManualControlSettings::CHANNELGROUPS_ARMING, value);
215 if (channeltype >= ManualControlSettings::CHANNELGROUPS_NUMELEM)
218 uint8_t channel = inverseMapping[channeltype];
220 if (value > 1 || value < -1 || channel >= UAVTalkReceiver::CHANNEL_NUMELEM || !hasControl)
224 pwmValue = (value * (float)(CHANNEL_MAX - CHANNEL_NEUTRAL)) + (
float)CHANNEL_NEUTRAL;
226 pwmValue = (value * (float)(CHANNEL_NEUTRAL - CHANNEL_MIN)) + (
float)CHANNEL_NEUTRAL;
227 m_gcsReceiver->setChannel(channel, pwmValue);
228 m_gcsReceiver->updated();
232 void GCSControl::objectsUpdated(
UAVObject *obj)
234 qDebug() <<
"GCSControl::objectsUpdated"
235 <<
"Object" << obj->
getName() <<
"changed outside this class";
238 void GCSControl::receiverActivitySlot()
241 m_gcsReceiver->updated();
void addObject(QObject *obj)
Core plugin system that manages the plugins, their life cycle and their registered objects...
bool setRoll(float value)
bool setThrottle(float value)
bool setFlightMode(ManualControlSettings::FlightModePositionOptions flightMode)
bool setChannel(quint8 channel, float value)
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
static void SetGcsAccess(Metadata &meta, AccessMode mode)
bool beginGCSControl()
GCSControl::beginGCSControl Configure the FC to use the GCSReceiver control for manual control (cache...
bool setPitch(float value)
void removeObject(QObject *obj)
bool endGCSControl()
GCSControl::endGCSControl restores the cached ManualControlSettings.
void addAutoReleasedObject(QObject *obj)
bool setArming(float value)