00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <uwsim/SceneBuilder.h>
00014 #include <uwsim/osgOceanScene.h>
00015 #include <uwsim/SimulatorConfig.h>
00016 #include <uwsim/SimulatedIAUV.h>
00017 #include <uwsim/URDFRobot.h>
00018 #include <osg/MatrixTransform>
00019 #include <osg/PositionAttitudeTransform>
00020
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 SimulatedIAUV::SimulatedIAUV(SceneBuilder *oscene, Vehicle vehicleChars) :
00086 urdf(new URDFRobot(oscene->scene->getOceanScene(), vehicleChars))
00087 {
00088 name = vehicleChars.name;
00089 baseTransform = new osg::MatrixTransform;
00090
00091 if (urdf->baseTransform != NULL )
00092 {
00093 baseTransform->addChild(urdf->baseTransform);
00094 baseTransform->setName(vehicleChars.name);
00095 }
00096
00097
00098 while (vehicleChars.Vcams.size() > 0)
00099 {
00100 Vcam vcam = vehicleChars.Vcams.front();
00101 OSG_INFO << "Adding a virtual camera " << vcam.name << "..." << std::endl;
00102 vehicleChars.Vcams.pop_front();
00103
00104
00105 osg::ref_ptr < osg::Transform > vMc = (osg::Transform*)new osg::PositionAttitudeTransform;
00106 vMc->asPositionAttitudeTransform()->setPosition(osg::Vec3d(vcam.position[0], vcam.position[1], vcam.position[2]));
00107 vMc->asPositionAttitudeTransform()->setAttitude(
00108 osg::Quat(vcam.orientation[0], osg::Vec3d(1, 0, 0), vcam.orientation[1], osg::Vec3d(0, 1, 0),
00109 vcam.orientation[2], osg::Vec3d(0, 0, 1)));
00110 urdf->link[vcam.link]->asGroup()->addChild(vMc);
00111 camview.push_back(
00112 VirtualCamera(oscene->root, vcam.name, vMc, vcam.resw, vcam.resh, vcam.baseLine, vcam.frameId,
00113 vcam.parameters.get(), 0, vcam.bw));
00114 if (vcam.showpath)
00115 camview[camview.size() - 1].showPath(vcam.showpath);
00116 OSG_INFO << "Done adding a virtual camera..." << std::endl;
00117 }
00118
00119
00120 while (vehicleChars.VRangecams.size() > 0)
00121 {
00122 Vcam vcam = vehicleChars.VRangecams.front();
00123 OSG_INFO << "Adding a virtual camera " << vcam.name << "..." << std::endl;
00124 vehicleChars.VRangecams.pop_front();
00125
00126
00127 osg::ref_ptr < osg::Transform > vMc = (osg::Transform*)new osg::PositionAttitudeTransform;
00128 vMc->asPositionAttitudeTransform()->setPosition(osg::Vec3d(vcam.position[0], vcam.position[1], vcam.position[2]));
00129 vMc->asPositionAttitudeTransform()->setAttitude(
00130 osg::Quat(vcam.orientation[0], osg::Vec3d(1, 0, 0), vcam.orientation[1], osg::Vec3d(0, 1, 0),
00131 vcam.orientation[2], osg::Vec3d(0, 0, 1)));
00132 urdf->link[vcam.link]->asGroup()->addChild(vMc);
00133 camview.push_back(
00134 VirtualCamera(oscene->root, vcam.name, vMc, vcam.resw, vcam.resh, vcam.baseLine, vcam.frameId,
00135 vcam.parameters.get(), 1, 0));
00136 if (vcam.showpath)
00137 camview[camview.size() - 1].showPath(vcam.showpath);
00138 OSG_INFO << "Done adding a virtual camera..." << std::endl;
00139 }
00140
00141
00142 while (vehicleChars.sls_projectors.size() > 0)
00143 {
00144 OSG_INFO << "Adding a structured light projector..." << std::endl;
00145 slProjector slp;
00146 slp = vehicleChars.sls_projectors.front();
00147 vehicleChars.sls_projectors.pop_front();
00148 osg::ref_ptr < osg::Transform > vMp = (osg::Transform*)new osg::PositionAttitudeTransform;
00149 vMp->asPositionAttitudeTransform()->setPosition(osg::Vec3d(slp.position[0], slp.position[1], slp.position[2]));
00150 vMp->asPositionAttitudeTransform()->setAttitude(
00151 osg::Quat(slp.orientation[0], osg::Vec3d(1, 0, 0), slp.orientation[1], osg::Vec3d(0, 1, 0), slp.orientation[2],
00152 osg::Vec3d(0, 0, 1)));
00153 urdf->link[slp.link]->asGroup()->addChild(vMp);
00154
00155 sls_projectors.push_back(VirtualSLSProjector(slp.name, oscene->root,
00156 vMp, slp.image_name, slp.fov, (slp.laser) ? true : false));
00157 camview.push_back(sls_projectors.back().camera);
00158 OSG_INFO << "Done adding a structured light projector..." << std::endl;
00159 }
00160
00161
00162 while (vehicleChars.range_sensors.size() > 0)
00163 {
00164 OSG_INFO << "Adding a virtual range sensor..." << std::endl;
00165 rangeSensor rs;
00166 rs = vehicleChars.range_sensors.front();
00167 vehicleChars.range_sensors.pop_front();
00168 osg::ref_ptr < osg::Transform > vMr = (osg::Transform*)new osg::PositionAttitudeTransform;
00169 vMr->asPositionAttitudeTransform()->setPosition(osg::Vec3d(rs.position[0], rs.position[1], rs.position[2]));
00170 vMr->asPositionAttitudeTransform()->setAttitude(
00171 osg::Quat(rs.orientation[0], osg::Vec3d(1, 0, 0), rs.orientation[1], osg::Vec3d(0, 1, 0), rs.orientation[2],
00172 osg::Vec3d(0, 0, 1)));
00173 urdf->link[rs.link]->asGroup()->addChild(vMr);
00174 range_sensors.push_back(
00175 VirtualRangeSensor(rs.name, oscene->scene->localizedWorld, vMr, rs.range, (rs.visible) ? true : false));
00176 OSG_INFO << "Done adding a virtual range sensor..." << std::endl;
00177 }
00178
00179
00180 while (vehicleChars.imus.size() > 0)
00181 {
00182 OSG_INFO << "Adding an IMU..." << std::endl;
00183 Imu imu;
00184 imu = vehicleChars.imus.front();
00185 vehicleChars.imus.pop_front();
00186 osg::ref_ptr < osg::Transform > vMi = (osg::Transform*)new osg::PositionAttitudeTransform;
00187 vMi->asPositionAttitudeTransform()->setPosition(osg::Vec3d(imu.position[0], imu.position[1], imu.position[2]));
00188 vMi->asPositionAttitudeTransform()->setAttitude(
00189 osg::Quat(imu.orientation[0], osg::Vec3d(1, 0, 0), imu.orientation[1], osg::Vec3d(0, 1, 0), imu.orientation[2],
00190 osg::Vec3d(0, 0, 1)));
00191 urdf->link[imu.link]->getParent(0)->getParent(0)->asGroup()->addChild(vMi);
00192 imus.push_back(InertialMeasurementUnit(imu.name, vMi, oscene->scene->localizedWorld->getMatrix(), imu.std));
00193 OSG_INFO << "Done adding an IMU..." << std::endl;
00194 }
00195
00196
00197 while (vehicleChars.pressure_sensors.size() > 0)
00198 {
00199 OSG_INFO << "Adding a pressure sensor..." << std::endl;
00200 XMLPressureSensor ps;
00201 ps = vehicleChars.pressure_sensors.front();
00202 vehicleChars.pressure_sensors.pop_front();
00203 osg::ref_ptr < osg::Transform > vMs = (osg::Transform*)new osg::PositionAttitudeTransform;
00204 vMs->asPositionAttitudeTransform()->setPosition(osg::Vec3d(ps.position[0], ps.position[1], ps.position[2]));
00205 vMs->asPositionAttitudeTransform()->setAttitude(
00206 osg::Quat(ps.orientation[0], osg::Vec3d(1, 0, 0), ps.orientation[1], osg::Vec3d(0, 1, 0), ps.orientation[2],
00207 osg::Vec3d(0, 0, 1)));
00208 urdf->link[ps.link]->getParent(0)->getParent(0)->asGroup()->addChild(vMs);
00209 pressure_sensors.push_back(PressureSensor(ps.name, vMs, oscene->scene->localizedWorld->getMatrix(), ps.std));
00210 OSG_INFO << "Done adding an Pressure Sensor..." << std::endl;
00211 }
00212
00213
00214 while (vehicleChars.gps_sensors.size() > 0)
00215 {
00216 OSG_INFO << "Adding a gps sensor..." << std::endl;
00217 XMLGPSSensor ps;
00218 ps = vehicleChars.gps_sensors.front();
00219 vehicleChars.gps_sensors.pop_front();
00220 osg::ref_ptr < osg::Transform > vMs = (osg::Transform*)new osg::PositionAttitudeTransform;
00221 vMs->asPositionAttitudeTransform()->setPosition(osg::Vec3d(ps.position[0], ps.position[1], ps.position[2]));
00222 vMs->asPositionAttitudeTransform()->setAttitude(
00223 osg::Quat(ps.orientation[0], osg::Vec3d(1, 0, 0), ps.orientation[1], osg::Vec3d(0, 1, 0), ps.orientation[2],
00224 osg::Vec3d(0, 0, 1)));
00225 urdf->link[ps.link]->getParent(0)->getParent(0)->asGroup()->addChild(vMs);
00226 gps_sensors.push_back(GPSSensor(oscene->scene, ps.name, vMs, oscene->scene->localizedWorld->getMatrix(), ps.std));
00227 OSG_INFO << "Done adding an GPS Sensor..." << std::endl;
00228 }
00229
00230
00231 while (vehicleChars.dvl_sensors.size() > 0)
00232 {
00233 OSG_INFO << "Adding a dvl sensor..." << std::endl;
00234 XMLDVLSensor ps;
00235 ps = vehicleChars.dvl_sensors.front();
00236 vehicleChars.dvl_sensors.pop_front();
00237 osg::ref_ptr < osg::Transform > vMs = (osg::Transform*)new osg::PositionAttitudeTransform;
00238 vMs->asPositionAttitudeTransform()->setPosition(osg::Vec3d(ps.position[0], ps.position[1], ps.position[2]));
00239 vMs->asPositionAttitudeTransform()->setAttitude(
00240 osg::Quat(ps.orientation[0], osg::Vec3d(1, 0, 0), ps.orientation[1], osg::Vec3d(0, 1, 0), ps.orientation[2],
00241 osg::Vec3d(0, 0, 1)));
00242 urdf->link[ps.link]->getParent(0)->getParent(0)->asGroup()->addChild(vMs);
00243 dvl_sensors.push_back(DVLSensor(ps.name, vMs, oscene->scene->localizedWorld->getMatrix(), ps.std));
00244 OSG_INFO << "Done adding an DVL Sensor..." << std::endl;
00245 }
00246
00247
00248 while (vehicleChars.multibeam_sensors.size() > 0)
00249 {
00250 OSG_INFO << "Adding a Multibeam sensor..." << std::endl;
00251 XMLMultibeamSensor MB;
00252 MB = vehicleChars.multibeam_sensors.front();
00253 vehicleChars.multibeam_sensors.pop_front();
00254 osg::ref_ptr < osg::Transform > vMs = (osg::Transform*)new osg::PositionAttitudeTransform;
00255 vMs->asPositionAttitudeTransform()->setPosition(osg::Vec3d(MB.position[0], MB.position[1], MB.position[2]));
00256 vMs->asPositionAttitudeTransform()->setAttitude(
00257 osg::Quat(MB.orientation[0], osg::Vec3d(1, 0, 0), MB.orientation[1], osg::Vec3d(0, 1, 0), MB.orientation[2],
00258 osg::Vec3d(0, 0, 1)));
00259 urdf->link[MB.link]->getParent(0)->getParent(0)->asGroup()->addChild(vMs);
00260 MultibeamSensor mb = MultibeamSensor(oscene->root, MB.name, vMs, MB.initAngle, MB.finalAngle, MB.angleIncr,
00261 MB.range);
00262 multibeam_sensors.push_back(mb);
00263 camview.push_back(mb);
00264 OSG_INFO << "Done adding a Multibeam Sensor..." << std::endl;
00265 }
00266
00267
00268 while (vehicleChars.object_pickers.size() > 0)
00269 {
00270 OSG_INFO << "Adding an object picker..." << std::endl;
00271 rangeSensor rs;
00272 rs = vehicleChars.object_pickers.front();
00273 vehicleChars.object_pickers.pop_front();
00274 osg::ref_ptr < osg::Transform > vMr = (osg::Transform*)new osg::PositionAttitudeTransform;
00275 vMr->asPositionAttitudeTransform()->setPosition(osg::Vec3d(rs.position[0], rs.position[1], rs.position[2]));
00276 vMr->asPositionAttitudeTransform()->setAttitude(
00277 osg::Quat(rs.orientation[0], osg::Vec3d(1, 0, 0), rs.orientation[1], osg::Vec3d(0, 1, 0), rs.orientation[2],
00278 osg::Vec3d(0, 0, 1)));
00279 vMr->setName("ObjectPickerNode");
00280 urdf->link[rs.link]->asGroup()->addChild(vMr);
00281 object_pickers.push_back(ObjectPicker(rs.name, oscene->scene->localizedWorld, vMr, rs.range, true, urdf));
00282 OSG_INFO << "Done adding an object picker..." << std::endl;
00283 }
00284
00285 devices.reset(new SimulatedDevices());
00286 devices->applyConfig(this, vehicleChars, oscene);
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00318 void SimulatedIAUV::setVehiclePosition(double x, double y, double z, double roll, double pitch, double yaw)
00319 {
00320 osg::Matrixd S, T, Rx, Ry, Rz, transform;
00321 T.makeTranslate(x, y, z);
00322 Rx.makeRotate(roll, 1, 0, 0);
00323 Ry.makeRotate(pitch, 0, 1, 0);
00324 Rz.makeRotate(yaw, 0, 0, 1);
00325 S.makeScale(2, 5, 8);
00326 transform = Rz * Ry * Rx * T;
00327 setVehiclePosition(transform);
00328 }
00329
00330 void SimulatedIAUV::setVehiclePosition(osg::Matrixd m)
00331 {
00332 baseTransform->setMatrix(m);
00333 }
00334