72 localisationAdmin = localisationManager->getPropertiesAdmin();
75 map = localisation->getMap();
78 widget.smoothingFrameSize, SIGNAL(valueChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
79 connect(widget.smoothingMergeDistance,
80 SIGNAL(valueChanged(
int)),
83 connect(widget.matchingMaxDistance,
84 SIGNAL(valueChanged(
double)),
87 connect(widget.matchingMinPoints,
88 SIGNAL(valueChanged(
double)),
91 connect(widget.matchingCorrectionFactor,
92 SIGNAL(valueChanged(
double)),
96 widget.edgeMaxDistance, SIGNAL(valueChanged(
double)),
this, SLOT(
onSpinBoxChanged(
double)));
97 connect(widget.edgeMaxDeltaAngle,
98 SIGNAL(valueChanged(
double)),
101 connect(widget.edgePointAddingThreshold,
102 SIGNAL(valueChanged(
double)),
105 connect(widget.edgeEpsilon, SIGNAL(valueChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
106 connect(widget.edgeMinPoints, SIGNAL(valueChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
107 connect(widget.useMapCorrection, SIGNAL(stateChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
108 connect(widget.useOdometry, SIGNAL(stateChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
109 connect(widget.reportPoints, SIGNAL(stateChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
110 connect(widget.reportEdges, SIGNAL(stateChanged(
int)),
this, SLOT(
onSpinBoxChanged(
int)));
111 connect(widget.setPoseButton, SIGNAL(clicked()),
this, SLOT(
onSetPoseClick()));
113 widget.sensorStdDev, SIGNAL(valueChanged(
double)),
this, SLOT(
onSpinBoxChanged(
double)));
115 widget.velSensorStdDev, SIGNAL(valueChanged(
double)),
this, SLOT(
onSpinBoxChanged(
double)));
117 connect(painterWidget, SIGNAL(mousePressed(QPoint)),
this, SLOT(
onCanvasClick(QPoint)));
121 usingTopic(localisation->getReportTopicName());
149 float minX = FLT_MAX;
151 float minY = FLT_MAX;
152 for (LineSegment2D& s : map)
154 maxX = std::max(maxX, s.start.e0);
155 maxY = std::max(maxY, s.start.e1);
156 minX = std::min(minX, s.start.e0);
157 minY = std::min(minY, s.start.e1);
158 maxX = std::max(maxX, s.end.e0);
159 maxY = std::max(maxY, s.end.e1);
160 minX = std::min(minX, s.end.e0);
161 minY = std::min(minY, s.end.e1);
164 float normX = 1.0f / (maxX - minX);
165 float normY = 1.0f / (maxY - minY);
166 float scaleFactorX = size.width() * normX;
167 float scaleFactorY = size.height() * normY;
168 float scaleFactor = 0.95f * std::min(scaleFactorX, scaleFactorY);
169 float invScaleFactor = 1.0f / scaleFactor;
171 auto toCanvas = [=](armarx::Vector2f p)
173 float xCoord = scaleFactor * (p.e0 - minX);
174 float yCoord = scaleFactor * (p.e1 - minY);
175 return QPoint((
int)xCoord, (
int)(size.height() - 1 - yCoord));
178 auto toCanvasE = [=](Eigen::Vector2f p)
180 float xCoord = scaleFactor * (p.x() - minX);
181 float yCoord = scaleFactor * (p.y() - minY);
182 return QPoint((
int)xCoord, (
int)(size.height() - 1 - yCoord));
185 auto fromCanvas = [=](QPoint p)
187 float globalX = (invScaleFactor * p.x()) + minX;
188 float globalY = invScaleFactor * (size.height() - 1 - p.y()) + minY;
189 return Eigen::Vector2f(globalX, globalY);
192 if (setPoseState == SetPoseState::Wait)
194 setPoseState = SetPoseState::Orientation;
196 else if (setPoseState == SetPoseState::Finished)
199 Eigen::Vector2f globalPos = fromCanvas(setPosition);
200 Eigen::Vector2f globalOr = fromCanvas(setOrientation);
201 Eigen::Vector2f fromPosToOr = globalOr - globalPos;
202 float theta = std::atan2(fromPosToOr.y(), fromPosToOr.x()) - M_PI_2;
206 ARMARX_INFO <<
"Set global pose to (" << globalPos.x() <<
", " << globalPos.y() <<
", "
208 localisation->setAbsolutePose(globalPos.x(), globalPos.y(), theta);
210 catch (std::exception
const& ex)
215 setPoseState = SetPoseState::None;
218 QBrush whiteBrush(QColor(240, 240, 240));
219 QPen blackPen(QColor(0, 0, 0));
220 blackPen.setWidth(1);
221 painter.setBrush(whiteBrush);
222 painter.setPen(blackPen);
225 lines.reserve(map.size());
226 for (LineSegment2D
const& s : map)
228 lines.emplace_back(toCanvas(s.start), toCanvas(s.end));
230 painter.drawLines(lines.data(), lines.size());
232 if (setPoseState == SetPoseState::Orientation)
234 QPoint setOrientation = painterWidget->mapFromGlobal(QCursor::pos());
235 Eigen::Vector2f globalPos = fromCanvas(setPosition);
236 Eigen::Vector2f globalOr = fromCanvas(setOrientation);
238 painter.setBrush(QColor(255, 0, 0));
239 painter.drawEllipse(toCanvasE(globalPos), 10, 10);
240 painter.drawLine(toCanvasE(globalPos), toCanvasE(globalOr));
244 Eigen::Vector2f robotPos(poseX, poseY);
245 float robotTheta = poseTheta;
247 armarx::Vector2f estRobotPos{robotPos.x(), robotPos.y()};
248 Eigen::Vector2f estRobotEnd =
250 500.0f * Eigen::Vector2f(Eigen::Rotation2Df(robotTheta) * Eigen::Vector2f::UnitY());
251 armarx::Vector2f estRobotEnda{estRobotEnd.x(), estRobotEnd.y()};
252 painter.setBrush(QColor(0, 255, 255));
253 painter.drawEllipse(toCanvas(estRobotPos), 10, 10);
254 painter.drawLine(toCanvas(estRobotPos), toCanvas(estRobotEnda));
255 painter.setBrush(QColor(255, 255, 0, 25));
256 float posUncertaintyAverage = (poseUncertaintyX + poseUncertaintyY) * 0.5;
257 painter.drawEllipse(toCanvas(estRobotPos),
258 (
int)(posUncertaintyAverage * scaleFactor),
259 (
int)(posUncertaintyAverage * scaleFactor));
265 if (widget.reportPoints->checkState() == Qt::Checked)
268 qpoints.reserve(points.size());
269 for (armarx::Vector2f
const& point : points)
271 qpoints.push_back(toCanvas(point));
275 if (widget.reportEdges->checkState() == Qt::Checked)
278 qedges.reserve(edges.size());
279 for (armarx::LineSegment2D
const& s : edges)
281 QPoint start = toCanvas(s.start);
282 QPoint end = toCanvas(s.end);
283 qedges.push_back(QLine(start, end));
289 float lineWidth = 1.0f;
290 QPen pointPen(QColor(0, 0, 255), lineWidth);
291 painter.setPen(pointPen);
293 painter.drawPoints(qpoints.data(), qpoints.size());
296 QPen edgePen(QColor(0, 255, 0), lineWidth);
297 painter.setPen(edgePen);
298 painter.drawLines(qedges.data(), qedges.size());