38 using namespace Eigen;
40 int main(
int argc,
char** argv) {
48 bool hasPointBearingSensor;
52 bool hasSegmentSensor;
55 double minSegmentLenght, maxSegmentLenght;
58 std::string outputFilename;
59 arg.
param(
"nlandmarks", nlandmarks, 100,
"number of landmarks in the map");
60 arg.
param(
"nSegments", nSegments, 1000,
"number of segments");
61 arg.
param(
"segmentGridSize", segmentGridSize, 50,
"number of cells of the grid where to align the segments");
62 arg.
param(
"minSegmentLenght", minSegmentLenght, 0.5,
"minimal lenght of a segment in the world");
63 arg.
param(
"maxSegmentLenght", maxSegmentLenght, 3,
"maximal lenght of a segment in the world");
65 arg.
param(
"simSteps", simSteps, 100,
"number of simulation steps");
66 arg.
param(
"worldSize", worldSize, 25.0,
"size of the world");
67 arg.
param(
"hasOdom", hasOdom,
false,
"the robot has an odometry" );
68 arg.
param(
"hasPointSensor", hasPointSensor,
false,
"the robot has a point sensor" );
69 arg.
param(
"hasPointBearingSensor", hasPointBearingSensor,
false,
"the robot has a point bearing sensor" );
70 arg.
param(
"hasPoseSensor", hasPoseSensor,
false,
"the robot has a pose sensor" );
71 arg.
param(
"hasCompass", hasCompass,
false,
"the robot has a compass");
72 arg.
param(
"hasGPS", hasGPS,
false,
"the robot has a GPS");
73 arg.
param(
"hasSegmentSensor", hasSegmentSensor,
false,
"the robot has a segment sensor" );
74 arg.
paramLeftOver(
"graph-output", outputFilename,
"simulator_out.g2o",
"graph file which will be written",
true);
79 std::mt19937 generator;
82 for (
int i=0; i<nlandmarks; i++){
86 landmark->
vertex()->setEstimate(Vector2d(x,y));
90 cerr <<
"nSegments = " << nSegments << endl;
92 for (
int i=0; i<nSegments; i++){
94 int ix =
sampleUniform(-segmentGridSize,segmentGridSize, &generator);
95 int iy =
sampleUniform(-segmentGridSize,segmentGridSize, &generator);
97 double th= (
M_PI/2)*ith;
98 th=atan2(sin(th),cos(th));
99 double xc = ix*(worldSize/segmentGridSize);
100 double yc = iy*(worldSize/segmentGridSize);
102 double l2 =
sampleUniform(minSegmentLenght, maxSegmentLenght, &generator);
104 double x1 = xc + cos(th)*l2;
105 double y1 = yc + sin(th)*l2;
106 double x2 = xc - cos(th)*l2;
107 double y2 = yc - sin(th)*l2;
110 segment->
vertex()->setEstimateP1(Vector2d(x1,y1));
111 segment->
vertex()->setEstimateP2(Vector2d(x2,y2));
119 Robot2D robot(&world,
"myRobot");
124 ss <<
"-ws" << worldSize;
125 ss <<
"-nl" << nlandmarks;
126 ss <<
"-steps" << simSteps;
132 odomInfo.setIdentity();
143 poseInfo.setIdentity();
150 if (hasPointSensor) {
154 pointInfo.setIdentity();
161 if (hasPointBearingSensor) {
165 ss <<
"-pointBearing";
168 if (hasSegmentSensor) {
169 cerr <<
"creating Segment Sensor" << endl;
171 cerr <<
"segmentSensorCreated" << endl;
200 double pStraight=0.7;
207 for (
int i=0; i<simSteps; i++){
231 if (sampled<pStraight)
233 else if (sampled<pStraight+pLeft)
238 double mTheta=dtheta-pose.
rotation().angle();
240 if (move.
rotation().angle()<std::numeric_limits<double>::epsilon()){
250 ofstream testStream(outputFilename.c_str());
251 graph.
save(testStream);
void setMinRange(double minRange_)
Command line parsing of argc and argv.
WorldObject< VertexSegment2D > WorldObjectSegment2D
bool addSensor(BaseSensor *sensor)
bool addRobot(BaseRobot *robot)
int main(int argc, char **argv)
WorldObject< VertexPointXY > WorldObjectPointXY
void setMaxRange(double maxRange_)
bool parseArgs(int argc, char **argv, bool exitOnError=true)
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
const Eigen::Rotation2Dd & rotation() const
rotational component
const InformationType & information()
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
const PoseType & pose() const
virtual void relativeMove(const PoseType &movement_)
bool addWorldObject(BaseWorldObject *worldObject)
const Vector2D & translation() const
translational component
virtual void move(const PoseType &pose_)
void setInformation(const InformationType &information_)
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
void setTranslation(const Vector2D &t_)
void setRotation(const Eigen::Rotation2Dd &R_)
double sampleUniform(double min, double max, std::mt19937 *generator)