Skip to content

Commit 13882d9

Browse files
authored
Fix GridConfig pose updates (#658)
Signed-off-by: Ian Chen <ichen@openrobotics.org>
1 parent 4ca0db0 commit 13882d9

File tree

3 files changed

+57
-31
lines changed

3 files changed

+57
-31
lines changed

src/plugins/grid_config/GridConfig.cc

+29-6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void GridConfig::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
130130
std::stringstream poseStr;
131131
poseStr << std::string(elem->GetText());
132132
poseStr >> gridParam.pose;
133+
this->emit GridPoseChanged();
133134
}
134135

135136
elem = insertElem->FirstChildElement("color");
@@ -285,13 +286,12 @@ void GridConfig::ConnectToGrid()
285286
this->dataPtr->gridParam.vCellCount = grid->VerticalCellCount();
286287
this->dataPtr->gridParam.cellLength = grid->CellLength();
287288
this->dataPtr->gridParam.pose = grid->Parent()->LocalPose();
289+
this->emit GridPoseChanged();
288290
this->dataPtr->gridParam.color = grid->Parent()->Material()->Ambient();
289291
emit this->newParams(
290292
grid->CellCount(),
291293
grid->VerticalCellCount(),
292294
grid->CellLength(),
293-
convert(grid->Parent()->LocalPose().Pos()),
294-
convert(grid->Parent()->LocalPose().Rot().Euler()),
295295
convert(grid->Parent()->Material()->Ambient()));
296296
}
297297
}
@@ -345,11 +345,20 @@ void GridConfig::UpdateCellLength(double _length)
345345
}
346346

347347
/////////////////////////////////////////////////
348-
void GridConfig::SetPose(
349-
double _x, double _y, double _z,
350-
double _roll, double _pitch, double _yaw)
348+
void GridConfig::SetGridPose(const QList<double> &_gridPose)
351349
{
352-
this->dataPtr->gridParam.pose = math::Pose3d(_x, _y, _z, _roll, _pitch, _yaw);
350+
if (_gridPose == this->GridPose())
351+
return;
352+
353+
this->dataPtr->gridParam.pose = math::Pose3d(
354+
_gridPose[0],
355+
_gridPose[1],
356+
_gridPose[2],
357+
_gridPose[3],
358+
_gridPose[4],
359+
_gridPose[5]);
360+
emit this->GridPoseChanged();
361+
353362
this->dataPtr->dirty = true;
354363
}
355364

@@ -405,6 +414,20 @@ void GridConfig::RefreshList()
405414
this->OnName(this->dataPtr->nameList.at(0));
406415
emit this->NameListChanged();
407416
}
417+
418+
/////////////////////////////////////////////////
419+
QList<double> GridConfig::GridPose() const
420+
{
421+
return QList({
422+
this->dataPtr->gridParam.pose.Pos().X(),
423+
this->dataPtr->gridParam.pose.Pos().Y(),
424+
this->dataPtr->gridParam.pose.Pos().Z(),
425+
this->dataPtr->gridParam.pose.Rot().Roll(),
426+
this->dataPtr->gridParam.pose.Rot().Pitch(),
427+
this->dataPtr->gridParam.pose.Rot().Yaw()
428+
});
429+
}
430+
408431
} // namespace gz::gui
409432

410433
// Register this plugin

src/plugins/grid_config/GridConfig.hh

+19-10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ namespace gz::gui::plugins
5656
NOTIFY NameListChanged
5757
)
5858

59+
/// \brief Grid pose (QList order is x, y, z, roll, pitch, yaw)
60+
Q_PROPERTY(
61+
QList<double> gridPose
62+
READ GridPose
63+
WRITE SetGridPose
64+
NOTIFY GridPoseChanged
65+
)
66+
5967
/// \brief Constructor
6068
public: GridConfig();
6169

@@ -80,6 +88,17 @@ namespace gz::gui::plugins
8088
/// \brief Refresh list of grids. This is called in the rendering thread.
8189
public: void RefreshList();
8290

91+
/// \brief Get the current grid camera pose.
92+
public: Q_INVOKABLE QList<double> GridPose() const;
93+
94+
/// \brief Set the grid pose
95+
/// \param[in] _gridPose GridPose to set.
96+
/// The QList elements are x, y, z, roll, pitch, yaw
97+
public slots: void SetGridPose(const QList<double> &_gridPose);
98+
99+
/// \brief Notify that the grid pose has changed.
100+
signals: void GridPoseChanged();
101+
83102
/// \brief Callback when refresh button is pressed.
84103
public slots: void OnRefresh();
85104

@@ -110,12 +129,6 @@ namespace gz::gui::plugins
110129
/// \param[in] _length new cell length
111130
public slots: void UpdateCellLength(double _length);
112131

113-
/// \brief Callback to update grid pose
114-
/// \param[in] _x, _y, _z cartesion coordinates
115-
/// \param[in] _roll, _pitch, _yaw principal coordinates
116-
public slots: void SetPose(double _x, double _y, double _z,
117-
double _roll, double _pitch, double _yaw);
118-
119132
/// \brief Callback to update grid color
120133
/// \param[in] _r, _g, _b, _a RGB color model with fourth alpha channel
121134
public slots: void SetColor(double _r, double _g, double _b, double _a);
@@ -128,15 +141,11 @@ namespace gz::gui::plugins
128141
/// \param[in] _hCellCount Horizontal cell count
129142
/// \param[in] _vCellCount Vertical cell count
130143
/// \param[in] _cellLength Cell length
131-
/// \param[in] _pos XYZ Position
132-
/// \param[in] _rot RPY orientation
133144
/// \param[in] _color Grid color
134145
signals: void newParams(
135146
int _hCellCount,
136147
int _vCellCount,
137148
double _cellLength,
138-
QVector3D _pos,
139-
QVector3D _rot,
140149
QColor _color);
141150

142151
/// \internal

src/plugins/grid_config/GridConfig.qml

+9-15
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,10 @@ GridLayout {
3737

3838
Connections {
3939
target: GridConfig
40-
function onNewParams(_hCellCount, _vCellCount, _cellLength, _pos, _rot, _color) {
40+
function onNewParams(_hCellCount, _vCellCount, _cellLength, _color) {
4141
horizontalCellCount.value = _hCellCount;
4242
verticalCellCount.value = _vCellCount;
4343
cellLength.value = _cellLength;
44-
gzPoseInstance.xValue = _pos.x;
45-
gzPoseInstance.yValue = _pos.y;
46-
gzPoseInstance.zValue = _pos.z;
47-
gzPoseInstance.rollValue = _rot.x;
48-
gzPoseInstance.pitchValue = _rot.y;
49-
gzPoseInstance.yawValue = _rot.z;
5044
gzColorGrid.r = _color.r;
5145
gzColorGrid.g = _color.g;
5246
gzColorGrid.b = _color.b;
@@ -182,17 +176,18 @@ GridLayout {
182176
Layout.columnSpan: 4
183177
Layout.fillWidth: true
184178
readOnly: false
185-
xValue: 0.00
186-
yValue: 0.00
187-
zValue: 0.00
188-
rollValue: 0.00
189-
pitchValue: 0.00
190-
yawValue: 0.00
179+
180+
xValue: GridConfig.gridPose[0]
181+
yValue: GridConfig.gridPose[1]
182+
zValue: GridConfig.gridPose[2]
183+
rollValue: GridConfig.gridPose[3]
184+
pitchValue: GridConfig.gridPose[4]
185+
yawValue: GridConfig.gridPose[5]
191186

192187
onGzPoseSet: {
193188
// _x, _y, _z, _roll, _pitch, _yaw are parameters of signal gzPoseSet
194189
// from gz-gui GzPose.qml
195-
GridConfig.SetPose(_x, _y, _z, _roll, _pitch, _yaw)
190+
GridConfig.SetGridPose([_x, _y, _z, _roll, _pitch, _yaw])
196191
}
197192
expand: true
198193
gzPlotEnabled: false
@@ -220,4 +215,3 @@ GridLayout {
220215
onGzColorSet: GridConfig.SetColor(gzColorGrid.r, gzColorGrid.g, gzColorGrid.b, gzColorGrid.a)
221216
}
222217
}
223-

0 commit comments

Comments
 (0)