Skip to content

Commit ad0ed25

Browse files
committed
added interactive markers
1 parent d1e2d2b commit ad0ed25

File tree

6 files changed

+124
-17
lines changed

6 files changed

+124
-17
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(lecture)
44
## Find catkin macros and libraries
55
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
66
## is used, also find other catkin packages
7-
find_package(catkin REQUIRED roscpp)
7+
find_package(catkin REQUIRED roscpp interactive_markers)
88
find_package(Qt5 REQUIRED COMPONENTS Widgets)
99
find_package(cmake_modules REQUIRED)
1010
find_package(Eigen REQUIRED)

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<!-- Use build_depend for packages required at compile time: -->
3636
<build_depend>cmake_modules</build_depend>
3737
<build_depend>roscpp</build_depend>
38+
<build_depend>interactive_markers</build_depend>
3839

3940
<!-- Use run_depend for packages you need at runtime: -->
4041
<run_depend>roscpp</run_depend>

src/MainWindow.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,32 @@
22
#include "RotationControl.h"
33

44
#include <QVBoxLayout>
5+
#include <Eigen/Core>
6+
#include <ros/ros.h>
57

68
MainWindow::MainWindow(QWidget *parent) :
7-
QMainWindow(parent)
9+
QMainWindow(parent), spinner(1)
810
{
11+
server.reset(new interactive_markers::InteractiveMarkerServer("euler","",false));
12+
setupUi();
13+
14+
server->applyChanges();
15+
spinner.start();
16+
}
17+
18+
MainWindow::~MainWindow()
19+
{
20+
spinner.stop();
21+
}
22+
23+
void MainWindow::setupUi() {
924
QWidget *central = new QWidget(this);
1025

11-
frame1 = new RotationControl(this);
12-
frame2 = new RotationControl(this);
13-
frame1p2 = new RotationControl(this);
14-
frame1c2 = new RotationControl(this);
26+
double s = 0.5;
27+
frame1 = new RotationControl("frame 1", Eigen::Vector3d(-s,s,0), server, this);
28+
frame2 = new RotationControl("frame 2", Eigen::Vector3d( s,s,0), server, this);
29+
frame1p2 = new RotationControl("frame 1+2", Eigen::Vector3d(-s,-s,0), server, this);
30+
frame1c2 = new RotationControl("frame 1*2", Eigen::Vector3d( s,-s,0), server, this);
1531

1632
QVBoxLayout *layout = new QVBoxLayout(central);
1733
layout->addWidget(frame1);

src/MainWindow.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
#pragma once
22

33
#include <QMainWindow>
4+
#include <interactive_markers/interactive_marker_server.h>
5+
46
class RotationControl;
57

68
class MainWindow : public QMainWindow
79
{
810
Q_OBJECT
911
public:
1012
explicit MainWindow(QWidget *parent = 0);
13+
~MainWindow();
1114

1215
signals:
1316

1417
public slots:
1518

16-
public:
19+
private:
20+
void setupUi();
21+
22+
private:
23+
boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server;
24+
ros::AsyncSpinner spinner;
25+
1726
RotationControl *frame1;
1827
RotationControl *frame2;
1928
RotationControl *frame1p2;

src/RotationControl.cpp

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33
#include "EulerWidget.h"
44

55
#include <QBoxLayout>
6+
#include <visualization_msgs/InteractiveMarker.h>
7+
#include <visualization_msgs/InteractiveMarkerFeedback.h>
68

7-
RotationControl::RotationControl(QWidget *parent, const QString &title) :
8-
QWidget(parent)
9+
RotationControl::RotationControl(const std::string &title,
10+
const Eigen::Vector3d &position,
11+
boost::shared_ptr<interactive_markers::InteractiveMarkerServer> &server,
12+
QWidget *parent) :
13+
QGroupBox(QString::fromStdString(title), parent), _server(server), _title(title)
914
{
1015
qRegisterMetaType<Eigen::Quaterniond>("Eigen::Quaterniond");
1116

12-
_qw = new QuaternionWidget(parent);
13-
_ew = new EulerWidget(parent);
17+
setupUi();
18+
createInteractiveMarker(position);
19+
}
20+
21+
void RotationControl::setupUi() {
22+
_qw = new QuaternionWidget(this);
23+
_ew = new EulerWidget(this);
1424

1525
QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
1626
layout->addWidget(_qw);
@@ -38,9 +48,13 @@ void RotationControl::setValue(const Eigen::Quaterniond &q) {
3848

3949
if (!q.isApprox(_qw->value())) _qw->setValue(q);
4050
if (!q.isApprox(_ew->value())) _ew->setValue(q);
51+
52+
updatePose(_q);
53+
4154
emit valueChanged(q);
4255
}
4356

57+
4458
void RotationControl::setEulerAxes(uint a1, uint a2, uint a3) {
4559
_ew->setEulerAxes(a1, a2, a3);
4660
}
@@ -54,3 +68,58 @@ const Eigen::Vector3d RotationControl::eulerAngles() const {
5468
void RotationControl::setEulerAngles(double e1, double e2, double e3) {
5569
_ew->setEulerAngles(e1, e2, e3);
5670
}
71+
72+
void RotationControl::updatePose(const Eigen::Quaterniond &q) {
73+
_pose.orientation.w = q.w();
74+
_pose.orientation.x = q.x();
75+
_pose.orientation.y = q.y();
76+
_pose.orientation.z = q.z();
77+
}
78+
79+
static visualization_msgs::InteractiveMarkerControl createViewPlaneControl() {
80+
visualization_msgs::InteractiveMarkerControl control;
81+
control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
82+
control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_3D;
83+
control.independent_marker_orientation = true;
84+
control.always_visible = true;
85+
control.name = "rotate";
86+
87+
return control;
88+
}
89+
90+
static visualization_msgs::Marker createBoxMarker(double x, double y, double z,
91+
const QColor &color) {
92+
visualization_msgs::Marker marker;
93+
94+
marker.type = visualization_msgs::Marker::CUBE;
95+
marker.scale.x = x;
96+
marker.scale.y = y;
97+
marker.scale.z = z;
98+
99+
marker.color.r = color.redF();
100+
marker.color.g = color.greenF();
101+
marker.color.b = color.blueF();
102+
marker.color.a = color.alphaF();
103+
104+
return marker;
105+
}
106+
107+
void RotationControl::createInteractiveMarker(const Eigen::Vector3d &pos) {
108+
_pose.position.x = pos[0];
109+
_pose.position.y = pos[1];
110+
_pose.position.z = pos[2];
111+
updatePose(_q);
112+
113+
visualization_msgs::InteractiveMarker imarker;
114+
imarker.header.frame_id = "world";
115+
imarker.header.stamp = ros::Time::now();
116+
imarker.pose = _pose;
117+
imarker.name = _title;
118+
float s = imarker.scale = 0.2;
119+
120+
visualization_msgs::InteractiveMarkerControl ctrl = createViewPlaneControl();
121+
ctrl.markers.push_back(createBoxMarker(3*s, 2*s, 1*s, QColor("grey")));
122+
imarker.controls.push_back(ctrl);
123+
124+
_server->insert(imarker);
125+
}

src/RotationControl.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#pragma once
22

3-
#include <QWidget>
3+
#include <QGroupBox>
44
#include <Eigen/Geometry>
5+
#include <interactive_markers/interactive_marker_server.h>
6+
#include <visualization_msgs/InteractiveMarkerFeedback.h>
57

68
class QuaternionWidget;
79
class EulerWidget;
810

9-
class RotationControl : public QWidget
11+
class RotationControl : public QGroupBox
1012
{
1113
Q_OBJECT
1214
public:
13-
explicit RotationControl(QWidget *parent = 0,
14-
const QString &title="");
15+
explicit RotationControl(const std::string &_title,
16+
const Eigen::Vector3d &position,
17+
boost::shared_ptr<interactive_markers::InteractiveMarkerServer> &_server,
18+
QWidget *parent = 0);
1519

1620
const Eigen::Quaterniond& value() const;
1721
const Eigen::Vector3d eulerAngles() const;
@@ -27,8 +31,16 @@ public slots:
2731
void setEulerAngles(double e1, double e2, double e3);
2832
void setEulerAxes(uint a1, uint a2, uint a3);
2933

30-
public:
31-
Eigen::Quaterniond _q;
34+
private:
35+
void setupUi();
36+
void createInteractiveMarker(const Eigen::Vector3d &position);
37+
void updatePose(const Eigen::Quaterniond &q);
38+
39+
private:
40+
Eigen::Quaterniond _q;
41+
boost::shared_ptr<interactive_markers::InteractiveMarkerServer> _server;
42+
std::string _title;
43+
geometry_msgs::Pose _pose;
3244

3345
QuaternionWidget *_qw;
3446
EulerWidget *_ew;

0 commit comments

Comments
 (0)