worked on grid-walker
started adding code for synthetic sensor simulation based on given paths
This commit is contained in:
70
synthetic/SyntheticWalker.h
Normal file
70
synthetic/SyntheticWalker.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef SYNTHETICWALKER_H
|
||||
#define SYNTHETICWALKER_H
|
||||
|
||||
#include "SyntheticPath.h"
|
||||
|
||||
/** walk along a path using a known walking speed */
|
||||
class SyntheticWalker {
|
||||
|
||||
public:
|
||||
|
||||
class Listener {
|
||||
public:
|
||||
virtual void onWalk(Timestamp walkedTime, float walkedDistance, const Point3 curPos) = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
/** the path to walk along */
|
||||
SyntheticPath path;
|
||||
|
||||
/** walking-speed in meter per sec */
|
||||
float walkSpeed_meterPerSec = 1.2;
|
||||
|
||||
/** adjusted while walking */
|
||||
float walkedDistance = 0;
|
||||
|
||||
/** adjusted while walking */
|
||||
Timestamp walkedTime;
|
||||
|
||||
/** the listener to inform */
|
||||
std::vector<Listener*> listeners;
|
||||
|
||||
const char* name = "SynWalker";
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
SyntheticWalker(SyntheticPath path) : path(path) {
|
||||
;
|
||||
}
|
||||
|
||||
/** attach a new listener */
|
||||
void addListener(Listener* l) {
|
||||
this->listeners.push_back(l);
|
||||
}
|
||||
|
||||
/** increment the walk */
|
||||
void tick(const Timestamp timePassed) {
|
||||
|
||||
// update time
|
||||
this->walkedTime += timePassed;
|
||||
|
||||
// update the walked distance using the walking speed
|
||||
this->walkedDistance += walkSpeed_meterPerSec * timePassed.sec();
|
||||
|
||||
// get the current position along the path
|
||||
const Point3 curPosOnPath = path.getPosAfterDistance(this->walkedDistance);
|
||||
|
||||
Log::add(name, "walkTime: " + std::to_string(walkedTime.sec()) + " walkDistance: " + std::to_string(walkedDistance) + " -> " + curPosOnPath.asString() );
|
||||
|
||||
// inform listener
|
||||
for (Listener* l : listeners) {l->onWalk(walkedTime, walkedDistance, curPosOnPath);}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SYNTHETICWALKER_H
|
||||
Reference in New Issue
Block a user