49 bool hasPointBearingSensor;
50 bool hasSegmentSensor;
55 double minSegmentLenght, maxSegmentLenght;
57 std::string outputFilename;
58 arg.
param(
"simSteps", simSteps, 100,
"number of simulation steps");
59 arg.
param(
"nLandmarks", nlandmarks, 1000,
"number of landmarks");
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");
64 arg.
param(
"worldSize", worldSize, 25.0,
"size of the world");
65 arg.
param(
"hasOdom", hasOdom,
false,
"the robot has an odometry" );
66 arg.
param(
"hasPointSensor", hasPointSensor,
false,
"the robot has a point sensor" );
67 arg.
param(
"hasPointBearingSensor", hasPointBearingSensor,
false,
"the robot has a point bearing sensor" );
68 arg.
param(
"hasPoseSensor", hasPoseSensor,
false,
"the robot has a pose sensor" );
69 arg.
param(
"hasCompass", hasCompass,
false,
"the robot has a compass");
70 arg.
param(
"hasGPS", hasGPS,
false,
"the robot has a GPS");
71 arg.
param(
"hasSegmentSensor", hasSegmentSensor,
false,
"the robot has a segment sensor" );
72 arg.
paramLeftOver(
"graph-output", outputFilename,
"simulator_out.g2o",
"graph file which will be written",
true);
77 std::mt19937 generator;
80 for (
int i=0; i<nlandmarks; i++){
84 landmark->
vertex()->setEstimate(Vector2d(x,y));
85 world.addWorldObject(landmark);
88 cerr <<
"nSegments = " << nSegments << endl;
90 for (
int i=0; i<nSegments; i++){
92 int ix =
sampleUniform(-segmentGridSize,segmentGridSize, &generator);
93 int iy =
sampleUniform(-segmentGridSize,segmentGridSize, &generator);
95 double th= (
M_PI/2)*ith;
96 th=atan2(sin(th),cos(th));
97 double xc = ix*(worldSize/segmentGridSize);
98 double yc = iy*(worldSize/segmentGridSize);
100 double l2 =
sampleUniform(minSegmentLenght, maxSegmentLenght, &generator);
102 double x1 = xc + cos(th)*l2;
103 double y1 = yc + sin(th)*l2;
104 double x2 = xc - cos(th)*l2;
105 double y2 = yc - sin(th)*l2;
108 segment->
vertex()->setEstimateP1(Vector2d(x1,y1));
109 segment->
vertex()->setEstimateP2(Vector2d(x2,y2));
110 world.addWorldObject(segment);
114 Robot2D robot(&world,
"myRobot");
115 world.addRobot(&robot);
119 ss <<
"-ws" << worldSize;
120 ss <<
"-nl" << nlandmarks;
121 ss <<
"-steps" << simSteps;
125 robot.addSensor(odometrySensor);
127 odomInfo.setIdentity();
136 robot.addSensor(poseSensor);
138 poseInfo.setIdentity();
145 if (hasPointSensor) {
147 robot.addSensor(pointSensor);
149 pointInfo.setIdentity();
155 if (hasPointBearingSensor) {
157 robot.addSensor(bearingSensor);
159 ss <<
"-pointBearing";
162 if (hasSegmentSensor) {
166 robot.addSensor(segmentSensor);
172 robot.addSensor(segmentSensorLine);
181 robot.addSensor(segmentSensorPointLine);
193 double pStraight=0.7;
200 for (
int i=0; i<simSteps; i++){
203 SE2 pose=robot.pose();
224 if (sampled<pStraight)
226 else if (sampled<pStraight+pLeft)
231 double mTheta=dtheta-pose.
rotation().angle();
233 if (move.
rotation().angle()<std::numeric_limits<double>::epsilon()){
237 robot.relativeMove(move);
243 ofstream testStream(outputFilename.c_str());
244 graph.
save(testStream);
void setMinRange(double minRange_)
Command line parsing of argc and argv.
WorldObject< VertexSegment2D > WorldObjectSegment2D
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 Vector2D & translation() const
translational component
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)