Skip to content

Commit

Permalink
Compute initial estimate in simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerKuemmerle committed Feb 22, 2025
1 parent 648b134 commit 7fd25d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
34 changes: 29 additions & 5 deletions g2o/simulator/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,29 @@

#include "simulator.h"

#include <memory>
#include <unordered_set>

#include "g2o/core/estimate_propagator.h"
#include "g2o/core/optimizable_graph.h"

namespace g2o {

namespace {
class G2O_CORE_API SimulationEstimatePropagatorCost
: public EstimatePropagatorCostBase {
public:
double operator()(OptimizableGraph::Edge* edge,
const OptimizableGraph::VertexSet& from,
OptimizableGraph::Vertex* to) const override {
return edge->initialEstimatePossible(from, to);
}
[[nodiscard]] std::string_view name() const override {
return "simulation spanning tree";

Check warning on line 47 in g2o/simulator/simulator.cpp

View check run for this annotation

Codecov / codecov/patch

g2o/simulator/simulator.cpp#L46-L47

Added lines #L46 - L47 were not covered by tests
}
};
} // namespace

void BaseWorldObject::setVertex(
const std::shared_ptr<OptimizableGraph::Vertex>& vertex) {
vertex_ = vertex;
Expand Down Expand Up @@ -96,11 +113,18 @@ void Simulator::finalize() {
}
iter = world_.graph().parameters().erase(iter);
}
// TODO(Rainer): Initial estimate
/* Fails since only implemented on SparseOptimizer
EstimatePropagatorCostOdometry costFunction(&world_.graph());
world_.graph().computeInitialGuess(costFunction);
*/

// Initial estimate
OptimizableGraph::VertexSet fixedVertices;
for (const auto& id_v : world_.graph().vertices()) {
auto v = std::dynamic_pointer_cast<OptimizableGraph::Vertex>(id_v.second);
if (!v || !v->fixed()) continue;
fixedVertices.emplace(std::move(v));
}

SimulationEstimatePropagatorCost propagator;
EstimatePropagator estimatePropagator(&world_.graph());
estimatePropagator.propagate(fixedVertices, propagator);
}

} // namespace g2o
1 change: 1 addition & 0 deletions g2o/simulator/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Robot : public BaseRobot {
pose_ = pose;
auto po = std::make_unique<PoseObject>();
po->vertex()->setEstimate(pose_);
po->vertex()->setFixed(trajectory_.empty());
const int pose_id = world.addWorldObject(std::move(po));
trajectory_.emplace_back(pose_id);
}
Expand Down

0 comments on commit 7fd25d3

Please sign in to comment.