g2o
sensor_pointxyz.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_pointxyz.h"
28 
29 namespace g2o {
30  using namespace std;
31  using namespace Eigen;
32 
33  // SensorPointXYZ
35  _offsetParam = 0;
36  _information.setIdentity();
37  _information*=1000;
38  _information(2,2)=10;
40  }
41 
43  if (! _robotPoseObject)
44  return false;
45  assert(to && to->vertex());
46  VertexType* v=to->vertex();
47  VertexType::EstimateType pose=v->estimate();
48  VertexType::EstimateType delta = _sensorPose.inverse()*pose;
49  Vector3d translation=delta;
50  double range2=translation.squaredNorm();
51  if (range2>_maxRange2)
52  return false;
53  if (range2<_minRange2)
54  return false;
55  translation.normalize();
56  // the cameras have the z in front
57  double bearing=acos(translation.z());
58  if (fabs(bearing)>_fov)
59  return false;
60  return true;
61  }
62 
64  if (!_offsetParam)
66  assert(world());
68  }
69 
72  e->setMeasurement(e->measurement()+n);
74  }
75 
77  if (! _offsetParam){
78  return;
79  }
81  RobotType* r= dynamic_cast<RobotType*>(robot());
82  std::list<PoseObject*>::reverse_iterator it=r->trajectory().rbegin();
83  int count = 0;
84  while (it!=r->trajectory().rend() && count < 1){
85  if (!_robotPoseObject)
86  _robotPoseObject = *it;
87  it++;
88  count++;
89  }
90  if (!_robotPoseObject)
91  return;
92  _sensorPose = _robotPoseObject->vertex()->estimate()*_offsetParam->offset();
93  for (std::set<BaseWorldObject*>::iterator it=world()->objects().begin();
94  it!=world()->objects().end(); it++){
95  WorldObjectType* o=dynamic_cast<WorldObjectType*>(*it);
96  if (o && isVisible(o)){
97  EdgeType* e=mkEdge(o);
99  if (e && graph()) {
100  graph()->addEdge(e);
102  addNoise(e);
103  }
104  }
105  }
106  }
107 
108 }
bool addParameter(Parameter *p)
Definition: simulator.cpp:102
void addNoise(EdgeType *e)
ParameterSE3Offset * _offsetParam
g2o edge from a track to a point node
const Isometry3D & offset() const
rotation of the offset as 3x3 rotation matrix
GaussianSampler< typename EdgeType::ErrorVector, InformationType > _sampler
Definition: simulator.h:271
RobotPoseType _sensorPose
SampleType generateSample()
Definition: sampler.h:67
virtual void sense()
virtual bool setMeasurementFromState()
bool setParameterId(int argNum, int paramId)
bool isVisible(WorldObjectType *to)
World * world()
Definition: simulator.cpp:69
virtual void setMeasurement(const Vector3D &m)
EIGEN_STRONG_INLINE void setInformation(const InformationType &information)
Definition: base_edge.h:69
TrajectoryType & trajectory()
Definition: simulator.h:119
int id() const
Definition: parameter.h:45
virtual void addParameters()
SensorPointXYZ(const std::string &name_)
OptimizableGraph * graph()
Definition: simulator.cpp:75
BaseRobot * robot()
Definition: simulator.h:129
std::set< BaseWorldObject * > & objects()
Definition: simulator.h:284
virtual bool addEdge(HyperGraph::Edge *e)
VertexType * vertex()
Definition: simulator.h:72
void setInformation(const InformationType &information_)
Definition: simulator.h:221
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75