40 {
42 int nlandmarks;
43 int nSegments;
44 int simSteps;
45 double worldSize;
46 bool hasOdom;
47 bool hasPoseSensor;
48 bool hasPointSensor;
49 bool hasPointBearingSensor;
50 bool hasSegmentSensor;
51 bool hasCompass;
52 bool hasGPS;
53
54 int segmentGridSize;
55 double minSegmentLength, maxSegmentLength;
56
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);
81
83
84 std::mt19937 generator;
87 for (int i = 0; i < nlandmarks; i++) {
91 landmark->vertex()->setEstimate(Vector2d(x, y));
92 world.addWorldObject(landmark);
93 }
94
95 cerr << "nSegments = " << nSegments << endl;
96
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;
104 double xc = ix * (worldSize / segmentGridSize);
105 double yc = iy * (worldSize / segmentGridSize);
106
107 double l2 =
sampleUniform(minSegmentLength, maxSegmentLength, &generator);
108
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;
113
114 segment->vertex()->setEstimateP1(Vector2d(x1, y1));
115 segment->vertex()->setEstimateP2(Vector2d(x2, y2));
116 world.addWorldObject(segment);
117 }
118
119 Robot2D robot(&world,
"myRobot");
120 world.addRobot(&robot);
121
122 stringstream ss;
123 ss << "-ws" << worldSize;
124 ss << "-nl" << nlandmarks;
125 ss << "-steps" << simSteps;
126
127 if (hasOdom) {
129 robot.addSensor(odometrySensor);
131 odomInfo.setIdentity();
132 odomInfo *= 100;
133 odomInfo(2, 2) = 1000;
135 ss << "-odom";
136 }
137
138 if (hasPoseSensor) {
140 robot.addSensor(poseSensor);
142 poseInfo.setIdentity();
143 poseInfo *= 100;
144 poseInfo(2, 2) = 1000;
146 ss << "-pose";
147 }
148
149 if (hasPointSensor) {
151 robot.addSensor(pointSensor);
153 pointInfo.setIdentity();
154 pointInfo *= 100;
156 ss << "-pointXY";
157 }
158
159 if (hasPointBearingSensor) {
162 robot.addSensor(bearingSensor);
164 ss << "-pointBearing";
165 }
166
167 if (hasSegmentSensor) {
171 robot.addSensor(segmentSensor);
173
178 robot.addSensor(segmentSensorLine);
180 m = m * 1000;
181 m(0, 0) *= 10;
183
188 robot.addSensor(segmentSensorPointLine);
189 Matrix3d m3 = segmentSensorPointLine->
information();
190 m3 = m3 * 1000;
191 m3(3, 3) *= 10;
193
194 ss << "-segment2d";
195 }
196
198 double pStraight = 0.7;
201 double pLeft = 0.15;
204
207
208 for (int i = 0; i < simSteps; i++) {
209 cerr << "m";
211 SE2 pose = robot.pose();
212 double dtheta = -100;
213 Vector2d dt;
215 dtheta = 0;
216 }
217
219 dtheta = -M_PI;
220 }
221
223 dtheta = M_PI / 2;
224 }
225
227 dtheta = -M_PI / 2;
228 }
229 if (dtheta < -M_PI) {
230
232 if (sampled < pStraight)
233 move = moveStraight;
234 else if (sampled < pStraight + pLeft)
235 move = moveLeft;
236 else
237 move = moveRight;
238 } else {
239 double mTheta = dtheta - pose.
rotation().angle();
241 if (move.
rotation().angle() < std::numeric_limits<double>::epsilon()) {
243 }
244 }
245 robot.relativeMove(move);
246
247 cerr << "s";
248 robot.sense();
249 }
250
251 ofstream testStream(outputFilename.c_str());
252 graph.
save(testStream);
253
254 return 0;
255}
const InformationType & information()
void setInformation(const InformationType &information_)
Command line parsing of argc and argv.
bool parseArgs(int argc, char **argv, bool exitOnError=true)
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)
void setMinRange(double minRange_)
void setMaxRange(double maxRange_)
const Vector2 & translation() const
translational component
void setRotation(const Rotation2D &R_)
void setTranslation(const Vector2 &t_)
const Rotation2D & rotation() const
rotational component
Jet< T, N > cos(const Jet< T, N > &f)
Jet< T, N > sin(const Jet< T, N > &f)
Jet< T, N > atan2(const Jet< T, N > &g, const Jet< T, N > &f)
double sampleUniform(double min, double max, std::mt19937 *generator)
WorldObject< VertexPointXY > WorldObjectPointXY
WorldObject< VertexSegment2D > WorldObjectSegment2D
Robot< WorldObjectSE2 > Robot2D
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.