#ifndef TEAMBALLLOCATORCANOPYCLUSTER_H
#define TEAMBALLLOCATORCANOPYCLUSTER_H
#include "ModuleFramework/Module.h"
#include "Tools/Debug/DebugRequest.h"
#include "Tools/Debug/DebugDrawings.h"
#include "Tools/Debug/DebugModify.h"
#include "Tools/Debug/DebugParameterList.h"
#include "Representations/Infrastructure/FrameInfo.h"
#include "Representations/Infrastructure/FieldInfo.h"
#include "Representations/Modeling/TeamBallModel.h"
#include "Representations/Modeling/TeamMessage.h"
#include "Representations/Modeling/RobotPose.h"
#include "Representations/Modeling/TeamMessageNTP.h"
#include "Representations/Modeling/TeamMessagePlayersState.h"
BEGIN_DECLARE_MODULE(TeamBallLocatorCanopyCluster)
PROVIDE(DebugModify)
PROVIDE(DebugRequest)
PROVIDE(DebugDrawings)
PROVIDE(DebugParameterList)
REQUIRE(FrameInfo)
REQUIRE(FieldInfo)
REQUIRE(TeamMessage)
REQUIRE(RobotPose)
REQUIRE(TeamMessageNTP)
REQUIRE(TeamMessagePlayersState)
PROVIDE(TeamBallModel)
END_DECLARE_MODULE(TeamBallLocatorCanopyCluster);
class TeamBallLocatorCanopyCluster : protected TeamBallLocatorCanopyClusterBase
{
public:
class Parameters: public ParameterList
{
public:
Parameters() : ParameterList("TeamBallLocatorCanopyCluster")
{
PARAMETER_REGISTER(maxBallAge) = 850; // in ms, wait at least two messages (approx.)
PARAMETER_REGISTER(t1) = 1000; // in mm
PARAMETER_REGISTER(t2) = 500; // in mm
PARAMETER_REGISTER(maxTimeTbIsValidWithoutUpdate) = 2000; // in ms
PARAMETER_REGISTER(ballsAreOnlyValidOnField) = true; // the received balls are only 'valid' if their inside the field boundries
PARAMETER_REGISTER(enablePlayingCheck) = true; // whether the check, if a teammate is alive, active & playing should be used
PARAMETER_REGISTER(enableNtpAdjustment) = true; // whether the ball age should be adjusted for the network latency
syncWithConfig();
}
int maxBallAge;
int t1; // loose distance
int t2; // tight distance
int maxTimeTbIsValidWithoutUpdate;
bool ballsAreOnlyValidOnField;
bool enablePlayingCheck;
bool enableNtpAdjustment;
} params;
TeamBallLocatorCanopyCluster();
~TeamBallLocatorCanopyCluster();
virtual void execute();
private:
std::map<unsigned int, unsigned int> lastMessages;
struct Ball
{
Vector2d pos;
Vector2d sum;
unsigned int size = 0;
bool valid = true;
Ball(const Vector2d& p) {<--- Struct 'Ball' has a constructor with 1 argument that is not explicit. [+]Struct 'Ball' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
pos = p;
sum = p;
++size;
}
void add(const Ball& p) {
sum += p.pos;
++size;
}
Vector2d center() {<--- Technically the member function 'TeamBallLocatorCanopyCluster::Ball::center' can be const. [+]The member function 'TeamBallLocatorCanopyCluster::Ball::center' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
return sum / size;
}
};
};
#endif // TEAMBALLLOCATORCANOPYCLUSTER_H