pose_widget.cpp
Go to the documentation of this file.
2 
3 namespace ram_qt_guis
4 {
5 
6 Pose::Pose(const QString name,
7  QWidget* parent) :
8  deg2rad_(0.017453293),
9  rad2deg_(57.2957795131),
10  pose_(Eigen::Affine3d::Identity())
11 {
12  setObjectName(name);
13 
14  layout_ = new QVBoxLayout(parent);
15 
16  label_pose_ = new QLabel(QString::fromStdString("Pose:"));
17  layout_->addWidget(label_pose_);
18 
19  QLabel* label_pose_x = new QLabel("X");
20  label_pose_x->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
21  QLabel* label_pose_y = new QLabel("Y");
22  QLabel* label_pose_z = new QLabel("Z");
23  QLabel* label_pose_w = new QLabel("W");
24  label_pose_w->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
25  QLabel* label_pose_p = new QLabel("P");
26  QLabel* label_pose_r = new QLabel("R");
27  pose_x_ = new QDoubleSpinBox;
28  pose_x_->setSuffix(" mm");
29  pose_x_->setRange(-20000, 20000);
30  pose_x_->setDecimals(3);
31  pose_y_ = new QDoubleSpinBox;
32  pose_y_->setSuffix(" mm");
33  pose_y_->setRange(-20000, 20000);
34  pose_y_->setDecimals(3);
35  pose_z_ = new QDoubleSpinBox;
36  pose_z_->setSuffix(" mm");
37  pose_z_->setRange(-20000, 20000);
38  pose_z_->setDecimals(3);
39  pose_w_ = new QDoubleSpinBox;
40  pose_w_->setSuffix(" deg");
41  pose_w_->setRange(-180, 180);
42  pose_w_->setDecimals(3);
43  pose_p_ = new QDoubleSpinBox;
44  pose_p_->setSuffix(" deg");
45  pose_p_->setRange(-180, 180);
46  pose_p_->setDecimals(3);
47  pose_r_ = new QDoubleSpinBox;
48  pose_r_->setSuffix(" deg");
49  pose_r_->setRange(-180, 180);
50  pose_r_->setDecimals(3);
51  QGridLayout* pose_layout = new QGridLayout;
52  layout_->addLayout(pose_layout);
53  pose_layout->addWidget(label_pose_x, 0, 0);
54  pose_layout->addWidget(pose_x_, 0, 1);
55  pose_layout->addWidget(label_pose_y, 1, 0);
56  pose_layout->addWidget(pose_y_, 1, 1);
57  pose_layout->addWidget(label_pose_z, 2, 0);
58  pose_layout->addWidget(pose_z_, 2, 1);
59  pose_layout->addWidget(label_pose_w, 0, 2);
60  pose_layout->addWidget(pose_w_, 0, 3);
61  pose_layout->addWidget(label_pose_p, 1, 2);
62  pose_layout->addWidget(pose_p_, 1, 3);
63  pose_layout->addWidget(label_pose_r, 2, 2);
64  pose_layout->addWidget(pose_r_, 2, 3);
65  pose_x_->setLocale(QLocale(QLocale::English));
66  pose_y_->setLocale(QLocale(QLocale::English));
67  pose_z_->setLocale(QLocale(QLocale::English));
68  pose_w_->setLocale(QLocale(QLocale::English));
69  pose_p_->setLocale(QLocale(QLocale::English));
70  pose_r_->setLocale(QLocale(QLocale::English));
71 
72  connect(pose_x_, SIGNAL(valueChanged(double)), this, SLOT(computePose()));
73  connect(pose_y_, SIGNAL(valueChanged(double)), this, SLOT(computePose()));
74  connect(pose_z_, SIGNAL(valueChanged(double)), this, SLOT(computePose()));
75  connect(pose_w_, SIGNAL(valueChanged(double)), this, SLOT(computePose()));
76  connect(pose_p_, SIGNAL(valueChanged(double)), this, SLOT(computePose()));
77  connect(pose_r_, SIGNAL(valueChanged(double)), this, SLOT(computePose()));
78 }
79 
80 void
82 {
83  config.mapSetValue(objectName() + "_x", pose_x_->value());
84  config.mapSetValue(objectName() + "_y", pose_y_->value());
85  config.mapSetValue(objectName() + "_z", pose_z_->value());
86  config.mapSetValue(objectName() + "_w", pose_w_->value());
87  config.mapSetValue(objectName() + "_p", pose_p_->value());
88  config.mapSetValue(objectName() + "_r", pose_r_->value());
89 }
90 
91 void
92 Pose::load(const rviz::Config &config)
93 {
94  float tmp(0);
95  if (config.mapGetFloat(objectName() + "_x", &tmp))
96  pose_x_->setValue(tmp);
97  if (config.mapGetFloat(objectName() + "_y", &tmp))
98  pose_y_->setValue(tmp);
99  if (config.mapGetFloat(objectName() + "_z", &tmp))
100  pose_z_->setValue(tmp);
101  if (config.mapGetFloat(objectName() + "_w", &tmp))
102  pose_w_->setValue(tmp);
103  if (config.mapGetFloat(objectName() + "_p", &tmp))
104  pose_p_->setValue(tmp);
105  if (config.mapGetFloat(objectName() + "_r", &tmp))
106  pose_r_->setValue(tmp);
107 }
108 
109 void
110 Pose::setTranslationEnabled(const bool enable)
111 {
112  pose_x_->setEnabled(enable);
113  pose_y_->setEnabled(enable);
114  pose_z_->setEnabled(enable);
115 }
116 
117 void
118 Pose::setText(const QString name)
119 {
120  label_pose_->setText(name);
121 }
122 
123 void
124 Pose::getPose(Eigen::Affine3d &pose)
125 {
126  pose = pose_;
127 }
128 
129 Eigen::Affine3d
131 {
132  return pose_;
133 }
134 
135 void
137 {
138  pose_ = Eigen::Affine3d::Identity();
139 
140  pose_x_->setValue(0);
141  pose_y_->setValue(0);
142  pose_z_->setValue(0);
143  pose_w_->setValue(0);
144  pose_p_->setValue(0);
145  pose_r_->setValue(0);
146 
147  Q_EMIT valueChanged();
148 }
149 
150 QVBoxLayout*
152 {
153  return layout_;
154 }
155 
156 void
158 {
159  pose_ = convertXYZWPRtoMatrix(pose_x_->value() / 1000.0,
160  pose_y_->value() / 1000.0,
161  pose_z_->value() / 1000.0,
162  deg2rad_ * pose_w_->value(),
163  deg2rad_ * pose_p_->value(),
164  deg2rad_ * pose_r_->value());
165 
166  Q_EMIT valueChanged();
167 }
168 
169 Eigen::Affine3d Pose::convertXYZWPRtoMatrix(const double x,
170  const double y,
171  const double z,
172  const double w,
173  const double p,
174  const double r)
175 {
176  using Eigen::Affine3d;
177  using Eigen::Matrix3d;
178  using Eigen::Vector3d;
179  using Eigen::AngleAxisd;
180 
181  Affine3d pose(Affine3d::Identity());
182  pose.translation()[0] = x;
183  pose.translation()[1] = y;
184  pose.translation()[2] = z;
185  Matrix3d rot;
186  rot = AngleAxisd(w, Vector3d::UnitX())
187  * AngleAxisd(p, Vector3d::UnitY())
188  * AngleAxisd(r, Vector3d::UnitZ());
189  pose.linear() = rot;
190 
191  return pose;
192 }
193 
194 }
195 
QDoubleSpinBox * pose_y_
Definition: pose_widget.hpp:56
QDoubleSpinBox * pose_r_
Definition: pose_widget.hpp:60
Eigen::Affine3d getPose()
bool mapGetFloat(const QString &key, float *value_out) const
QDoubleSpinBox * pose_p_
Definition: pose_widget.hpp:59
Eigen::Affine3d convertXYZWPRtoMatrix(const double x, const double y, const double z, const double w, const double p, const double r)
QLabel * label_pose_
Definition: pose_widget.hpp:54
void mapSetValue(const QString &key, QVariant value)
void setTranslationEnabled(const bool)
Identity
void save(rviz::Config)
Definition: pose_widget.cpp:81
QDoubleSpinBox * pose_x_
Definition: pose_widget.hpp:55
QDoubleSpinBox * pose_w_
Definition: pose_widget.hpp:58
QVBoxLayout * getLayout()
Pose(const QString name, QWidget *parent=NULL)
Definition: pose_widget.cpp:6
void load(const rviz::Config &)
Definition: pose_widget.cpp:92
void setText(const QString name)
QDoubleSpinBox * pose_z_
Definition: pose_widget.hpp:57
const double deg2rad_
Definition: pose_widget.hpp:41
QVBoxLayout * layout_
Definition: pose_widget.hpp:53
Eigen::Affine3d pose_
Definition: pose_widget.hpp:51


ram_qt_guis
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:11