41 {
43 int nlandmarks;
44 int simSteps;
45 double worldSize;
46 bool hasOdom;
47 bool hasPoseSensor;
48 bool hasPointSensor;
49 bool hasPointBearingSensor;
50 bool hasCompass;
51 bool hasGPS;
52
53 bool hasSegmentSensor;
54 int nSegments;
55 int segmentGridSize;
56 double minSegmentLength, maxSegmentLength;
57
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");
67
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);
83
85
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));
94 world.addWorldObject(landmark);
95 }
96
97 cerr << "nSegments = " << nSegments << endl;
98
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;
106 double xc = ix * (worldSize / segmentGridSize);
107 double yc = iy * (worldSize / segmentGridSize);
108
109 double l2 =
sampleUniform(minSegmentLength, maxSegmentLength, &generator);
110
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;
115
116 segment->vertex()->setEstimateP1(Vector2d(x1, y1));
117 segment->vertex()->setEstimateP2(Vector2d(x2, y2));
118 world.addWorldObject(segment);
119 }
120
121 Robot2D robot(&world,
"myRobot");
122 world.addRobot(&robot);
123
124 stringstream ss;
125 ss << "-ws" << worldSize;
126 ss << "-nl" << nlandmarks;
127 ss << "-steps" << simSteps;
128
129 if (hasOdom) {
131 robot.addSensor(odometrySensor);
133 odomInfo.setIdentity();
134 odomInfo *= 500;
135 odomInfo(2, 2) = 5000;
137 ss << "-odom";
138 }
139
140 if (hasPoseSensor) {
142 robot.addSensor(poseSensor);
144 poseInfo.setIdentity();
145 poseInfo *= 500;
146 poseInfo(2, 2) = 5000;
148 ss << "-pose";
149 }
150
151 if (hasPointSensor) {
153 robot.addSensor(pointSensor);
155 pointInfo.setIdentity();
156 pointInfo *= 1000;
158 pointSensor->
setFov(0.75 * M_PI);
159 ss << "-pointXY";
160 }
161
162 if (hasPointBearingSensor) {
165 robot.addSensor(bearingSensor);
167 ss << "-pointBearing";
168 }
169
170 if (hasSegmentSensor) {
171 cerr << "creating Segment Sensor" << endl;
173 cerr << "segmentSensorCreated" << endl;
176 robot.addSensor(segmentSensor);
178
183 robot.addSensor(segmentSensorLine);
185 m = m * 1000;
186 m(0, 0) *= 10;
188
193 robot.addSensor(segmentSensorPointLine);
194 Matrix3d m3 = segmentSensorPointLine->
information();
195 m3 = m3 * 1000;
196 m3(2, 2) *= 10;
198
199 ss << "-segment2d";
200 }
201
203 double pStraight = 0.7;
206 double pLeft = 0.15;
209
212
213 for (int i = 0; i < simSteps; i++) {
214 cerr << "m";
216 SE2 pose = robot.pose();
217 double dtheta = -100;
218 Vector2d dt;
220 dtheta = 0;
221 }
222
224 dtheta = -M_PI;
225 }
226
228 dtheta = M_PI / 2;
229 }
230
232 dtheta = -M_PI / 2;
233 }
234 if (dtheta < -M_PI) {
235
237 if (sampled < pStraight)
238 move = moveStraight;
239 else if (sampled < pStraight + pLeft)
240 move = moveLeft;
241 else
242 move = moveRight;
243 } else {
244 double mTheta = dtheta - pose.
rotation().angle();
246 if (move.
rotation().angle() < std::numeric_limits<double>::epsilon()) {
248 }
249 }
250 robot.relativeMove(move);
251
252 cerr << "s";
253 robot.sense();
254 }
255
256 ofstream testStream(outputFilename.c_str());
257 graph.
save(testStream);
258
259 return 0;
260}
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.