Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to UKF #717

Open
wants to merge 3 commits into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions include/robot_localization/filter_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,16 @@ class FilterBase
//! @brief Method for settings bounds on acceleration values derived from controls
//! @param[in] state - The current state variable (e.g., linear X velocity)
//! @param[in] control - The current control commanded velocity corresponding to the state variable
//! @param[in] delta - the timestep of the predict for which these terms are computed
//! @param[in] accelerationLimit - Limit for acceleration (regardless of driving direction)
//! @param[in] accelerationGain - Gain applied to acceleration control error
//! @param[in] decelerationLimit - Limit for deceleration (moving towards zero, regardless of driving direction)
//! @param[in] decelerationGain - Gain applied to deceleration control error
//! @return a usable acceleration estimate for the control vector
//!
inline double computeControlAcceleration(const double state, const double control, const double accelerationLimit,
const double accelerationGain, const double decelerationLimit, const double decelerationGain)
inline double computeControlAcceleration(const double state, const double control, const double delta,
const double accelerationLimit, const double accelerationGain, const double decelerationLimit,
const double decelerationGain)
{
FB_DEBUG("---------- FilterBase::computeControlAcceleration ----------\n");

Expand All @@ -357,7 +359,7 @@ class FilterBase
gain = decelerationGain;
}

const double finalAccel = std::min(std::max(gain * error, -limit), limit);
const double finalAccel = std::min(std::max(gain * error / delta, -limit), limit);

FB_DEBUG("Control value: " << control << "\n" <<
"State value: " << state << "\n" <<
Expand Down
2 changes: 1 addition & 1 deletion src/filter_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace RobotLocalization
if (controlUpdateVector_[controlInd])
{
controlAcceleration_(controlInd) = computeControlAcceleration(state_(controlInd + POSITION_V_OFFSET),
(timedOut ? 0.0 : latestControl_(controlInd)), accelerationLimits_[controlInd],
(timedOut ? 0.0 : latestControl_(controlInd)), predictionDelta, accelerationLimits_[controlInd],
accelerationGains_[controlInd], decelerationLimits_[controlInd], decelerationGains_[controlInd]);
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/ukf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ namespace RobotLocalization
{
state_.noalias() += kalmanGainSubset * innovationSubset;

// (6) Compute the new estimate error covariance P = P - (K * P_zz * K')
estimateErrorCovariance_.noalias() -= (kalmanGainSubset * predictedMeasCovar * kalmanGainSubset.transpose());
// (6) Compute the new estimate error covariance P = P - (K * ( P_zz + R ) * K')
estimateErrorCovariance_.noalias() -= (kalmanGainSubset * (predictedMeasCovar + measurementCovarianceSubset)*
kalmanGainSubset.transpose());

wrapStateAngles();

Expand Down Expand Up @@ -453,6 +454,18 @@ namespace RobotLocalization
transferFunction_(StateMemberVy, StateMemberAy) = delta;
transferFunction_(StateMemberVz, StateMemberAz) = delta;

// Apply control terms, which are actually accelerations
sigmaPoint(StateMemberVroll) += controlAcceleration_(ControlMemberVroll) * delta;
sigmaPoint(StateMemberVpitch) += controlAcceleration_(ControlMemberVpitch) * delta;
sigmaPoint(StateMemberVyaw) += controlAcceleration_(ControlMemberVyaw) * delta;

sigmaPoint(StateMemberAx) = (controlUpdateVector_[ControlMemberVx] ?
controlAcceleration_(ControlMemberVx) : sigmaPoint(StateMemberAx));
sigmaPoint(StateMemberAy) = (controlUpdateVector_[ControlMemberVy] ?
controlAcceleration_(ControlMemberVy) : sigmaPoint(StateMemberAy));
sigmaPoint(StateMemberAz) = (controlUpdateVector_[ControlMemberVz] ?
controlAcceleration_(ControlMemberVz) : sigmaPoint(StateMemberAz));

sigmaPoint.applyOnTheLeft(transferFunction_);
}
} // namespace RobotLocalization