19 bool useKalmanFilter) :
20 useKalmanFilter(useKalmanFilter)
24 human.linearVelocity = Eigen::Vector2f::Zero();
25 human.detectionTime = detectionTime;
26 lastDetectedHuman = human;
33 Q.block<2, 2>(0, 0) *= params.control_pos_cov * params.control_pos_cov;
34 Q.block<1, 1>(2, 2) *= params.control_rot_cov * params.control_rot_cov;
38 R.block<2, 2>(0, 0) *= params.obs_pos_cov * params.obs_pos_cov;
39 R.block<1, 1>(2, 2) *= params.obs_rot_cov * params.obs_rot_cov;
43 P0.block<2, 2>(0, 0) *= params.initial_state_pos_cov * params.initial_state_pos_cov;
44 P0.block<1, 1>(2, 2) *= params.initial_state_rot_cov * params.initial_state_rot_cov;
52 ukf = std::make_unique<UnscentedKalmanFilter<SystemModelT>>(Q, R, alpha, state0, P0);
59 double dt = (detectionTime - human.detectionTime).toSecondsDouble();
66 human.pose = fromUkfState(ukf->getCurrentState());
67 human.detectionTime = detectionTime;
71 human.pose = human.estimateAt(detectionTime);
72 human.detectionTime = detectionTime;
85 ukf->update(observation);
87 newPose = fromUkfState(ukf->getCurrentState());
88 newPose.linear() = pose.linear();
96 Eigen::Vector2f newVelocity = human.linearVelocity;
97 if (pastPoses.size() >= (params.velocityAverageBinDistance + params.velocityAverageBinSize))
99 TimedVector2f p1 = getAveragedTimedPose(0, params.velocityAverageBinSize);
100 TimedVector2f p2 = getAveragedTimedPose(params.velocityAverageBinDistance,
101 params.velocityAverageBinDistance +
102 params.velocityAverageBinSize);
103 Eigen::Vector2f ds = p2.pose - p1.pose;
104 double dt = (p2.time * 1000.0) / (p1.time * 1000.0);
105 Eigen::Vector2f linVelocity = ds /
dt;
106 if (linVelocity.norm() > 1000)
108 linVelocity = linVelocity.normalized();
111 newVelocity = linVelocity;
115 newVelocity = Eigen::Vector2f::Zero();
119 if (pastPoses.size() >= params.positionAverageBinSize)
121 TimedVector2f p = getAveragedTimedPose(pastPoses.size() - params.positionAverageBinSize,
122 params.positionAverageBinSize);
130 human.detectionTime = detectionTime;
131 human.pose = newPose;
132 human.linearVelocity = newVelocity;
135 Eigen::Vector2f{pose.translation()}});
136 if (pastPoses.size() > (params.velocityAverageBinDistance + params.velocityAverageBinSize))
138 pastPoses.pop_front();
141 lastDetectedHuman = human;
153 return (currentTime - lastDetectedHuman.detectionTime);
160 return {{pose.translation().x() / 1000,
161 pose.translation().y() / 1000,
170 pose2d.translation().x() = pose.
pose.x() * 1000;
171 pose2d.translation().y() = pose.
pose.y() * 1000;
172 pose2d.linear() = Eigen::Rotation2Df(0 ).toRotationMatrix();
178 HumanFilter::toUkfControl(
const Eigen::Vector2f& vel)
181 const auto& global_R_human = human.pose.linear();
182 const auto human_V_vel = global_R_human.inverse() * vel;
185 return {{human_V_vel.x() / 1000, human_V_vel.y() / 1000, 0}};
194 HumanFilter::TimedVector2f
195 HumanFilter::getAveragedTimedPose(
unsigned int start_idx,
unsigned int end_idx)
197 std::int64_t avgTime = 0;
198 Eigen::Vector2f avgPose = Eigen::Vector2f::Zero();
199 auto it = pastPoses.begin();
200 for (std::int64_t i = 0; i < start_idx; ++i)
204 const auto numItems = end_idx - start_idx;
205 for (std::int64_t i = start_idx; i < end_idx; i++)
207 const auto& [time, pose] = *it;
209 avgTime += time / numItems;
215 return {avgTime, avgPose};
Eigen::Matrix< FloatT, dim::control, dim::control > PropCovT
Eigen::Matrix< FloatT, dim::obs, dim::obs > ObsCovT
Eigen::Matrix< FloatT, 3, 1 > AlphaT
Eigen::Matrix< FloatT, dim::state, dim::state > StateCovT
Represents a point in time.
std::int64_t toMilliSecondsSinceEpoch() const
const Human & get() const
HumanFilter::get returns the human whose pose is filtered containing the most recent state.
void propagation(const DateTime &detectionTime)
HumanFilter::propagation propagate the system model to the given point in time.
void update(const core::Pose2D &pose, const DateTime &detectionTime)
HumanFilter::update update the filter a new detected pose of the tracked human and the detection time...
HumanFilter(const core::Pose2D &pose0, const DateTime &detectionTime, bool useKalmanFilter)
HumanFilter::HumanFilter creates a new filter that filters 2D poses (position and rotation in a two d...
Duration detectionAge(const DateTime ¤tTime) const
This file is part of ArmarX.
This file is part of ArmarX.
manif::SE3< floatT > pose
StateSE3< FloatT > StateT
static ObsT observationFunction(const StateT &state)
ControlSE2< FloatT > ControlT
Eigen::Matrix< FloatT, dim::obs, 1 > ObsT
StateSE2< FloatT > StateT