41int main(
int argc,
char** argv) {
49 bool hasPointBearingSensor;
53 bool hasSegmentSensor;
56 double minSegmentLength, maxSegmentLength;
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,
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");
68 arg.
param(
"simSteps", simSteps, 100,
"number of simulation steps");
69 arg.
param(
"worldSize", worldSize, 25.0,
"size of the world");
70 arg.
param(
"hasOdom", hasOdom,
false,
"the robot has an odometry");
71 arg.
param(
"hasPointSensor", hasPointSensor,
false,
72 "the robot has a point sensor");
73 arg.
param(
"hasPointBearingSensor", hasPointBearingSensor,
false,
74 "the robot has a point bearing sensor");
75 arg.
param(
"hasPoseSensor", hasPoseSensor,
false,
76 "the robot has a pose sensor");
77 arg.
param(
"hasCompass", hasCompass,
false,
"the robot has a compass");
78 arg.
param(
"hasGPS", hasGPS,
false,
"the robot has a GPS");
79 arg.
param(
"hasSegmentSensor", hasSegmentSensor,
false,
80 "the robot has a segment sensor");
81 arg.
paramLeftOver(
"graph-output", outputFilename,
"simulator_out.g2o",
82 "graph file which will be written",
true);
86 std::mt19937 generator;
89 for (
int i = 0; i < nlandmarks; i++) {
91 double x =
sampleUniform(-.5, .5, &generator) * (worldSize + 5);
92 double y =
sampleUniform(-.5, .5, &generator) * (worldSize + 5);
93 landmark->vertex()->setEstimate(Vector2d(x, y));
97 cerr <<
"nSegments = " << nSegments << endl;
99 for (
int i = 0; i < nSegments; i++) {
101 int ix =
sampleUniform(-segmentGridSize, segmentGridSize, &generator);
102 int iy =
sampleUniform(-segmentGridSize, segmentGridSize, &generator);
104 double th = (M_PI / 2) * ith;
105 th = atan2(sin(th), cos(th));
106 double xc = ix * (worldSize / segmentGridSize);
107 double yc = iy * (worldSize / segmentGridSize);
109 double l2 =
sampleUniform(minSegmentLength, maxSegmentLength, &generator);
111 double x1 = xc + cos(th) * l2;
112 double y1 = yc + sin(th) * l2;
113 double x2 = xc - cos(th) * l2;
114 double y2 = yc - sin(th) * l2;
116 segment->vertex()->setEstimateP1(Vector2d(x1, y1));
117 segment->vertex()->setEstimateP2(Vector2d(x2, y2));
121 Robot2D robot(&world,
"myRobot");
125 ss <<
"-ws" << worldSize;
126 ss <<
"-nl" << nlandmarks;
127 ss <<
"-steps" << simSteps;
131 robot.addSensor(odometrySensor);
133 odomInfo.setIdentity();
135 odomInfo(2, 2) = 5000;
142 robot.addSensor(poseSensor);
144 poseInfo.setIdentity();
146 poseInfo(2, 2) = 5000;
151 if (hasPointSensor) {
153 robot.addSensor(pointSensor);
155 pointInfo.setIdentity();
158 pointSensor->
setFov(0.75 * M_PI);
162 if (hasPointBearingSensor) {
165 robot.addSensor(bearingSensor);
167 ss <<
"-pointBearing";
170 if (hasSegmentSensor) {
171 cerr <<
"creating Segment Sensor" << endl;
173 cerr <<
"segmentSensorCreated" << endl;
176 robot.addSensor(segmentSensor);
183 robot.addSensor(segmentSensorLine);
193 robot.addSensor(segmentSensorPointLine);
194 Matrix3d m3 = segmentSensorPointLine->
information();
203 double pStraight = 0.7;
213 for (
int i = 0; i < simSteps; i++) {
216 SE2 pose = robot.pose();
217 double dtheta = -100;
234 if (dtheta < -M_PI) {
237 if (sampled < pStraight)
239 else if (sampled < pStraight + pLeft)
244 double mTheta = dtheta - pose.
rotation().angle();
246 if (move.
rotation().angle() < std::numeric_limits<double>::epsilon()) {
250 robot.relativeMove(move);
256 ofstream testStream(outputFilename.c_str());
257 graph.
save(testStream);