43int main(
int argc,
char** argv) {
51 bool hasPointDepthSensor;
52 bool hasPointDisparitySensor;
56 std::string outputFilename;
57 arg.
param(
"simSteps", simSteps, 100,
"number of simulation steps");
58 arg.
param(
"nLandmarks", nlandmarks, 1000,
"number of landmarks");
59 arg.
param(
"worldSize", worldSize, 25.0,
"size of the world");
60 arg.
param(
"hasOdom", hasOdom,
false,
"the robot has an odometry");
61 arg.
param(
"hasPointSensor", hasPointSensor,
false,
62 "the robot has a point sensor");
63 arg.
param(
"hasPointDepthSensor", hasPointDepthSensor,
false,
64 "the robot has a point sensor");
65 arg.
param(
"hasPointDisparitySensor", hasPointDisparitySensor,
false,
66 "the robot has a point sensor");
67 arg.
param(
"hasPoseSensor", hasPoseSensor,
false,
68 "the robot has a pose sensor");
69 arg.
param(
"hasCompass", hasCompass,
false,
"the robot has a compass");
70 arg.
param(
"hasGPS", hasGPS,
false,
"the robot has a GPS");
71 arg.
paramLeftOver(
"graph-output", outputFilename,
"simulator_out.g2o",
72 "graph file which will be written",
true);
76 std::mt19937 generator;
79 for (
int i = 0; i < nlandmarks; i++) {
84 landmark->vertex()->setEstimate(Vector3d(x, y, z));
87 Robot3D robot(&world,
"myRobot");
91 ss <<
"-ws" << worldSize;
92 ss <<
"-nl" << nlandmarks;
93 ss <<
"-steps" << simSteps;
97 robot.addSensor(odometrySensor);
101 if (hasPointSensor) {
103 pointSensor->
setFov(M_PI / 4);
104 robot.addSensor(pointSensor);
105 Eigen::Isometry3d cameraPose;
107 R << 0, 0, 1, -1, 0, 0, 0, -1, 0;
110 cameraPose.translation() = Vector3d(0., 0., 0.3);
115 if (hasPointDisparitySensor) {
118 disparitySensor->
setFov(M_PI / 4);
121 robot.addSensor(disparitySensor);
122 Eigen::Isometry3d cameraPose;
124 R << 0, 0, 1, -1, 0, 0, 0, -1, 0;
126 cameraPose.translation() = Vector3d(0., 0., 0.3);
131 if (hasPointDepthSensor) {
133 depthSensor->
setFov(M_PI / 4);
136 robot.addSensor(depthSensor);
137 Eigen::Isometry3d cameraPose;
139 R << 0, 0, 1, -1, 0, 0, 0, -1, 0;
141 cameraPose.translation() = Vector3d(0., 0., 0.3);
148 robot.addSensor(poseSensor);
153#ifdef _POSE_PRIOR_SENSOR
155 robot.addSensor(&posePriorSensor);
157 Eigen::Isometry3d cameraPose;
159 R << 0, 0, 1, -1, 0, 0, 0, -1, 0;
161 cameraPose.translation() = Vector3d(0., 0., 0.3);
166#ifdef _POSE_SENSOR_OFFSET
168 poseSensor.
setFov(M_PI / 4);
171 robot.addSensor(&poseSensor);
173 Eigen::Isometry3d cameraPose;
175 R << 0, 0, 1, -1, 0, 0, 0, -1, 0;
177 cameraPose.translation() = Vector3d(0., 0., 0.3);
183 robot.move(Eigen::Isometry3d::Identity());
184 double pStraight = 0.7;
185 Eigen::Isometry3d moveStraight = Eigen::Isometry3d::Identity();
186 moveStraight.translation() = Vector3d(1., 0., 0.);
188 Eigen::Isometry3d moveLeft = Eigen::Isometry3d::Identity();
189 moveLeft = AngleAxisd(M_PI / 2, Vector3d::UnitZ());
191 Eigen::Isometry3d moveRight = Eigen::Isometry3d::Identity();
192 moveRight = AngleAxisd(-M_PI / 2, Vector3d::UnitZ());
194 Eigen::Matrix3d dtheta = Eigen::Matrix3d::Identity();
195 for (
int i = 0; i < simSteps; i++) {
196 bool boundariesReached =
true;
199 const Eigen::Isometry3d& pose = robot.pose();
200 if (pose.translation().x() < -.5 * worldSize) {
201 dtheta = AngleAxisd(0, Vector3d::UnitZ());
202 }
else if (pose.translation().x() > .5 * worldSize) {
203 dtheta = AngleAxisd(-M_PI, Vector3d::UnitZ());
204 }
else if (pose.translation().y() < -.5 * worldSize) {
205 dtheta = AngleAxisd(M_PI / 2, Vector3d::UnitZ());
206 }
else if (pose.translation().y() > .5 * worldSize) {
207 dtheta = AngleAxisd(-M_PI / 2, Vector3d::UnitZ());
209 boundariesReached =
false;
212 Eigen::Isometry3d move = Eigen::Isometry3d::Identity();
213 if (boundariesReached) {
214 Eigen::Matrix3d mTheta = pose.rotation().inverse() * dtheta;
216 AngleAxisd aa(mTheta);
217 if (aa.angle() < std::numeric_limits<double>::epsilon()) {
218 move.translation() = Vector3d(1., 0., 0.);
222 if (sampled < pStraight)
224 else if (sampled < pStraight + pLeft)
231 robot.relativeMove(move);
238 ofstream testStream(outputFilename.c_str());
239 graph.
save(testStream);