Commit 57207de3 authored by hengli's avatar hengli

Added command to select target position for robot - command can be accessed...

Added command to select target position for robot - command can be accessed via a right-click in the 3D View perspective --Lionel
parent 8b414e7d
...@@ -45,7 +45,7 @@ INCLUDEPATH += . \ ...@@ -45,7 +45,7 @@ INCLUDEPATH += . \
$$BASEDIR/../mavlink/contrib/slugs/include \ $$BASEDIR/../mavlink/contrib/slugs/include \
$$BASEDIR/../mavlink/include \ $$BASEDIR/../mavlink/include \
/usr/include/freetype2 /usr/include/freetype2
LIBS += /usr/lib/libftgl.so LIBS += /usr/lib/libftgl.so /usr/lib/libglut.so
# ../mavlink/include \ # ../mavlink/include \
# MAVLink/include \ # MAVLink/include \
......
...@@ -1336,6 +1336,16 @@ void UAS::shutdown() ...@@ -1336,6 +1336,16 @@ void UAS::shutdown()
} }
} }
void UAS::setTargetPosition(float x, float y, float z, float yaw)
{
mavlink_message_t msg;
mavlink_msg_position_target_pack(MG::SYSTEM::ID, MG::SYSTEM::COMPID, &msg, x, y, z, yaw);
// Send message twice to increase chance of reception
sendMessage(msg);
sendMessage(msg);
}
/** /**
* @return The name of this system as string in human-readable form * @return The name of this system as string in human-readable form
*/ */
......
...@@ -179,6 +179,9 @@ public slots: ...@@ -179,6 +179,9 @@ public slots:
/** @brief Shut the system cleanly down. Will shut down any onboard computers **/ /** @brief Shut the system cleanly down. Will shut down any onboard computers **/
void shutdown(); void shutdown();
/** @brief Set the target position for the robot to navigate to. */
void setTargetPosition(float x, float y, float z, float yaw);
void startLowBattAlarm(); void startLowBattAlarm();
void stopLowBattAlarm(); void stopLowBattAlarm();
......
...@@ -177,6 +177,13 @@ public slots: ...@@ -177,6 +177,13 @@ public slots:
* Works only if already landed and will cleanly shut down all onboard computers. * Works only if already landed and will cleanly shut down all onboard computers.
*/ */
virtual void shutdown() = 0; virtual void shutdown() = 0;
/** @brief Set the target position for the robot to navigate to.
* @param x x-coordinate of the target position
* @param y y-coordinate of the target position
* @param z z-coordinate of the target position
* @param yaw heading of the target position
*/
virtual void setTargetPosition(float x, float y, float z, float yaw) = 0;
/** @brief Request the list of stored waypoints from the robot */ /** @brief Request the list of stored waypoints from the robot */
//virtual void requestWaypoints() = 0; //virtual void requestWaypoints() = 0;
/** @brief Clear all existing waypoints on the robot */ /** @brief Clear all existing waypoints on the robot */
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Generates a display list which renders a Pixhawk Cheetah MAV.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
/* /*
This file was produced by Deep Exploration Plugin: CPP Export filter. This file was produced by Deep Exploration Plugin: CPP Export filter.
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Generates a display list which renders a Pixhawk Cheetah MAV.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef CHEETAHGL_H_ #ifndef CHEETAHGL_H_
#define CHEETAHGL_H_ #define CHEETAHGL_H_
#include <GL/gl.h> #include <GL/gl.h>
/**
* @brief Creates a display list which renders a Pixhawk Cheetah MAV.
* @param red Red intensity of the MAV model
* @param green Green intensity of the MAV model
* @param blue Blue intensity of the MAV model
*
* @return The index of the display list.
**/
GLint generatePixhawkCheetah(float red, float green, float blue); GLint generatePixhawkCheetah(float red, float green, float blue);
#endif #endif
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class CheetahModel.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#include "CheetahModel.h" #include "CheetahModel.h"
#include "CheetahGL.h" #include "CheetahGL.h"
...@@ -11,14 +42,14 @@ CheetahModel::CheetahModel() ...@@ -11,14 +42,14 @@ CheetahModel::CheetahModel()
void void
CheetahModel::init(float red, float green, float blue) CheetahModel::init(float red, float green, float blue)
{ {
cheetah_dl = generatePixhawkCheetah(red, green, blue); cheetah_dl = generatePixhawkCheetah(red, green, blue);
} }
void void
CheetahModel::draw(void) CheetahModel::draw(void)
{ {
glPushMatrix(); glPushMatrix();
glScalef(0.5f, 0.5f, -0.5f); glScalef(0.5f, 0.5f, -0.5f);
glCallList(cheetah_dl); glCallList(cheetah_dl);
glPopMatrix(); glPopMatrix();
} }
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class CheetahModel.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef CHEETAHMODEL_H_ #ifndef CHEETAHMODEL_H_
#define CHEETAHMODEL_H_ #define CHEETAHMODEL_H_
#include <GL/gl.h> #include <GL/gl.h>
/**
* @brief Container for display list which renders the Pixhawk Cheetah MAV.
**/
class CheetahModel class CheetahModel
{ {
public: public:
CheetahModel(); CheetahModel();
/**
* @brief Initializes the display list.
* @param red Red intensity of the MAV model
* @param green Green intensity of the MAV model
* @param blue Blue intensity of the MAV model
**/
void init(float red, float green, float blue);
void init(float red, float green, float blue); /**
void draw(void); * @brief Executes the display list.
**/
void draw(void);
private: private:
GLint cheetah_dl; GLint cheetah_dl;
}; };
#endif /* CHEETAHMODEL_H_ */ #endif /* CHEETAHMODEL_H_ */
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class Q3DWidget.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#include "Q3DWidget.h" #include "Q3DWidget.h"
#include <cmath> #include <cmath>
...@@ -28,7 +59,6 @@ Q3DWidget::Q3DWidget(QWidget* parent) ...@@ -28,7 +59,6 @@ Q3DWidget::Q3DWidget(QWidget* parent)
, _forceRedraw(false) , _forceRedraw(false)
, allow2DRotation(true) , allow2DRotation(true)
, limitCamera(false) , limitCamera(false)
, lockCamera(false)
, timerFunc(NULL) , timerFunc(NULL)
, timerFuncData(NULL) , timerFuncData(NULL)
{ {
...@@ -105,12 +135,6 @@ Q3DWidget::setCameraLimit(bool onoff) ...@@ -105,12 +135,6 @@ Q3DWidget::setCameraLimit(bool onoff)
limitCamera = onoff; limitCamera = onoff;
} }
void
Q3DWidget::setCameraLock(bool onoff)
{
lockCamera = onoff;
}
void void
Q3DWidget::set2DCameraParams(float zoomSensitivity2D, Q3DWidget::set2DCameraParams(float zoomSensitivity2D,
float rotateSensitivity2D, float rotateSensitivity2D,
...@@ -338,21 +362,18 @@ Q3DWidget::getMouseY(void) ...@@ -338,21 +362,18 @@ Q3DWidget::getMouseY(void)
void void
Q3DWidget::rotateCamera(float dx, float dy) Q3DWidget::rotateCamera(float dx, float dy)
{ {
if (!lockCamera) cameraPose.pan += dx * cameraParams.rotateSensitivity;
cameraPose.tilt += dy * cameraParams.rotateSensitivity;
if (limitCamera)
{ {
cameraPose.pan += dx * cameraParams.rotateSensitivity; if (cameraPose.tilt < 180.5f)
cameraPose.tilt += dy * cameraParams.rotateSensitivity; {
if (limitCamera) cameraPose.tilt = 180.5f;
{ }
if (cameraPose.tilt < 180.5f) else if (cameraPose.tilt > 269.5f)
{ {
cameraPose.tilt = 180.5f; cameraPose.tilt = 269.5f;
} }
else if (cameraPose.tilt > 269.5f)
{
cameraPose.tilt = 269.5f;
}
}
} }
} }
...@@ -495,8 +516,8 @@ Q3DWidget::paintGL(void) ...@@ -495,8 +516,8 @@ Q3DWidget::paintGL(void)
setDisplayMode2D(); setDisplayMode2D();
// do camera control // do camera control
glTranslatef(static_cast<float>(windowWidth) / 2.0f, glTranslatef(static_cast<float>(windowWidth) / 2.0f,
static_cast<float>(windowHeight) / 2.0f, static_cast<float>(windowHeight) / 2.0f,
0.0f); 0.0f);
glScalef(cameraPose.zoom, cameraPose.zoom, 1.0f); glScalef(cameraPose.zoom, cameraPose.zoom, 1.0f);
glRotatef(r2d(cameraPose.rotation2D), 0.0f, 0.0f, 1.0f); glRotatef(r2d(cameraPose.rotation2D), 0.0f, 0.0f, 1.0f);
glScalef(cameraPose.warpX, cameraPose.warpY, 1.0f); glScalef(cameraPose.warpX, cameraPose.warpY, 1.0f);
...@@ -540,303 +561,301 @@ Q3DWidget::resizeGL(int32_t width, int32_t height) ...@@ -540,303 +561,301 @@ Q3DWidget::resizeGL(int32_t width, int32_t height)
void void
Q3DWidget::keyPressEvent(QKeyEvent* event) Q3DWidget::keyPressEvent(QKeyEvent* event)
{ {
float dx = 0.0f, dy = 0.0f; float dx = 0.0f, dy = 0.0f;
Qt::KeyboardModifiers modifiers = event->modifiers(); Qt::KeyboardModifiers modifiers = event->modifiers();
if (_is3D) if (_is3D)
{ {
if (modifiers & Qt::ControlModifier) if (modifiers & Qt::ControlModifier)
{ {
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
dx = -KEY_ROTATE_AMOUNT; dx = -KEY_ROTATE_AMOUNT;
dy = 0.0f; dy = 0.0f;
break; break;
case Qt::Key_Right: case Qt::Key_Right:
dx = KEY_ROTATE_AMOUNT; dx = KEY_ROTATE_AMOUNT;
dy = 0.0f; dy = 0.0f;
break; break;
case Qt::Key_Up: case Qt::Key_Up:
dx = 0.0f; dx = 0.0f;
dy = KEY_ROTATE_AMOUNT; dy = KEY_ROTATE_AMOUNT;
break; break;
case Qt::Key_Down: case Qt::Key_Down:
dx = 0.0f; dx = 0.0f;
dy = -KEY_ROTATE_AMOUNT; dy = -KEY_ROTATE_AMOUNT;
break; break;
default: default:
QWidget::keyPressEvent(event); QWidget::keyPressEvent(event);
} }
if (dx != 0.0f || dy != 0.0f) if (dx != 0.0f || dy != 0.0f)
{ {
rotateCamera(dx, dy); rotateCamera(dx, dy);
} }
} }
else if (modifiers & Qt::AltModifier) else if (modifiers & Qt::AltModifier)
{ {
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Up: case Qt::Key_Up:
dy = KEY_ZOOM_AMOUNT; dy = KEY_ZOOM_AMOUNT;
break; break;
case Qt::Key_Down: case Qt::Key_Down:
dy = -KEY_ZOOM_AMOUNT; dy = -KEY_ZOOM_AMOUNT;
break; break;
default: default:
QWidget::keyPressEvent(event); QWidget::keyPressEvent(event);
} }
if (dy != 0.0f) if (dy != 0.0f)
{ {
zoomCamera(dy); zoomCamera(dy);
} }
} }
else else
{ {
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
dx = KEY_MOVE_AMOUNT; dx = KEY_MOVE_AMOUNT;
dy = 0.0f; dy = 0.0f;
break; break;
case Qt::Key_Right: case Qt::Key_Right:
dx = -KEY_MOVE_AMOUNT; dx = -KEY_MOVE_AMOUNT;
dy = 0.0f; dy = 0.0f;
break; break;
case Qt::Key_Up: case Qt::Key_Up:
dx = 0.0f; dx = 0.0f;
dy = -KEY_MOVE_AMOUNT; dy = -KEY_MOVE_AMOUNT;
break; break;
case Qt::Key_Down: case Qt::Key_Down:
dx = 0.0f; dx = 0.0f;
dy = KEY_MOVE_AMOUNT; dy = KEY_MOVE_AMOUNT;
break; break;
default: default:
QWidget::keyPressEvent(event); QWidget::keyPressEvent(event);
} }
if (dx != 0.0f || dy != 0.0f) if (dx != 0.0f || dy != 0.0f)
{ {
moveCamera(dx, dy); moveCamera(dx, dy);
} }
} }
} }
else { else
if (modifiers & Qt::ControlModifier) {
{ if (modifiers & Qt::ControlModifier)
switch (event->key()) {
{ switch (event->key())
case Qt::Key_Left: {
dx = KEY_ROTATE_AMOUNT; case Qt::Key_Left:
dy = 0.0f; dx = KEY_ROTATE_AMOUNT;
break; dy = 0.0f;
case Qt::Key_Right: break;
dx = -KEY_ROTATE_AMOUNT; case Qt::Key_Right:
dy = 0.0f; dx = -KEY_ROTATE_AMOUNT;
break; dy = 0.0f;
default: break;
QWidget::keyPressEvent(event); default:
} QWidget::keyPressEvent(event);
if (dx != 0.0f) }
{ if (dx != 0.0f)
rotateCamera2D(dx); {
} rotateCamera2D(dx);
} }
else if (modifiers & Qt::AltModifier) }
{ else if (modifiers & Qt::AltModifier)
switch (event->key()) {
{ switch (event->key())
case Qt::Key_Up: {
dy = KEY_ZOOM_AMOUNT; case Qt::Key_Up:
break; dy = KEY_ZOOM_AMOUNT;
case Qt::Key_Down: break;
dy = -KEY_ZOOM_AMOUNT; case Qt::Key_Down:
break; dy = -KEY_ZOOM_AMOUNT;
default: break;
QWidget::keyPressEvent(event); default:
} QWidget::keyPressEvent(event);
if (dy != 0.0f) }
{ if (dy != 0.0f)
zoomCamera2D(dy); {
} zoomCamera2D(dy);
} }
else { }
switch (event->key()) else
{ {
case Qt::Key_Left: switch (event->key())
dx = KEY_MOVE_AMOUNT; {
dy = 0.0f; case Qt::Key_Left:
break; dx = KEY_MOVE_AMOUNT;
case Qt::Key_Right: dy = 0.0f;
dx = -KEY_MOVE_AMOUNT; break;
dy = 0.0f; case Qt::Key_Right:
break; dx = -KEY_MOVE_AMOUNT;
case Qt::Key_Up: dy = 0.0f;
dx = 0.0f; break;
dy = KEY_MOVE_AMOUNT; case Qt::Key_Up:
break; dx = 0.0f;
case Qt::Key_Down: dy = KEY_MOVE_AMOUNT;
dx = 0.0f; break;
dy = -KEY_MOVE_AMOUNT; case Qt::Key_Down:
break; dx = 0.0f;
default: dy = -KEY_MOVE_AMOUNT;
QWidget::keyPressEvent(event); break;
} default:
if (dx != 0.0f || dy != 0.0f) QWidget::keyPressEvent(event);
{ }
moveCamera2D(dx, dy); if (dx != 0.0f || dy != 0.0f)
} {
} moveCamera2D(dx, dy);
} }
}
_forceRedraw = true; }
if (userKeyboardFunc) _forceRedraw = true;
{
if (event->text().isEmpty()) if (userKeyboardFunc)
{ {
userKeyboardFunc(0, userKeyboardFuncData); if (event->text().isEmpty())
} {
else userKeyboardFunc(0, userKeyboardFuncData);
{ }
userKeyboardFunc(event->text().at(0).toAscii(), else
userKeyboardFuncData); {
} userKeyboardFunc(event->text().at(0).toAscii(),
} userKeyboardFuncData);
}
}
} }
void void
Q3DWidget::mousePressEvent(QMouseEvent* event) Q3DWidget::mousePressEvent(QMouseEvent* event)
{ {
Qt::KeyboardModifiers modifiers = event->modifiers(); Qt::KeyboardModifiers modifiers = event->modifiers();
if (!(modifiers & (Qt::ControlModifier | Qt::AltModifier))) if (!(modifiers & (Qt::ControlModifier | Qt::AltModifier)))
{ {
lastMouseX = event->x(); lastMouseX = event->x();
lastMouseY = event->y(); lastMouseY = event->y();
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
{ {
cameraPose.state = ROTATING; cameraPose.state = ROTATING;
} }
else if (event->button() == Qt::MidButton) else if (event->button() == Qt::MidButton)
{ {
cameraPose.state = MOVING; cameraPose.state = MOVING;
} }
else if (event->button() == Qt::RightButton) }
{
cameraPose.state = ZOOMING;
}
}
_forceRedraw = true; _forceRedraw = true;
if (userMouseFunc) if (userMouseFunc)
{ {
userMouseFunc(event->button(), MOUSE_STATE_DOWN, event->x(), event->y(), userMouseFunc(event->button(), MOUSE_STATE_DOWN, event->x(), event->y(),
userMouseFuncData); userMouseFuncData);
} }
} }
void void
Q3DWidget::mouseReleaseEvent(QMouseEvent* event) Q3DWidget::mouseReleaseEvent(QMouseEvent* event)
{ {
Qt::KeyboardModifiers modifiers = event->modifiers(); Qt::KeyboardModifiers modifiers = event->modifiers();
if (!(modifiers & (Qt::ControlModifier | Qt::AltModifier))) if (!(modifiers & (Qt::ControlModifier | Qt::AltModifier)))
{ {
cameraPose.state = IDLE; cameraPose.state = IDLE;
} }
_forceRedraw = true; _forceRedraw = true;
if (userMouseFunc) if (userMouseFunc)
{ {
userMouseFunc(event->button(), MOUSE_STATE_UP, event->x(), event->y(), userMouseFunc(event->button(), MOUSE_STATE_UP, event->x(), event->y(),
userMouseFuncData); userMouseFuncData);
} }
} }
void void
Q3DWidget::mouseMoveEvent(QMouseEvent* event) Q3DWidget::mouseMoveEvent(QMouseEvent* event)
{ {
int32_t dx = event->x() - lastMouseX; int32_t dx = event->x() - lastMouseX;
int32_t dy = event->y() - lastMouseY; int32_t dy = event->y() - lastMouseY;
if (_is3D) if (_is3D)
{ {
if (cameraPose.state == ROTATING) if (cameraPose.state == ROTATING)
{ {
rotateCamera(static_cast<float>(dx), static_cast<float>(dy)); rotateCamera(static_cast<float>(dx), static_cast<float>(dy));
} }
else if (cameraPose.state == MOVING) else if (cameraPose.state == MOVING)
{ {
moveCamera(static_cast<float>(dx), static_cast<float>(dy)); moveCamera(static_cast<float>(dx), static_cast<float>(dy));
} }
else if (cameraPose.state == ZOOMING) else if (cameraPose.state == ZOOMING)
{ {
zoomCamera(static_cast<float>(dy)); zoomCamera(static_cast<float>(dy));
} }
} }
else else
{ {
if (cameraPose.state == ROTATING) if (cameraPose.state == ROTATING)
{ {
if (event->x() > windowWidth / 2) if (event->x() > windowWidth / 2)
{ {
dy *= -1; dy *= -1;
} }
rotateCamera2D(static_cast<float>(dx)); rotateCamera2D(static_cast<float>(dx));
} }
else if (cameraPose.state == MOVING) else if (cameraPose.state == MOVING)
{ {
moveCamera2D(static_cast<float>(dx), static_cast<float>(dy)); moveCamera2D(static_cast<float>(dx), static_cast<float>(dy));
} }
else if (cameraPose.state == ZOOMING) else if (cameraPose.state == ZOOMING)
{ {
zoomCamera2D(static_cast<float>(dy)); zoomCamera2D(static_cast<float>(dy));
} }
} }
lastMouseX = event->x(); lastMouseX = event->x();
lastMouseY = event->y(); lastMouseY = event->y();
_forceRedraw = true; _forceRedraw = true;
if (userMotionFunc) if (userMotionFunc)
{ {
userMotionFunc(event->x(), event->y(), userMotionFuncData); userMotionFunc(event->x(), event->y(), userMotionFuncData);
} }
} }
void void
Q3DWidget::wheelEvent(QWheelEvent* event) Q3DWidget::wheelEvent(QWheelEvent* event)
{ {
if (_is3D) if (_is3D)
{ {
zoomCamera(static_cast<float>(event->delta()) / 40.0f); zoomCamera(static_cast<float>(event->delta()) / 40.0f);
} }
else else
{ {
zoomCamera2D(static_cast<float>(event->delta()) / 40.0f); zoomCamera2D(static_cast<float>(event->delta()) / 40.0f);
} }
_forceRedraw = true; _forceRedraw = true;
} }
void void
Q3DWidget::timerEvent(QTimerEvent* event) Q3DWidget::timerEvent(QTimerEvent* event)
{ {
if (event->timerId() == timer.timerId()) if (event->timerId() == timer.timerId())
{ {
if (_forceRedraw) if (_forceRedraw)
{ {
updateGL(); updateGL();
_forceRedraw = false; _forceRedraw = false;
} }
} }
else else
{ {
QObject::timerEvent(event); QObject::timerEvent(event);
} }
} }
void void
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class Q3DWidget.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef Q3DWIDGET_H_ #ifndef Q3DWIDGET_H_
#define Q3DWIDGET_H_ #define Q3DWIDGET_H_
...@@ -50,6 +81,9 @@ typedef void (*KeyboardFunc)(char, void *); ...@@ -50,6 +81,9 @@ typedef void (*KeyboardFunc)(char, void *);
typedef void (*MouseFunc)(Qt::MouseButton, MouseState, int32_t, int32_t, void *); typedef void (*MouseFunc)(Qt::MouseButton, MouseState, int32_t, int32_t, void *);
typedef void (*MotionFunc)(int32_t, int32_t, void *); typedef void (*MotionFunc)(int32_t, int32_t, void *);
/**
* @brief A base 3D widget which executes OpenGL commands.
**/
class Q3DWidget: public QGLWidget class Q3DWidget: public QGLWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -67,7 +101,6 @@ public: ...@@ -67,7 +101,6 @@ public:
float maxClipRange); float maxClipRange);
void setCameraLimit(bool onoff); void setCameraLimit(bool onoff);
void setCameraLock(bool onoff);
void set2DCameraParams(float zoomSensitivity, void set2DCameraParams(float zoomSensitivity,
float rotateSensitivity, float rotateSensitivity,
...@@ -166,7 +199,6 @@ private: ...@@ -166,7 +199,6 @@ private:
bool _forceRedraw; bool _forceRedraw;
bool allow2DRotation; bool allow2DRotation;
bool limitCamera; bool limitCamera;
bool lockCamera;
CameraParams cameraParams; CameraParams cameraParams;
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class QMap3DWidget.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#include "QMap3DWidget.h" #include "QMap3DWidget.h"
#include <FTGL/ftgl.h> #include <FTGL/ftgl.h>
#include <GL/glut.h>
#include <QCheckBox> #include <QCheckBox>
#include <sys/time.h> #include <sys/time.h>
...@@ -14,14 +46,20 @@ QMap3DWidget::QMap3DWidget(QWidget* parent) ...@@ -14,14 +46,20 @@ QMap3DWidget::QMap3DWidget(QWidget* parent)
, lastRedrawTime(0.0) , lastRedrawTime(0.0)
, displayGrid(false) , displayGrid(false)
, displayTrail(false) , displayTrail(false)
, lockCamera(false) , lockCamera(true)
, updateLastUnlockedPose(true)
, displayTarget(false)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
initialize(10, 10, 1000, 900, 10.0f); initialize(10, 10, 1000, 900, 10.0f);
setCameraParams(0.05f, 0.5f, 0.01f, 0.5f, 30.0f, 0.01f, 400.0f); setCameraParams(0.05f, 0.5f, 0.01f, 0.5f, 30.0f, 0.01f, 400.0f);
int32_t argc = 0;
glutInit(&argc, NULL);
setDisplayFunc(display, this); setDisplayFunc(display, this);
setMouseFunc(mouse, this);
addTimerFunc(100, timer, this); addTimerFunc(100, timer, this);
buildLayout(); buildLayout();
...@@ -58,7 +96,6 @@ QMap3DWidget::buildLayout(void) ...@@ -58,7 +96,6 @@ QMap3DWidget::buildLayout(void)
QGridLayout* layout = new QGridLayout(this); QGridLayout* layout = new QGridLayout(this);
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(2); layout->setSpacing(2);
//layout->addWidget(mc, 0, 0, 1, 2);
layout->addWidget(gridCheckBox, 1, 0); layout->addWidget(gridCheckBox, 1, 0);
layout->addWidget(trailCheckBox, 1, 1); layout->addWidget(trailCheckBox, 1, 1);
layout->addWidget(recenterButton, 1, 2); layout->addWidget(recenterButton, 1, 2);
...@@ -106,7 +143,25 @@ QMap3DWidget::displayHandler(void) ...@@ -106,7 +143,25 @@ QMap3DWidget::displayHandler(void)
robotYaw = uas->getYaw(); robotYaw = uas->getYaw();
} }
setCameraLock(lockCamera); if (updateLastUnlockedPose)
{
lastUnlockedPose.x = robotX;
lastUnlockedPose.y = robotY;
lastUnlockedPose.z = robotZ;
camOffset.x = 0.0f;
camOffset.y = 0.0f;
camOffset.z = 0.0f;
updateLastUnlockedPose = false;
}
if (!lockCamera)
{
camOffset.x = robotX - lastUnlockedPose.x;
camOffset.y = robotY - lastUnlockedPose.y;
camOffset.z = robotZ - lastUnlockedPose.z;
}
// turn on smooth lines // turn on smooth lines
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
...@@ -118,6 +173,9 @@ QMap3DWidget::displayHandler(void) ...@@ -118,6 +173,9 @@ QMap3DWidget::displayHandler(void)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(camOffset.x, camOffset.y, camOffset.z);
// draw Cheetah model // draw Cheetah model
drawPlatform(robotRoll, robotPitch, robotYaw); drawPlatform(robotRoll, robotPitch, robotYaw);
...@@ -131,6 +189,13 @@ QMap3DWidget::displayHandler(void) ...@@ -131,6 +189,13 @@ QMap3DWidget::displayHandler(void)
drawTrail(robotX, robotY, robotZ); drawTrail(robotX, robotY, robotZ);
} }
if (displayTarget)
{
drawTarget(robotX, robotY, robotZ);
}
glPopMatrix();
// switch to 2D // switch to 2D
setDisplayMode2D(); setDisplayMode2D();
...@@ -143,7 +208,7 @@ QMap3DWidget::displayHandler(void) ...@@ -143,7 +208,7 @@ QMap3DWidget::displayHandler(void)
glVertex2f(getWindowWidth(), 0.0f); glVertex2f(getWindowWidth(), 0.0f);
glEnd(); glEnd();
char buffer[6][255]; char buffer[7][255];
sprintf(buffer[0], "x = %.2f", robotX); sprintf(buffer[0], "x = %.2f", robotX);
sprintf(buffer[1], "y = %.2f", robotY); sprintf(buffer[1], "y = %.2f", robotY);
...@@ -152,12 +217,17 @@ QMap3DWidget::displayHandler(void) ...@@ -152,12 +217,17 @@ QMap3DWidget::displayHandler(void)
sprintf(buffer[4], "p = %.2f", robotPitch); sprintf(buffer[4], "p = %.2f", robotPitch);
sprintf(buffer[5], "y = %.2f", robotYaw); sprintf(buffer[5], "y = %.2f", robotYaw);
std::pair<float,float> mouseWorldCoords =
getPositionIn3DMode(getMouseX(), getMouseY());
sprintf(buffer[6], "Cursor [%.2f %.2f]",
mouseWorldCoords.first + robotX, mouseWorldCoords.second + robotY);
font->FaceSize(10); font->FaceSize(10);
glColor3f(1.0f, 1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f);
glPushMatrix(); glPushMatrix();
glTranslatef(0.0f, 30.0f, 0.0f); glTranslatef(0.0f, 30.0f, 0.0f);
for (int32_t i = 0; i < 6; ++i) for (int32_t i = 0; i < 7; ++i)
{ {
glTranslatef(60.0f, 0.0f, 0.0f); glTranslatef(60.0f, 0.0f, 0.0f);
font->Render(buffer[i]); font->Render(buffer[i]);
...@@ -165,19 +235,25 @@ QMap3DWidget::displayHandler(void) ...@@ -165,19 +235,25 @@ QMap3DWidget::displayHandler(void)
glPopMatrix(); glPopMatrix();
} }
/** void
* QMap3DWidget::mouse(Qt::MouseButton button, MouseState state,
* @param uas the UAS/MAV to monitor/display with the HUD int32_t x, int32_t y, void* clientData)
*/
void QMap3DWidget::setActiveUAS(UASInterface* uas)
{ {
if (this->uas != NULL && this->uas != uas) QMap3DWidget* map3d = reinterpret_cast<QMap3DWidget *>(clientData);
map3d->mouseHandler(button, state, x, y);
}
void
QMap3DWidget::mouseHandler(Qt::MouseButton button, MouseState state,
int32_t x, int32_t y)
{
if (button == Qt::RightButton && state == MOUSE_STATE_DOWN)
{ {
// Disconnect any previously connected active MAV QMenu menu(this);
//disconnect(uas, SIGNAL(valueChanged(UASInterface*,QString,double,quint64)), this, SLOT(updateValue(UASInterface*,QString,double,quint64))); QAction* targetAction = menu.addAction("Mark as Target");
connect(targetAction, SIGNAL(triggered()), this, SLOT(markTarget()));
menu.exec(mapToGlobal(QPoint(x, y)));
} }
this->uas = uas;
} }
void void
...@@ -210,6 +286,45 @@ QMap3DWidget::getTime(void) const ...@@ -210,6 +286,45 @@ QMap3DWidget::getTime(void) const
static_cast<double>(tv.tv_usec) / 1000000.0; static_cast<double>(tv.tv_usec) / 1000000.0;
} }
/**
*
* @param uas the UAS/MAV to monitor/display with the HUD
*/
void QMap3DWidget::setActiveUAS(UASInterface* uas)
{
if (this->uas != NULL && this->uas != uas)
{
// Disconnect any previously connected active MAV
//disconnect(uas, SIGNAL(valueChanged(UASInterface*,QString,double,quint64)), this, SLOT(updateValue(UASInterface*,QString,double,quint64)));
}
this->uas = uas;
}
void
QMap3DWidget::markTarget(void)
{
std::pair<float,float> mouseWorldCoords =
getPositionIn3DMode(getLastMouseX(), getLastMouseY());
float robotX = 0.0f, robotY = 0.0f, robotZ = 0.0f;
if (uas != NULL)
{
robotX = uas->getLocalX();
robotY = uas->getLocalY();
robotZ = uas->getLocalZ();
}
targetPosition.x = mouseWorldCoords.first + robotX;
targetPosition.y = mouseWorldCoords.second + robotY;
targetPosition.z = robotZ;
displayTarget = true;
uas->setTargetPosition(targetPosition.x, targetPosition.y,
targetPosition.z, 0.0f);
}
void void
QMap3DWidget::showGrid(int32_t state) QMap3DWidget::showGrid(int32_t state)
{ {
...@@ -244,6 +359,8 @@ QMap3DWidget::showTrail(int32_t state) ...@@ -244,6 +359,8 @@ QMap3DWidget::showTrail(int32_t state)
void void
QMap3DWidget::recenterCamera(void) QMap3DWidget::recenterCamera(void)
{ {
updateLastUnlockedPose = true;
recenter(); recenter();
} }
...@@ -355,3 +472,36 @@ QMap3DWidget::drawTrail(float x, float y, float z) ...@@ -355,3 +472,36 @@ QMap3DWidget::drawTrail(float x, float y, float z)
} }
glEnd(); glEnd();
} }
void
QMap3DWidget::drawTarget(float x, float y, float z)
{
static double radius = 0.2;
static bool expand = true;
if (radius < 0.1)
{
expand = true;
}
else if (radius > 0.25)
{
expand = false;
}
glPushMatrix();
glTranslatef(targetPosition.x - x, targetPosition.y - y, 0.0f);
glColor3f(0.0f, 0.7f, 1.0f);
glLineWidth(1.0f);
glutWireSphere(radius, 10, 10);
if (expand)
{
radius += 0.02;
}
else
{
radius -= 0.02;
}
glPopMatrix();
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class QMap3DWidget.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef QMAP3DWIDGET_H #ifndef QMAP3DWIDGET_H
#define QMAP3DWIDGET_H #define QMAP3DWIDGET_H
...@@ -7,6 +38,9 @@ class CheetahModel; ...@@ -7,6 +38,9 @@ class CheetahModel;
class FTTextureFont; class FTTextureFont;
class UASInterface; class UASInterface;
/**
* @brief A 3D View widget which displays vehicle-centric information.
**/
class QMap3DWidget : public Q3DWidget class QMap3DWidget : public Q3DWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -20,6 +54,11 @@ public: ...@@ -20,6 +54,11 @@ public:
static void display(void* clientData); static void display(void* clientData);
void displayHandler(void); void displayHandler(void);
static void mouse(Qt::MouseButton button, MouseState state,
int32_t x, int32_t y, void* clientData);
void mouseHandler(Qt::MouseButton button, MouseState state,
int32_t x, int32_t y);
static void timer(void* clientData); static void timer(void* clientData);
void timerHandler(void); void timerHandler(void);
...@@ -27,6 +66,7 @@ public: ...@@ -27,6 +66,7 @@ public:
public slots: public slots:
void setActiveUAS(UASInterface* uas); void setActiveUAS(UASInterface* uas);
void markTarget(void);
private slots: private slots:
void showGrid(int state); void showGrid(int state);
...@@ -41,12 +81,12 @@ private: ...@@ -41,12 +81,12 @@ private:
void drawPlatform(float roll, float pitch, float yaw); void drawPlatform(float roll, float pitch, float yaw);
void drawGrid(void); void drawGrid(void);
void drawTrail(float x, float y, float z); void drawTrail(float x, float y, float z);
void drawTarget(float x, float y, float z);
double lastRedrawTime; double lastRedrawTime;
bool displayGrid; bool displayGrid;
bool displayTrail; bool displayTrail;
bool lockCamera;
typedef struct typedef struct
{ {
...@@ -54,8 +94,17 @@ private: ...@@ -54,8 +94,17 @@ private:
float y; float y;
float z; float z;
} Pose3D; } Pose3D;
bool lockCamera;
Pose3D lastUnlockedPose;
bool updateLastUnlockedPose;
Pose3D camOffset;
QVarLengthArray<Pose3D, 10000> trail; QVarLengthArray<Pose3D, 10000> trail;
bool displayTarget;
Pose3D targetPosition;
QScopedPointer<CheetahModel> cheetahModel; QScopedPointer<CheetahModel> cheetahModel;
QScopedPointer<FTTextureFont> font; QScopedPointer<FTTextureFont> font;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment