67 double maxSensorRangeLandmarks = 2.5 * stepLen;
69 int landMarksPerSquareMeter = 1;
70 double observationProb = 0.8;
74 Vector2d transNoise(0.05, 0.01);
76 Vector2d landmarkNoise(0.05, 0.05);
78 Vector2d bound(boundArea, boundArea);
81 probLimits.resize(MO_NUM_ELEMS);
82 for (
int i = 0; i < probLimits.size(); ++i)
83 probLimits[i] = (i + 1) / (double) MO_NUM_ELEMS;
87 covariance(0, 0) = transNoise[0]*transNoise[0];
88 covariance(1, 1) = transNoise[1]*transNoise[1];
89 covariance(2, 2) = rotNoise*rotNoise;
90 Matrix3d information = covariance.inverse();
92 SE2 maxStepTransf(stepLen * steps, 0, 0);
97 Simulator::GridPose firstPose;
99 firstPose.truePose = SE2(0,0,0);
100 firstPose.simulatorPose = SE2(0,0,0);
101 poses.push_back(firstPose);
102 cerr <<
"Simulator: sampling nodes ...";
103 while ((
int)poses.size() < numNodes) {
105 for (
int i = 1; i < steps && (int)poses.size() < numNodes; ++i) {
106 Simulator::GridPose nextGridPose =
generateNewPose(poses.back(), SE2(stepLen,0,0), transNoise, rotNoise);
107 poses.push_back(nextGridPose);
109 if ((
int)poses.size() == numNodes)
114 int motionDirection = 0;
115 while (probLimits[motionDirection] < sampleMove && motionDirection+1 < MO_NUM_ELEMS) {
119 SE2 nextMotionStep =
getMotion(motionDirection, stepLen);
120 Simulator::GridPose nextGridPose =
generateNewPose(poses.back(), nextMotionStep, transNoise, rotNoise);
123 SE2 nextStepFinalPose = nextGridPose.
truePose * maxStepTransf;
124 if (fabs(nextStepFinalPose.translation().x()) >= bound[0] || fabs(nextStepFinalPose.translation().y()) >= bound[1]) {
127 for (
int i = 0; i < MO_NUM_ELEMS; ++i) {
129 nextGridPose =
generateNewPose(poses.back(), nextMotionStep, transNoise, rotNoise);
130 nextStepFinalPose = nextGridPose.
truePose * maxStepTransf;
131 if (fabs(nextStepFinalPose.translation().x()) < bound[0] && fabs(nextStepFinalPose.translation().y()) < bound[1])
136 poses.push_back(nextGridPose);
138 cerr <<
"done." << endl;
141 cerr <<
"Simulator: Creating landmarks ... ";
143 for (PosesVector::const_iterator it = poses.begin(); it != poses.end(); ++it) {
144 int ccx = (int)round(it->truePose.translation().x());
145 int ccy = (int)round(it->truePose.translation().y());
146 for (
int a=-landmarksRange; a<=landmarksRange; a++)
147 for (
int b=-landmarksRange; b<=landmarksRange; b++){
151 if (landmarksForCell.size() == 0) {
152 for (
int i = 0; i < landMarksPerSquareMeter; ++i) {
153 Landmark* l =
new Landmark();
158 }
while (
hypot_sqr(offx, offy) < 0.25*0.25);
159 l->truePose[0] = cx + offx;
160 l->truePose[1] = cy + offy;
161 landmarksForCell.push_back(l);
166 cerr <<
"done." << endl;
168 cerr <<
"Simulator: Simulating landmark observations for the poses ... ";
169 double maxSensorSqr = maxSensorRangeLandmarks * maxSensorRangeLandmarks;
171 for (PosesVector::iterator it = poses.begin(); it != poses.end(); ++it) {
172 Simulator::GridPose& pv = *it;
173 int cx = (int)round(it->truePose.translation().x());
174 int cy = (int)round(it->truePose.translation().y());
175 int numGridCells = (int)(maxSensorRangeLandmarks) + 1;
178 SE2 trueInv = pv.truePose.inverse();
180 for (
int xx = cx - numGridCells; xx <= cx + numGridCells; ++xx)
181 for (
int yy = cy - numGridCells; yy <= cy + numGridCells; ++yy) {
183 if (landmarksForCell.size() == 0)
185 for (
size_t i = 0; i < landmarksForCell.size(); ++i) {
186 Landmark* l = landmarksForCell[i];
187 double dSqr =
hypot_sqr(pv.truePose.translation().x() - l->truePose.x(), pv.truePose.translation().y() - l->truePose.y());
188 if (dSqr > maxSensorSqr)
191 if (obs > observationProb)
195 if (l->seenBy.size() == 0) {
196 Vector2d trueObservation = trueInv * l->truePose;
197 Vector2d observation = trueObservation;
200 l->simulatedPose = pv.simulatorPose * observation;
202 l->seenBy.push_back(pv.id);
203 pv.landmarks.push_back(l);
208 cerr <<
"done." << endl;
212 cerr <<
"Simulator: Adding odometry measurements ... ";
213 for (
size_t i = 1; i < poses.size(); ++i) {
214 const GridPose& prev = poses[i-1];
215 const GridPose& p = poses[i];
222 edge.trueTransf = prev.truePose.inverse() * p.truePose;
223 edge.simulatorTransf = prev.simulatorPose.inverse() * p.simulatorPose;
224 edge.information = information;
226 cerr <<
"done." << endl;
232 cerr <<
"Simulator: add landmark observations ... ";
233 Matrix2d covariance; covariance.fill(0.);
234 covariance(0, 0) = landmarkNoise[0]*landmarkNoise[0];
235 covariance(1, 1) = landmarkNoise[1]*landmarkNoise[1];
236 Matrix2d information = covariance.inverse();
238 for (
size_t i = 0; i < poses.size(); ++i) {
239 const GridPose& p = poses[i];
240 for (
size_t j = 0; j < p.landmarks.size(); ++j) {
241 Landmark* l = p.landmarks[j];
242 if (l->seenBy.size() > 0 && l->seenBy[0] == p.id) {
243 landmarks.push_back(*l);
248 for (
size_t i = 0; i < poses.size(); ++i) {
249 const GridPose& p = poses[i];
250 SE2 trueInv = (p.truePose * sensorOffset).inverse();
251 for (
size_t j = 0; j < p.landmarks.size(); ++j) {
252 Landmark* l = p.landmarks[j];
253 Vector2d observation;
254 Vector2d trueObservation = trueInv * l->truePose;
255 observation = trueObservation;
256 if (l->seenBy.size() > 0 && l->seenBy[0] == p.id) {
257 observation = (p.simulatorPose * sensorOffset).inverse() * l->simulatedPose;
269 le.trueMeas = trueObservation;
270 le.simulatorMeas = observation;
271 le.information = information;
274 cerr <<
"done." << endl;
279 for (LandmarkGrid::iterator it = grid.begin(); it != grid.end(); ++it) {
280 for (std::map<int, Simulator::LandmarkPtrVector>::iterator itt = it->second.begin(); itt != it->second.end(); ++itt) {
282 for (
size_t i = 0; i < landmarks.size(); ++i)
LandmarkEdgeVector _landmarkObservations
SE2 getMotion(int motionDirection, double stepLen)
const PosesVector & poses() const
static double uniform_rand(double lowerBndr, double upperBndr)
std::vector< GridPose, Eigen::aligned_allocator< GridPose > > PosesVector
LandmarkVector _landmarks
std::map< int, std::map< int, Simulator::LandmarkPtrVector > > LandmarkGrid
const LandmarkVector & landmarks() const
static double gauss_rand(double mean, double sigma)
std::vector< Landmark, Eigen::aligned_allocator< Landmark > > LandmarkVector
GridPose generateNewPose(const GridPose &prev, const SE2 &trueMotion, const Eigen::Vector2d &transNoise, double rotNoise)
std::vector< Landmark * > LandmarkPtrVector