Commit b81bdcfe authored by hengli's avatar hengli

Added yaw selection into target selection.

parent f24335bc
...@@ -2196,7 +2196,7 @@ void UAS::shutdown() ...@@ -2196,7 +2196,7 @@ void UAS::shutdown()
void UAS::setTargetPosition(float x, float y, float z, float yaw) void UAS::setTargetPosition(float x, float y, float z, float yaw)
{ {
mavlink_message_t msg; mavlink_message_t msg;
mavlink_msg_set_local_position_setpoint_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, uasId, 0, MAV_FRAME_LOCAL_NED, x, y, z, yaw); mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, uasId, MAV_COMP_ID_ALL, MAV_CMD_NAV_PATHPLANNING, 1, 2, 2, 0, yaw, x, y, z);
sendMessage(msg); sendMessage(msg);
} }
......
...@@ -248,13 +248,15 @@ Pixhawk3DWidget::toggleFollowCamera(int32_t state) ...@@ -248,13 +248,15 @@ Pixhawk3DWidget::toggleFollowCamera(int32_t state)
} }
void void
Pixhawk3DWidget::selectTarget(void) Pixhawk3DWidget::selectTargetHeading(void)
{ {
if (!uas) if (!uas)
{ {
return; return;
} }
osg::Vec2d p;
if (frame == MAV_FRAME_GLOBAL) if (frame == MAV_FRAME_GLOBAL)
{ {
double altitude = uas->getAltitude(); double altitude = uas->getAltitude();
...@@ -262,7 +264,7 @@ Pixhawk3DWidget::selectTarget(void) ...@@ -262,7 +264,7 @@ Pixhawk3DWidget::selectTarget(void)
std::pair<double,double> cursorWorldCoords = std::pair<double,double> cursorWorldCoords =
getGlobalCursorPosition(getMouseX(), getMouseY(), altitude); getGlobalCursorPosition(getMouseX(), getMouseY(), altitude);
target.set(cursorWorldCoords.first, cursorWorldCoords.second); p.set(cursorWorldCoords.first, cursorWorldCoords.second);
} }
else if (frame == MAV_FRAME_LOCAL_NED) else if (frame == MAV_FRAME_LOCAL_NED)
{ {
...@@ -271,12 +273,50 @@ Pixhawk3DWidget::selectTarget(void) ...@@ -271,12 +273,50 @@ Pixhawk3DWidget::selectTarget(void)
std::pair<double,double> cursorWorldCoords = std::pair<double,double> cursorWorldCoords =
getGlobalCursorPosition(getMouseX(), getMouseY(), -z); getGlobalCursorPosition(getMouseX(), getMouseY(), -z);
target.set(cursorWorldCoords.first, cursorWorldCoords.second); p.set(cursorWorldCoords.first, cursorWorldCoords.second);
} }
uas->setTargetPosition(target.x(), target.y(), 0.0, 0.0); target.z() = atan2(p.y() - target.y(), p.x() - target.x());
}
void
Pixhawk3DWidget::selectTarget(void)
{
if (!uas)
{
return;
}
if (frame == MAV_FRAME_GLOBAL)
{
double altitude = uas->getAltitude();
std::pair<double,double> cursorWorldCoords =
getGlobalCursorPosition(getMouseX(), getMouseY(), altitude);
target.set(cursorWorldCoords.first, cursorWorldCoords.second, 0.0);
}
else if (frame == MAV_FRAME_LOCAL_NED)
{
double z = uas->getLocalZ();
std::pair<double,double> cursorWorldCoords =
getGlobalCursorPosition(getMouseX(), getMouseY(), -z);
target.set(cursorWorldCoords.first, cursorWorldCoords.second, 0.0);
}
enableTarget = true; enableTarget = true;
mode = SELECT_TARGET_YAW_MODE;
}
void
Pixhawk3DWidget::setTarget(void)
{
selectTargetHeading();
uas->setTargetPosition(target.x(), target.y(), 0.0, target.z());
} }
void void
...@@ -303,7 +343,7 @@ Pixhawk3DWidget::insertWaypoint(void) ...@@ -303,7 +343,7 @@ Pixhawk3DWidget::insertWaypoint(void)
Imagery::UTMtoLL(cursorWorldCoords.first, cursorWorldCoords.second, utmZone, Imagery::UTMtoLL(cursorWorldCoords.first, cursorWorldCoords.second, utmZone,
latitude, longitude); latitude, longitude);
wp = new Waypoint(0, longitude, latitude, altitude); wp = new Waypoint(0, longitude, latitude, altitude, 0.0, 0.25);
} }
else if (frame == MAV_FRAME_LOCAL_NED) else if (frame == MAV_FRAME_LOCAL_NED)
{ {
...@@ -313,7 +353,7 @@ Pixhawk3DWidget::insertWaypoint(void) ...@@ -313,7 +353,7 @@ Pixhawk3DWidget::insertWaypoint(void)
getGlobalCursorPosition(getMouseX(), getMouseY(), -z); getGlobalCursorPosition(getMouseX(), getMouseY(), -z);
wp = new Waypoint(0, cursorWorldCoords.first, wp = new Waypoint(0, cursorWorldCoords.first,
cursorWorldCoords.second, z); cursorWorldCoords.second, z, 0.0, 0.25);
} }
if (wp) if (wp)
...@@ -706,6 +746,14 @@ Pixhawk3DWidget::mousePressEvent(QMouseEvent* event) ...@@ -706,6 +746,14 @@ Pixhawk3DWidget::mousePressEvent(QMouseEvent* event)
return; return;
} }
if (mode == SELECT_TARGET_YAW_MODE)
{
setTarget();
mode = DEFAULT_MODE;
return;
}
if (event->modifiers() == Qt::ShiftModifier) if (event->modifiers() == Qt::ShiftModifier)
{ {
selectedWpIndex = findWaypoint(event->x(), event->y()); selectedWpIndex = findWaypoint(event->x(), event->y());
...@@ -725,6 +773,17 @@ Pixhawk3DWidget::mousePressEvent(QMouseEvent* event) ...@@ -725,6 +773,17 @@ Pixhawk3DWidget::mousePressEvent(QMouseEvent* event)
Q3DWidget::mousePressEvent(event); Q3DWidget::mousePressEvent(event);
} }
void
Pixhawk3DWidget::mouseMoveEvent(QMouseEvent* event)
{
if (mode == SELECT_TARGET_YAW_MODE)
{
selectTargetHeading();
}
Q3DWidget::mouseMoveEvent(event);
}
void void
Pixhawk3DWidget::getPose(double& x, double& y, double& z, Pixhawk3DWidget::getPose(double& x, double& y, double& z,
double& roll, double& pitch, double& yaw, double& roll, double& pitch, double& yaw,
...@@ -927,14 +986,15 @@ Pixhawk3DWidget::createTarget(void) ...@@ -927,14 +986,15 @@ Pixhawk3DWidget::createTarget(void)
pat->setPosition(osg::Vec3d(0.0, 0.0, 0.0)); pat->setPosition(osg::Vec3d(0.0, 0.0, 0.0));
osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(osg::Vec3f(0.0f, 0.0f, 0.0f), 0.1f); osg::ref_ptr<osg::Cone> cone = new osg::Cone(osg::Vec3f(0.0f, 0.0f, 0.0f), 0.1f, 0.4f);
osg::ref_ptr<osg::ShapeDrawable> sphereDrawable = new osg::ShapeDrawable(sphere); osg::ref_ptr<osg::ShapeDrawable> coneDrawable = new osg::ShapeDrawable(cone);
sphereDrawable->setColor(osg::Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); coneDrawable->setColor(osg::Vec4f(0.0f, 1.0f, 0.0f, 1.0f));
osg::ref_ptr<osg::Geode> sphereGeode = new osg::Geode; coneDrawable->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
sphereGeode->addDrawable(sphereDrawable); osg::ref_ptr<osg::Geode> coneGeode = new osg::Geode;
sphereGeode->setName("Target"); coneGeode->addDrawable(coneDrawable);
coneGeode->setName("Target");
pat->addChild(sphereGeode); pat->addChild(coneGeode);
return pat; return pat;
} }
...@@ -1216,8 +1276,23 @@ void ...@@ -1216,8 +1276,23 @@ void
Pixhawk3DWidget::updateTarget(double robotX, double robotY) Pixhawk3DWidget::updateTarget(double robotX, double robotY)
{ {
osg::PositionAttitudeTransform* pat = osg::PositionAttitudeTransform* pat =
static_cast<osg::PositionAttitudeTransform*>(targetNode.get()); dynamic_cast<osg::PositionAttitudeTransform*>(targetNode.get());
pat->setPosition(osg::Vec3d(target.y() - robotY, target.x() - robotX, 0.0)); pat->setPosition(osg::Vec3d(target.y() - robotY, target.x() - robotX, 0.0));
pat->setAttitude(osg::Quat(target.z() - M_PI_2, osg::Vec3d(1.0f, 0.0f, 0.0f),
M_PI_2, osg::Vec3d(0.0f, 1.0f, 0.0f),
0.0, osg::Vec3d(0.0f, 0.0f, 1.0f)));
osg::Geode* geode = dynamic_cast<osg::Geode*>(pat->getChild(0));
osg::ShapeDrawable* sd = dynamic_cast<osg::ShapeDrawable*>(geode->getDrawable(0));
if (mode == SELECT_TARGET_YAW_MODE)
{
sd->setColor(osg::Vec4f(1.0f, 0.8f, 0.0f, 1.0f));
}
else
{
sd->setColor(osg::Vec4f(0.0f, 1.0f, 0.0f, 1.0f));
}
} }
float colormap_jet[128][3] = { float colormap_jet[128][3] = {
......
...@@ -70,7 +70,9 @@ private slots: ...@@ -70,7 +70,9 @@ private slots:
void recenter(void); void recenter(void);
void toggleFollowCamera(int state); void toggleFollowCamera(int state);
void selectTargetHeading(void);
void selectTarget(void); void selectTarget(void);
void setTarget(void);
void insertWaypoint(void); void insertWaypoint(void);
void moveWaypoint(void); void moveWaypoint(void);
void setWaypoint(void); void setWaypoint(void);
...@@ -85,6 +87,7 @@ protected: ...@@ -85,6 +87,7 @@ protected:
virtual void display(void); virtual void display(void);
virtual void keyPressEvent(QKeyEvent* event); virtual void keyPressEvent(QKeyEvent* event);
virtual void mousePressEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
UASInterface* uas; UASInterface* uas;
...@@ -127,7 +130,8 @@ private: ...@@ -127,7 +130,8 @@ private:
enum Mode { enum Mode {
DEFAULT_MODE, DEFAULT_MODE,
MOVE_WAYPOINT_MODE MOVE_WAYPOINT_MODE,
SELECT_TARGET_YAW_MODE
}; };
Mode mode; Mode mode;
int selectedWpIndex; int selectedWpIndex;
...@@ -170,7 +174,7 @@ private: ...@@ -170,7 +174,7 @@ private:
QVector< osg::ref_ptr<osg::Node> > vehicleModels; QVector< osg::ref_ptr<osg::Node> > vehicleModels;
MAV_FRAME frame; MAV_FRAME frame;
osg::Vec2d target; osg::Vec3d target;
double lastRobotX, lastRobotY, lastRobotZ; double lastRobotX, lastRobotY, lastRobotZ;
}; };
......
...@@ -67,6 +67,7 @@ Q3DWidget::Q3DWidget(QWidget* parent) ...@@ -67,6 +67,7 @@ Q3DWidget::Q3DWidget(QWidget* parent)
setThreadingModel(osgViewer::Viewer::SingleThreaded); setThreadingModel(osgViewer::Viewer::SingleThreaded);
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
setMouseTracking(true);
} }
Q3DWidget::~Q3DWidget() Q3DWidget::~Q3DWidget()
......
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