95 lines
2.3 KiB
C++
95 lines
2.3 KiB
C++
#ifndef NAV_MESH_MAIN_H
|
|
#define NAV_MESH_MAIN_H
|
|
|
|
#include "mesh.h"
|
|
#include "filter.h"
|
|
#include <memory>
|
|
#include <thread>
|
|
#include <Indoor/floorplan/v2/FloorplanReader.h>
|
|
|
|
void navMeshMain() {
|
|
|
|
std::string mapFile = "/apps/paper/diss/data/maps/museum31.xml";
|
|
|
|
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(mapFile);
|
|
|
|
NM::NavMeshSettings set;
|
|
MyNavMesh mesh;
|
|
MyNavMeshFactory fac(&mesh, set);
|
|
fac.build(map);
|
|
|
|
const Point3 src(26, 43, 7.5);
|
|
|
|
// add shortest-path to destination
|
|
//const Point3 dst(51, 45, 1.7);
|
|
const Point3 dst(25, 45, 0);
|
|
NM::NavMeshDijkstra::stamp<MyNavMeshTriangle>(mesh, dst);
|
|
|
|
// debug show
|
|
NM::NavMeshDebug dbg;
|
|
dbg.addMesh(mesh);
|
|
//dbg.addDijkstra(mesh);
|
|
dbg.draw();
|
|
|
|
// particle-filter
|
|
const int numParticles = 1000;
|
|
auto init = std::make_unique<MyPFInitFixed>(&mesh, src); // known position
|
|
//auto init = std::make_unique<MyPFInitUniform>(&mesh); // uniform distribution
|
|
auto eval = std::make_unique<MyPFEval>();
|
|
auto trans = std::make_unique<MyPFTrans>(mesh);
|
|
auto resample = std::make_unique<K::ParticleFilterResamplingSimple<MyState>>();
|
|
auto estimate = std::make_unique<K::ParticleFilterEstimationWeightedAverage<MyState>>();
|
|
|
|
// setup
|
|
MyFilter pf(numParticles, std::move(init));
|
|
pf.setEvaluation(std::move(eval));
|
|
pf.setTransition(std::move(trans));
|
|
pf.setResampling(std::move(resample));
|
|
pf.setEstimation(std::move(estimate));
|
|
pf.setNEffThreshold(1);
|
|
|
|
|
|
MyControl ctrl;
|
|
MyObservation obs;
|
|
|
|
//Distribution::Uniform<float> dHead(0, 2*M_PI);
|
|
Distribution::Normal<float> dHead(0, 0.1);
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
|
|
|
ctrl.numStepsSinceLastEval = 1;
|
|
ctrl.headingChangeSinceLastEval = dHead.draw();
|
|
|
|
MyState est = pf.update(&ctrl, obs);
|
|
|
|
ctrl.afterEval();
|
|
|
|
try {
|
|
MyNavMeshLocation loc = mesh.getLocationNearestTo(est.pos.pos);
|
|
auto path = loc.tria->getPathToDestination<MyNavMeshTriangle>(loc.pos);
|
|
dbg.addDijkstra(path);
|
|
} catch (...) {;}
|
|
|
|
const int d = (i * 1) % 360;
|
|
dbg.plot.getView().setCamera(60, d);
|
|
dbg.showParticles(pf.getParticles());
|
|
dbg.setCurPos(est.pos.pos);
|
|
|
|
//dbg.gp.setOutput("/tmp/123/" + std::to_string(i) + ".png");
|
|
//dbg.gp.setTerminal("pngcairo", K::GnuplotSize(60, 30));
|
|
|
|
std::cout << i << std::endl;
|
|
|
|
dbg.draw();
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#endif
|