g2o
sensor_line3d.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 G. Grisetti, R. Kuemmerle, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #include "sensor_line3d.h"
28 
29 namespace g2o {
30  using namespace std;
31 
32  // SensorLine3D
33  SensorLine3D::SensorLine3D(const std::string& name_): BinarySensor<Robot3D, EdgeSE3Line3D, WorldObjectLine3D>(name_) {
34  _offsetParam = 0;
35  _information.setIdentity();
36  _information*=1e9;
37  //_information(2,2)=10;
38  setInformation(_information);
39  }
40 
41  bool SensorLine3D::isVisible(SensorLine3D::WorldObjectType* to){
42  if (! _robotPoseObject)
43  return false;
44  assert(to && to->vertex());
45  VertexType* v=to->vertex();
46  VertexType::EstimateType pose=v->estimate();
47  VertexType::EstimateType delta = _sensorPose.inverse()*pose;
48  Vector3d translation=delta;
49  double range2=translation.squaredNorm();
50  if (range2>_maxRange2)
51  return false;
52  if (range2<_minRange2)
53  return false;
54  translation.normalize();
55  // the cameras have the z in front
56  double bearing=acos(translation.z());
57  if (fabs(bearing)>_fov)
58  return false;
59  return true;
60  }
61 
62  void SensorLine3D::addParameters(){
63  if (!_offsetParam)
64  _offsetParam = new ParameterSE3Offset();
65  assert(world());
66  world()->addParameter(_offsetParam);
67  }
68 
69  void SensorLine3D::addNoise(EdgeType* e){
70  EdgeType::ErrorVector n=_sampler.generateSample();
71  e->setMeasurement(e->measurement()+n);
72  e->setInformation(information());
73  }
74 
75  void SensorLine3D::sense() {
76  if (! _offsetParam){
77  return;
78  }
79  _robotPoseObject=0;
80  RobotType* r= dynamic_cast<RobotType*>(robot());
81  std::list<PoseObject*>::reverse_iterator it=r->trajectory().rbegin();
82  int count = 0;
83  while (it!=r->trajectory().rend() && count < 1){
84  if (!_robotPoseObject)
85  _robotPoseObject = *it;
86  it++;
87  count++;
88  }
89  if (!_robotPoseObject)
90  return;
91  _sensorPose = _robotPoseObject->vertex()->estimate()*_offsetParam->offset();
92  for (std::set<BaseWorldObject*>::iterator it=world()->objects().begin();
93  it!=world()->objects().end(); it++){
94  WorldObjectType* o=dynamic_cast<WorldObjectType*>(*it);
95  if (o && isVisible(o)){
96  EdgeType* e=mkEdge(o);
97  e->setParameterId(0,_offsetParam->id());
98  if (e && graph()) {
99  graph()->addEdge(e);
100  e->setMeasurementFromState();
101  addNoise(e);
102  }
103  }
104  }
105  }
106 
107 }
WorldObject< VertexLine3D > WorldObjectLine3D
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
Definition: protocol.txt:7
Robot< WorldObjectSE3 > Robot3D