|
|
|
@ -1,24 +1,4 @@
@@ -1,24 +1,4 @@
|
|
|
|
|
/*=====================================================================
|
|
|
|
|
|
|
|
|
|
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit |
|
|
|
|
|
|
|
|
|
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
|
|
|
|
|
|
|
|
|
|
This file is part of the PIXHAWK project |
|
|
|
|
|
|
|
|
|
PIXHAWK 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. |
|
|
|
|
|
|
|
|
|
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
======================================================================*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -44,17 +24,17 @@ This file is part of the PIXHAWK project
@@ -44,17 +24,17 @@ This file is part of the PIXHAWK project
|
|
|
|
|
* @image html http://pixhawk.ethz.ch/wiki/_media/standards/body-frame.png Aeronautical frame
|
|
|
|
|
*/ |
|
|
|
|
JoystickInput::JoystickInput() : |
|
|
|
|
sdlJoystickMin(-32768.0f), |
|
|
|
|
sdlJoystickMax(32767.0f), |
|
|
|
|
defaultIndex(0), |
|
|
|
|
uas(NULL), |
|
|
|
|
uasButtonList(QList<int>()), |
|
|
|
|
done(false), |
|
|
|
|
thrustAxis(2), |
|
|
|
|
xAxis(0), |
|
|
|
|
yAxis(1), |
|
|
|
|
yawAxis(3), |
|
|
|
|
joystickName(tr("Unitinialized")) |
|
|
|
|
sdlJoystickMin(-32768.0f), |
|
|
|
|
sdlJoystickMax(32767.0f), |
|
|
|
|
defaultIndex(0), |
|
|
|
|
uas(NULL), |
|
|
|
|
uasButtonList(QList<int>()), |
|
|
|
|
done(false), |
|
|
|
|
thrustAxis(2), |
|
|
|
|
xAxis(0), |
|
|
|
|
yAxis(1), |
|
|
|
|
yawAxis(3), |
|
|
|
|
joystickName(tr("Unitinialized")) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
|
calibrationPositive[i] = sdlJoystickMax; |
|
|
|
@ -69,12 +49,12 @@ JoystickInput::JoystickInput() :
@@ -69,12 +49,12 @@ JoystickInput::JoystickInput() :
|
|
|
|
|
|
|
|
|
|
JoystickInput::~JoystickInput() |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
QMutexLocker locker(&this->m_doneMutex); |
|
|
|
|
done = true; |
|
|
|
|
} |
|
|
|
|
this->wait(); |
|
|
|
|
this->deleteLater(); |
|
|
|
|
done = true; |
|
|
|
|
while (done) |
|
|
|
|
{ |
|
|
|
|
QGC::SLEEP::usleep(5000); |
|
|
|
|
} |
|
|
|
|
this->deleteLater(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -82,9 +62,11 @@ void JoystickInput::setActiveUAS(UASInterface* uas)
@@ -82,9 +62,11 @@ void JoystickInput::setActiveUAS(UASInterface* uas)
|
|
|
|
|
{ |
|
|
|
|
// Only connect / disconnect is the UAS is of a controllable UAS class
|
|
|
|
|
UAS* tmp = 0; |
|
|
|
|
if (this->uas) { |
|
|
|
|
if (this->uas) |
|
|
|
|
{ |
|
|
|
|
tmp = dynamic_cast<UAS*>(this->uas); |
|
|
|
|
if(tmp) { |
|
|
|
|
if(tmp) |
|
|
|
|
{ |
|
|
|
|
disconnect(this, SIGNAL(joystickChanged(double,double,double,double,int,int)), tmp, SLOT(setManualControlCommands(double,double,double,double))); |
|
|
|
|
disconnect(this, SIGNAL(buttonPressed(int)), tmp, SLOT(receiveButton(int))); |
|
|
|
|
} |
|
|
|
@ -97,7 +79,8 @@ void JoystickInput::setActiveUAS(UASInterface* uas)
@@ -97,7 +79,8 @@ void JoystickInput::setActiveUAS(UASInterface* uas)
|
|
|
|
|
connect(this, SIGNAL(joystickChanged(double,double,double,double,int,int)), tmp, SLOT(setManualControlCommands(double,double,double,double))); |
|
|
|
|
connect(this, SIGNAL(buttonPressed(int)), tmp, SLOT(receiveButton(int))); |
|
|
|
|
} |
|
|
|
|
if (!isRunning()) { |
|
|
|
|
if (!isRunning()) |
|
|
|
|
{ |
|
|
|
|
start(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -113,17 +96,20 @@ void JoystickInput::init()
@@ -113,17 +96,20 @@ void JoystickInput::init()
|
|
|
|
|
int numJoysticks = SDL_NumJoysticks(); |
|
|
|
|
|
|
|
|
|
// Wait for joysticks if none is connected
|
|
|
|
|
while (numJoysticks == 0) { |
|
|
|
|
MG::SLEEP::msleep(200); |
|
|
|
|
while (numJoysticks == 0) |
|
|
|
|
{ |
|
|
|
|
MG::SLEEP::msleep(800); |
|
|
|
|
// INITIALIZE SDL Joystick support
|
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) { |
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) |
|
|
|
|
{ |
|
|
|
|
printf("Couldn't initialize SimpleDirectMediaLayer: %s\n", SDL_GetError()); |
|
|
|
|
} |
|
|
|
|
numJoysticks = SDL_NumJoysticks(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("%d Input devices found:\n", numJoysticks); |
|
|
|
|
for(int i=0; i < SDL_NumJoysticks(); i++ ) { |
|
|
|
|
for(int i=0; i < SDL_NumJoysticks(); i++ ) |
|
|
|
|
{ |
|
|
|
|
printf("\t- %s\n", SDL_JoystickName(i)); |
|
|
|
|
joystickName = QString(SDL_JoystickName(i)); |
|
|
|
|
} |
|
|
|
@ -147,16 +133,14 @@ void JoystickInput::run()
@@ -147,16 +133,14 @@ void JoystickInput::run()
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
|
|
forever |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
QMutexLocker locker(&this->m_doneMutex); |
|
|
|
|
if(done) |
|
|
|
|
{ |
|
|
|
|
done = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
while(SDL_PollEvent(&event)) { |
|
|
|
|
{ |
|
|
|
|
if (done) |
|
|
|
|
{ |
|
|
|
|
done = false; |
|
|
|
|
exit(); |
|
|
|
|
} |
|
|
|
|
while(SDL_PollEvent(&event)) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
SDL_JoystickUpdate(); |
|
|
|
|
|
|
|
|
@ -197,7 +181,8 @@ void JoystickInput::run()
@@ -197,7 +181,8 @@ void JoystickInput::run()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Display all axes
|
|
|
|
|
for(int i = 0; i < SDL_JoystickNumAxes(joystick); i++) { |
|
|
|
|
for(int i = 0; i < SDL_JoystickNumAxes(joystick); i++) |
|
|
|
|
{ |
|
|
|
|
//qDebug() << "\rAXIS" << i << "is: " << SDL_JoystickGetAxis(joystick, i);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -268,15 +253,19 @@ void JoystickInput::run()
@@ -268,15 +253,19 @@ void JoystickInput::run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Display all buttons
|
|
|
|
|
for(int i = 0; i < SDL_JoystickNumButtons(joystick); i++) { |
|
|
|
|
for(int i = 0; i < SDL_JoystickNumButtons(joystick); i++) |
|
|
|
|
{ |
|
|
|
|
//qDebug() << "BUTTON" << i << "is: " << SDL_JoystickGetAxis(joystick, i);
|
|
|
|
|
if(SDL_JoystickGetButton(joystick, i)) { |
|
|
|
|
if(SDL_JoystickGetButton(joystick, i)) |
|
|
|
|
{ |
|
|
|
|
emit buttonPressed(i); |
|
|
|
|
// Check if button is a UAS select button
|
|
|
|
|
|
|
|
|
|
if (uasButtonList.contains(i)) { |
|
|
|
|
if (uasButtonList.contains(i)) |
|
|
|
|
{ |
|
|
|
|
UASInterface* uas = UASManager::instance()->getUASForId(i); |
|
|
|
|
if (uas) { |
|
|
|
|
if (uas) |
|
|
|
|
{ |
|
|
|
|
UASManager::instance()->setActiveUAS(uas); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|