18 #ifndef OPEN_KARTO_MAPPER_H 19 #define OPEN_KARTO_MAPPER_H 40 virtual void Info(
const std::string& ) {};
52 virtual void Debug(
const std::string& ) {};
120 Update(rPose1, rPose2, rCovariance);
150 m_Covariance = rotationMatrix * rCovariance * rotationMatrix.
Transpose();
177 return m_PoseDifference;
232 inline const std::vector<Edge<T>*>&
GetEdges()
const 252 std::vector<Vertex<T>*> vertices;
280 m_Edges.push_back(pEdge);
308 m_pSource->AddEdge(
this);
309 m_pTarget->AddEdge(
this);
320 if (m_pLabel != NULL)
448 typedef std::map<Name, std::vector<Vertex<T>*> >
VertexMap;
474 m_Vertices[rName].push_back(pVertex);
483 m_Edges.push_back(pEdge);
491 forEachAs(
typename VertexMap, &m_Vertices, indexIter)
512 inline const std::vector<Edge<T>*>&
GetEdges()
const 609 return m_pLoopScanMatcher;
675 Pose2 ComputeWeightedMean(
const Pose2Vector& rMeans,
const std::vector<Matrix3>& rCovariances)
const;
686 const Name& rSensorName,
744 virtual void Compute() = 0;
750 virtual const IdPoseVector& GetCorrections()
const = 0;
818 assert(resolution != 0.0);
821 kt_int32u borderSize = GetHalfKernelSize(smearDeviation, resolution) + 1;
866 assert(m_pKernel != NULL);
868 int gridIndex = GridIndex(rGridPoint);
877 for (
kt_int32s j = -halfKernel; j <= halfKernel; j++)
881 kt_int32s kernelConstant = (halfKernel) + m_KernelSize * (j + halfKernel);
886 for (
kt_int32s i = -halfKernel; i <= halfKernel; i++)
888 kt_int32s kernelArrayIndex = i + kernelConstant;
890 kt_int8u kernelValue = m_pKernel[kernelArrayIndex];
891 if (kernelValue > pGridAdr[i])
894 pGridAdr[i] = kernelValue;
911 :
Grid<
kt_int8u>(width + borderSize * 2, height + borderSize * 2)
912 , m_SmearDeviation(smearDeviation)
915 GetCoordinateConverter()->SetScale(1.0 / resolution);
931 assert(resolution != 0.0);
932 assert(m_SmearDeviation != 0.0);
936 const kt_double MIN_SMEAR_DISTANCE_DEVIATION = 0.5 * resolution;
937 const kt_double MAX_SMEAR_DISTANCE_DEVIATION = 10 * resolution;
940 if (!
math::InRange(m_SmearDeviation, MIN_SMEAR_DISTANCE_DEVIATION, MAX_SMEAR_DISTANCE_DEVIATION))
942 std::stringstream error;
943 error <<
"Mapper Error: Smear deviation too small: Must be between " 944 << MIN_SMEAR_DISTANCE_DEVIATION
946 << MAX_SMEAR_DISTANCE_DEVIATION;
947 throw std::runtime_error(error.str());
953 m_KernelSize = 2 * GetHalfKernelSize(m_SmearDeviation, resolution) + 1;
956 m_pKernel =
new kt_int8u[m_KernelSize * m_KernelSize];
957 if (m_pKernel == NULL)
959 throw std::runtime_error(
"Unable to allocate memory for kernel!");
964 for (
kt_int32s i = -halfKernel; i <= halfKernel; i++)
966 for (
kt_int32s j = -halfKernel; j <= halfKernel; j++)
969 kt_double distanceFromMean = _hypot(i * resolution, j * resolution);
971 kt_double distanceFromMean = hypot(i * resolution, j * resolution);
973 kt_double z = exp(-0.5 * pow(distanceFromMean / m_SmearDeviation, 2));
976 assert(
math::IsUpTo(kernelValue, static_cast<kt_int32u>(255)));
978 int kernelArrayIndex = (i + halfKernel) + m_KernelSize * (j + halfKernel);
979 m_pKernel[kernelArrayIndex] =
static_cast<kt_int8u>(kernelValue);
993 assert(resolution != 0.0);
1054 kt_bool doRefineMatch =
true);
1073 const Pose2& rSearchCenter,
1093 void ComputePositionalCovariance(
const Pose2& rBestPose,
1095 const Pose2& rSearchCenter,
1110 void ComputeAngularCovariance(
const Pose2& rBestPose,
1112 const Pose2& rSearchCenter,
1123 return m_pCorrelationGrid;
1163 : m_pMapper(pMapper)
1164 , m_pCorrelationGrid(NULL)
1165 , m_pSearchSpaceProbs(NULL)
1166 , m_pGridLookup(NULL)
1197 : m_RunningBufferMaximumSize(runningBufferMaximumSize)
1198 , m_RunningBufferMaximumDistance(runningBufferMaximumDistance)
1217 void RegisterSensor(
const Name& rSensorName);
1233 std::vector<Name> deviceNames;
1236 deviceNames.push_back(iter->first);
1321 if (m_ScanManagers.find(rSensorName) != m_ScanManagers.end())
1323 return m_ScanManagers[rSensorName];
1517 Mapper(
const std::string& rName);
1529 void Initialize(
kt_double rangeThreshold);
1591 virtual ScanMatcher* GetSequentialScanMatcher()
const;
1605 return m_pMapperSensorManager;
1615 return m_pGraph->TryCloseLoop(pScan, rSensorName);
1619 void InitializeParameters();
1638 void FireInfo(
const std::string& rInfo)
const;
1644 void FireDebug(
const std::string& rInfo)
const;
1650 void FireLoopClosureCheck(
const std::string& rInfo)
const;
1656 void FireBeginLoopClosure(
const std::string& rInfo)
const;
1662 void FireEndLoopClosure(
const std::string& rInfo)
const;
1887 bool getParamUseScanMatching();
1888 bool getParamUseScanBarycenter();
1889 double getParamMinimumTimeInterval();
1890 double getParamMinimumTravelDistance();
1891 double getParamMinimumTravelHeading();
1892 int getParamScanBufferSize();
1893 double getParamScanBufferMaximumScanDistance();
1894 double getParamLinkMatchMinimumResponseFine();
1895 double getParamLinkScanMaximumDistance();
1896 double getParamLoopSearchMaximumDistance();
1897 bool getParamDoLoopClosing();
1898 int getParamLoopMatchMinimumChainSize();
1899 double getParamLoopMatchMaximumVarianceCoarse();
1900 double getParamLoopMatchMinimumResponseCoarse();
1901 double getParamLoopMatchMinimumResponseFine();
1904 double getParamCorrelationSearchSpaceDimension();
1905 double getParamCorrelationSearchSpaceResolution();
1906 double getParamCorrelationSearchSpaceSmearDeviation();
1909 double getParamLoopSearchSpaceDimension();
1910 double getParamLoopSearchSpaceResolution();
1911 double getParamLoopSearchSpaceSmearDeviation();
1914 double getParamDistanceVariancePenalty();
1915 double getParamAngleVariancePenalty();
1916 double getParamFineSearchAngleOffset();
1917 double getParamCoarseSearchAngleOffset();
1918 double getParamCoarseAngleResolution();
1919 double getParamMinimumAnglePenalty();
1920 double getParamMinimumDistancePenalty();
1921 bool getParamUseResponseExpansion();
1925 void setParamUseScanMatching(
bool b);
1926 void setParamUseScanBarycenter(
bool b);
1927 void setParamMinimumTimeInterval(
double d);
1928 void setParamMinimumTravelDistance(
double d);
1929 void setParamMinimumTravelHeading(
double d);
1930 void setParamScanBufferSize(
int i);
1931 void setParamScanBufferMaximumScanDistance(
double d);
1932 void setParamLinkMatchMinimumResponseFine(
double d);
1933 void setParamLinkScanMaximumDistance(
double d);
1934 void setParamLoopSearchMaximumDistance(
double d);
1935 void setParamDoLoopClosing(
bool b);
1936 void setParamLoopMatchMinimumChainSize(
int i);
1937 void setParamLoopMatchMaximumVarianceCoarse(
double d);
1938 void setParamLoopMatchMinimumResponseCoarse(
double d);
1939 void setParamLoopMatchMinimumResponseFine(
double d);
1942 void setParamCorrelationSearchSpaceDimension(
double d);
1943 void setParamCorrelationSearchSpaceResolution(
double d);
1944 void setParamCorrelationSearchSpaceSmearDeviation(
double d);
1947 void setParamLoopSearchSpaceDimension(
double d);
1948 void setParamLoopSearchSpaceResolution(
double d);
1949 void setParamLoopSearchSpaceSmearDeviation(
double d);
1952 void setParamDistanceVariancePenalty(
double d);
1953 void setParamAngleVariancePenalty(
double d);
1954 void setParamFineSearchAngleOffset(
double d);
1955 void setParamCoarseSearchAngleOffset(
double d);
1956 void setParamCoarseAngleResolution(
double d);
1957 void setParamMinimumAnglePenalty(
double d);
1958 void setParamMinimumDistancePenalty(
double d);
1959 void setParamUseResponseExpansion(
bool b);
1963 #endif // OPEN_KARTO_MAPPER_H CorrelationGrid(kt_int32u width, kt_int32u height, kt_int32u borderSize, kt_double resolution, kt_double smearDeviation)
std::map< Name, ScanManager * > ScanManagerMap
ScanMatcher * m_pSequentialScanMatcher
std::vector< Vertex< T > * > GetAdjacentVertices() const
kt_int32s GetStateId() const
GraphTraversal(Graph< T > *pGraph)
virtual ~CorrelationGrid()
Parameter< kt_double > * m_pLinkScanMaximumDistance
virtual void Info(const std::string &)
kt_double GetHeading() const
kt_double Round(kt_double value)
kt_bool TryCloseLoop(LocalizedRangeScan *pScan, const Name &rSensorName)
virtual void AddNode(Vertex< LocalizedRangeScan > *)
Parameter< kt_double > * m_pCoarseAngleResolution
Parameter< kt_double > * m_pLoopMatchMaximumVarianceCoarse
std::vector< Vector2< kt_double > > PointVectorDouble
Parameter< kt_double > * m_pMinimumTravelHeading
virtual void EndLoopClosure(const std::string &)
#define forEachAs(listtype, list, iter)
void AddEdge(Edge< T > *pEdge)
Parameter< kt_double > * m_pMinimumAnglePenalty
MapperSensorManager * GetMapperSensorManager() const
std::vector< MapperListener * > m_Listeners
virtual void RemoveNode(kt_int32s)
Rectangle2< kt_int32s > m_Roi
virtual void RemoveConstraint(kt_int32s, kt_int32s)
virtual ~GraphTraversal()
std::vector< Name > GetSensorNames()
virtual void LoopClosureCheck(const std::string &)
Parameter< kt_double > * m_pLoopSearchSpaceSmearDeviation
void Update(const Pose2 &rPose1, const Pose2 &rPose2, const Matrix3 &rCovariance)
const Matrix3 & GetCovariance()
Parameter< kt_int32u > * m_pLoopMatchMinimumChainSize
Parameter< kt_double > * m_pCorrelationSearchSpaceResolution
Parameter< kt_double > * m_pMinimumDistancePenalty
void AddVertex(const Name &rName, Vertex< T > *pVertex)
virtual void AddConstraint(Edge< LocalizedRangeScan > *)
CorrelationGrid * GetCorrelationGrid() const
Parameter< kt_double > * m_pDistanceVariancePenalty
Matrix3 Transpose() const
Parameter< kt_bool > * m_pUseScanMatching
#define forEach(listtype, list)
kt_double m_SmearDeviation
void SetROI(const Rectangle2< kt_int32s > &roi)
const Rectangle2< kt_int32s > & GetROI() const
MapperSensorManager * m_pMapperSensorManager
kt_int32u m_RunningBufferMaximumSize
GraphTraversal< LocalizedRangeScan > * m_pTraversal
Parameter< kt_bool > * m_pDoLoopClosing
Parameter< kt_double > * m_pFineSearchAngleOffset
Parameter< kt_double > * m_pScanBufferMaximumScanDistance
ScanSolver * m_pScanOptimizer
virtual void Debug(const std::string &)
Parameter< kt_double > * m_pLoopSearchSpaceDimension
void SmearPoint(const Vector2< kt_int32s > &rGridPoint)
const Name & GetSensorName() const
ScanMatcher * GetLoopScanMatcher() const
Parameter< kt_double > * m_pMinimumTravelDistance
std::vector< Edge< T > * > m_Edges
void AddEdge(Edge< T > *pEdge)
void SetUseScanMatching(kt_bool val)
std::vector< Pose2 > Pose2Vector
const VertexMap & GetVertices() const
virtual kt_int32s GridIndex(const Vector2< kt_int32s > &rGrid, kt_bool boundaryCheck=true) const
virtual ~MapperSensorManager()
ScanMatcher(Mapper *pMapper)
kt_bool InRange(const T &value, const T &a, const T &b)
kt_double m_RunningBufferMaximumDistance
const std::vector< Edge< T > * > & GetEdges() const
#define const_forEach(listtype, list)
virtual void BeginLoopClosure(const std::string &)
GridIndexLookup< kt_int8u > * m_pGridLookup
static CorrelationGrid * CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution, kt_double smearDeviation)
CorrelationGrid * m_pCorrelationGrid
Parameter< kt_double > * m_pLoopSearchSpaceResolution
Parameter< kt_double > * m_pCorrelationSearchSpaceDimension
MapperSensorManager(kt_int32u runningBufferMaximumSize, kt_double runningBufferMaximumDistance)
LocalizedRangeScan * GetScan(kt_int32s id)
std::vector< std::pair< kt_int32s, Pose2 > > IdPoseVector
Parameter< kt_double > * m_pLinkMatchMinimumResponseFine
Vertex< LocalizedRangeScan > * GetVertex(LocalizedRangeScan *pScan)
ScanMatcher * m_pLoopScanMatcher
void SetLabel(EdgeLabel *pLabel)
ScanManagerMap m_ScanManagers
Grid< kt_double > * m_pSearchSpaceProbs
std::map< Name, std::vector< Vertex< T > * > > VertexMap
static kt_int32s GetHalfKernelSize(kt_double smearDeviation, kt_double resolution)
Edge(Vertex< T > *pSource, Vertex< T > *pTarget)
Parameter< kt_double > * m_pCorrelationSearchSpaceSmearDeviation
Vertex< T > * GetSource() const
const std::vector< Edge< T > * > & GetEdges() const
Vertex< T > * GetTarget() const
virtual kt_int32s GridIndex(const Vector2< kt_int32s > &rGrid, kt_bool boundaryCheck=true) const
Parameter< kt_double > * m_pLoopMatchMinimumResponseCoarse
std::vector< LocalizedRangeScan * > m_Scans
LinkInfo(const Pose2 &rPose1, const Pose2 &rPose2, const Matrix3 &rCovariance)
Parameter< kt_double > * m_pCoarseSearchAngleOffset
Parameter< kt_double > * m_pLoopSearchMaximumDistance
Parameter< kt_double > * m_pAngleVariancePenalty
virtual void CalculateKernel()
Parameter< kt_double > * m_pMinimumTimeInterval
Parameter< kt_bool > * m_pUseResponseExpansion
Parameter< kt_int32u > * m_pScanBufferSize
kt_bool IsUpTo(const T &value, const T &maximum)
std::vector< Edge< T > * > m_Edges
ScanManager * GetScanManager(LocalizedRangeScan *pScan)
std::vector< LocalizedRangeScan * > LocalizedRangeScanVector
ScanManager * GetScanManager(const Name &rSensorName)
Parameter< kt_bool > * m_pUseScanBarycenter
const Pose2 & GetPoseDifference()
Parameter< kt_double > * m_pLoopMatchMinimumResponseFine
void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)