1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Ground/Joystick: Make the joystick only update at 50 hertz to keep telemetry

reasonable

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2077 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2010-11-05 14:28:18 +00:00 committed by peabody124
parent 9c8c4d90a1
commit c5ff7ca5a8
2 changed files with 10 additions and 6 deletions

View File

@ -29,7 +29,8 @@
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
#include "uavobjects/uavobjectmanager.h" #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobject.h" #include "uavobjects/uavobject.h"
#include <QDebug>
#define JOYSTICK_UPDATE_RATE 50
GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent) : GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent), IUAVGadget(classId, parent),
@ -43,7 +44,7 @@ GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widg
connect(this, SIGNAL(aboutToQuit()), &sdlGamepad, SLOT(quit())); connect(this, SIGNAL(aboutToQuit()), &sdlGamepad, SLOT(quit()));
if(sdlGamepad.init()) { if(sdlGamepad.init()) {
qDebug() << "SDL Initialized"; joystickTime.start();
sdlGamepad.start(); sdlGamepad.start();
qRegisterMetaType<QListInt16>("QListInt16"); qRegisterMetaType<QListInt16>("QListInt16");
qRegisterMetaType<ButtonNumber>("ButtonNumber"); qRegisterMetaType<ButtonNumber>("ButtonNumber");
@ -105,7 +106,7 @@ void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double r
void GCSControlGadget::gamepads(quint8 count) void GCSControlGadget::gamepads(quint8 count)
{ {
sdlGamepad.setGamepad(0); sdlGamepad.setGamepad(0);
sdlGamepad.setTickRate(40); sdlGamepad.setTickRate(JOYSTICK_UPDATE_RATE);
} }
void GCSControlGadget::buttonState(ButtonNumber number, bool pressed) void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
@ -119,6 +120,8 @@ void GCSControlGadget::axesValues(QListInt16 values)
double rightX = values[2]; double rightX = values[2];
double rightY = values[3]; double rightY = values[3];
double max = 32767; double max = 32767;
if(joystickTime.elapsed() > JOYSTICK_UPDATE_RATE) {
joystickTime.restart();
sticksChangedLocally(leftX/max,-leftY/max,rightX/max,-rightY/max); sticksChangedLocally(leftX/max,-leftY/max,rightX/max,-rightY/max);
}
} }

View File

@ -31,6 +31,7 @@
#include <coreplugin/iuavgadget.h> #include <coreplugin/iuavgadget.h>
#include <uavobjects/manualcontrolcommand.h> #include <uavobjects/manualcontrolcommand.h>
#include "sdlgamepad/sdlgamepad.h" #include "sdlgamepad/sdlgamepad.h"
#include <QTime>
namespace Core { namespace Core {
class IUAVGadget; class IUAVGadget;
@ -57,7 +58,7 @@ public:
private: private:
ManualControlCommand* getManualControlCommand(); ManualControlCommand* getManualControlCommand();
SDLGamepad sdlGamepad; SDLGamepad sdlGamepad;
QTime joystickTime;
QWidget *m_widget; QWidget *m_widget;
QList<int> m_context; QList<int> m_context;
UAVObject::Metadata mccInitialData; UAVObject::Metadata mccInitialData;