1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef MULTIKALMANBALLLOCATOR_H
#define MULTIKALMANBALLLOCATOR_H

#include <ModuleFramework/Module.h>
#include <Eigen/StdVector> //necessary for alignement in std::vector to work

// representations
#include "Representations/Perception/MultiBallPercept.h"
#include "Representations/Modeling/BallModel.h"
#include "Representations/Modeling/BodyState.h"
#include "Representations/Modeling/PlayerInfo.h"

#include "Representations/Modeling/OdometryData.h"
#include "Representations/Modeling/KinematicChain.h"
#include "Representations/Infrastructure/FrameInfo.h"
#include "Representations/Motion/MotionStatus.h"

#include "Representations/Perception/CameraMatrix.h"
#include "Representations/Infrastructure/FieldInfo.h"

// tools
#include "BallHypothesis.h"
#include "UpdateAssociationFunctions.h"

// debug
#include "Tools/Debug/DebugDrawings.h"
#include "Tools/Debug/DebugRequest.h"
#include "Tools/Debug/DebugParameterList.h"
#include "Tools/Debug/DebugPlot.h"
#include "Tools/Debug/Color.h"


//////////////////// BEGIN MODULE INTERFACE DECLARATION ////////////////////

BEGIN_DECLARE_MODULE(MultiKalmanBallLocator)

// debug stuff
  PROVIDE(DebugDrawings)
  PROVIDE(DebugRequest)
  PROVIDE(DebugParameterList)
  PROVIDE(DebugPlot)

  REQUIRE(FieldInfo)

  REQUIRE(BodyState)
  REQUIRE(PlayerInfo)
  REQUIRE(FrameInfo)
  REQUIRE(OdometryData)

// for preview stuff
  REQUIRE(MotionStatus)
  REQUIRE(KinematicChain)

  REQUIRE(MultiBallPercept)

// for extended kalman filter
  REQUIRE(CameraInfo)
  REQUIRE(CameraInfoTop)
  REQUIRE(CameraMatrix)
  REQUIRE(CameraMatrixTop)

  PROVIDE(BallModel)
END_DECLARE_MODULE(MultiKalmanBallLocator)


//////////////////// END MODULE INTERFACE DECLARATION //////////////////////

class MultiKalmanBallLocator : private MultiKalmanBallLocatorBase
{
public:
    MultiKalmanBallLocator();
    virtual ~MultiKalmanBallLocator();

    virtual void execute();

// from other kalman filter ball locator
private:
    OdometryData lastRobotOdometry;
    FrameInfo    lastFrameInfo;

private:
    typedef std::vector<BallHypothesis, Eigen::aligned_allocator<BallHypothesis> > Filters;
    Filters filter;
    Filters::const_iterator bestModel;

    // TODO: does it make sense to use the numerical epsilon: std::numeric_limits<double>::epsilon() or std::numeric_limits<float>::epsilon()?
    // TODO: or is this value specific to the algorithms? E.g. ball speed below 1mm/s is considered 0.
    const double epsilon=10e-6;

public:
    const Filters& get_filter() {
        return filter;
    }

    void clear_filter() {
        filter.clear();
    }

private:
    void updateByPerceptsCool();
    void updateByPerceptsNormal();
    void updateByPerceptsGreedy(CameraInfo::CameraID camera);

    void applyOdometryOnFilterState(ExtendedKalmanFilter4d& filter);

    void predict(ExtendedKalmanFilter4d& filter, double dt) const;

    Filters::const_iterator selectBestModel() const;
    Filters::const_iterator selectBestModelBasedOnCovariance() const;

    void provideBallModel(const BallHypothesis &model);

    /*    DEBUG STUFF    */
    void doDebugRequest();
    void doDebugRequestBeforPredictionAndUpdate();
    void doDebugRequestBeforUpdate();
    void drawFilter(const BallHypothesis& bh, const Color& model_color, Color cov_loc_color, Color cov_vel_color) const;
    void drawFiltersOnField() const;
    void reloadParameters();

    class Parameters:  public ParameterList
    {
        inline void enforceSymmetryOfQ(double v){
            processNoiseStdSingleDimension(0,1) = v;
        }

        inline void enforceSymmetryOfR(double v){
            measurementNoiseCovariances(0,1) = v;
        }

        inline void enforceSymmetryOfInitialP(double v){
            initialStateStdSingleDimension(0,1) = v;
        }

     public:
        Parameters() : ParameterList("MultiKalmanBallLocator")<--- Member variable 'Parameters::area95Threshold' is not initialized in the constructor.
        {
            registerParameter("processNoiseStdQ00", processNoiseStdSingleDimension(0,0)) = 15;
            registerParameter("processNoiseStdQ10", processNoiseStdSingleDimension(1,0), &Parameters::enforceSymmetryOfQ) = 0;
            registerParameter("processNoiseStdQ11", processNoiseStdSingleDimension(1,1)) = 500;

            // experimental determined
            registerParameter("measurementNoiseR00", measurementNoiseCovariances(0,0)) =  0.00130217; //[rad^2]
            registerParameter("measurementNoiseR10", measurementNoiseCovariances(1,0), &Parameters::enforceSymmetryOfR) = -0.00041764; //[rad^2]
            registerParameter("measurementNoiseR11", measurementNoiseCovariances(1,1)) =  0.00123935; //[rad^2]

            registerParameter("initialStateStdP00", initialStateStdSingleDimension(0,0)) = 250;
            registerParameter("initialStateStdP10", initialStateStdSingleDimension(1,0), &Parameters::enforceSymmetryOfInitialP) = 0;
            registerParameter("initialStateStdP11", initialStateStdSingleDimension(1,1)) = 250;

            //thresholds for association functions
            PARAMETER_REGISTER(euclidThreshold) = Math::fromDegrees(10);
            PARAMETER_REGISTER(mahalanobisThreshold) = Math::fromDegrees(10);
            PARAMETER_REGISTER(maximumLikelihoodThreshold) = 0.0005;

            //AssymetricalBoolFilte parameters
            PARAMETER_REGISTER(g0) = 0.03;
            PARAMETER_REGISTER(g1) = 0.5;

            PARAMETER_REGISTER(association.use_normal) = false;
            PARAMETER_REGISTER(association.use_cool)   = false;
            PARAMETER_REGISTER(association.use_greedy)  = true;

            PARAMETER_REGISTER(area95Threshold_radius.factor) = std::sqrt(2) * 1;
            PARAMETER_REGISTER(area95Threshold_radius.offset) = std::sqrt(2) * 125;

            PARAMETER_REGISTER(use_covariance_based_selection) = true;

            syncWithConfig();
        }

        double g0;
        double g1;
        Eigen::Matrix2d processNoiseStdSingleDimension;
        Eigen::Matrix2d measurementNoiseCovariances;
        Eigen::Matrix2d initialStateStdSingleDimension;

        double area95Threshold;

        double euclidThreshold;
        double mahalanobisThreshold;
        double maximumLikelihoodThreshold;

        struct {
            bool use_normal;
            bool use_cool;
            bool use_greedy;
        } association;

        struct {
            double factor;
            double offset;
        } area95Threshold_radius;

        bool use_covariance_based_selection;
    } params;

    Measurement_Function_H h;
    UpdateAssociationFunction* updateAssociationFunction;

    // available update association value functions
    EuclideanUAF   euclid;
    MahalanobisUAF mahalanobis;
    LikelihoodUAF  likelihood;
};

#endif // MULTIKALMANBALLLOCATOR_H