40int main(
int argc,
char** argv) {
49 bool hasPointBearingSensor;
50 bool hasSegmentSensor;
55 double minSegmentLength, maxSegmentLength;
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,
62 "number of cells of the grid where to align the segments");
63 arg.
param(
"minSegmentLength", minSegmentLength, 0.5,
64 "minimal Length of a segment in the world");
65 arg.
param(
"maxSegmentLength", maxSegmentLength, 3,
66 "maximal Length of a segment in the world");
67 arg.
param(
"worldSize", worldSize, 25.0,
"size of the world");
68 arg.
param(
"hasOdom", hasOdom,
false,
"the robot has an odometry");
69 arg.
param(
"hasPointSensor", hasPointSensor,
false,
70 "the robot has a point sensor");
71 arg.
param(
"hasPointBearingSensor", hasPointBearingSensor,
false,
72 "the robot has a point bearing sensor");
73 arg.
param(
"hasPoseSensor", hasPoseSensor,
false,
74 "the robot has a pose sensor");
75 arg.
param(
"hasCompass", hasCompass,
false,
"the robot has a compass");
76 arg.
param(
"hasGPS", hasGPS,
false,
"the robot has a GPS");
77 arg.
param(
"hasSegmentSensor", hasSegmentSensor,
false,
78 "the robot has a segment sensor");
79 arg.
paramLeftOver(
"graph-output", outputFilename,
"simulator_out.g2o",
80 "graph file which will be written",
true);
84 std::mt19937 generator;
87 for (
int i = 0; i < nlandmarks; i++) {
91 landmark->vertex()->setEstimate(Vector2d(x, y));
95 cerr <<
"nSegments = " << nSegments << endl;
97 for (
int i = 0; i < nSegments; i++) {
99 int ix =
sampleUniform(-segmentGridSize, segmentGridSize, &generator);
100 int iy =
sampleUniform(-segmentGridSize, segmentGridSize, &generator);
102 double th = (M_PI / 2) * ith;
103 th = atan2(sin(th), cos(th));
104 double xc = ix * (worldSize / segmentGridSize);
105 double yc = iy * (worldSize / segmentGridSize);
107 double l2 =
sampleUniform(minSegmentLength, maxSegmentLength, &generator);
109 double x1 = xc + cos(th) * l2;
110 double y1 = yc + sin(th) * l2;
111 double x2 = xc - cos(th) * l2;
112 double y2 = yc - sin(th) * l2;
114 segment->vertex()->setEstimateP1(Vector2d(x1, y1));
115 segment->vertex()->setEstimateP2(Vector2d(x2, y2));
119 Robot2D robot(&world,
"myRobot");
123 ss <<
"-ws" << worldSize;
124 ss <<
"-nl" << nlandmarks;
125 ss <<
"-steps" << simSteps;
129 robot.addSensor(odometrySensor);
131 odomInfo.setIdentity();
133 odomInfo(2, 2) = 1000;
140 robot.addSensor(poseSensor);
142 poseInfo.setIdentity();
144 poseInfo(2, 2) = 1000;
149 if (hasPointSensor) {
151 robot.addSensor(pointSensor);
153 pointInfo.setIdentity();
159 if (hasPointBearingSensor) {
162 robot.addSensor(bearingSensor);
164 ss <<
"-pointBearing";
167 if (hasSegmentSensor) {
171 robot.addSensor(segmentSensor);
178 robot.addSensor(segmentSensorLine);
188 robot.addSensor(segmentSensorPointLine);
189 Matrix3d m3 = segmentSensorPointLine->
information();
198 double pStraight = 0.7;
208 for (
int i = 0; i < simSteps; i++) {
211 SE2 pose = robot.pose();
212 double dtheta = -100;
229 if (dtheta < -M_PI) {
232 if (sampled < pStraight)
234 else if (sampled < pStraight + pLeft)
239 double mTheta = dtheta - pose.
rotation().angle();
241 if (move.
rotation().angle() < std::numeric_limits<double>::epsilon()) {
245 robot.relativeMove(move);
251 ofstream testStream(outputFilename.c_str());
252 graph.
save(testStream);