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

Get rid of potential div-0 errors so we can set dt = 0 for pausing. #2705

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Get rid of potential div-0 errors so we can set dt = 0 for pausing.
  • Loading branch information
Nicholas Gyde committed May 20, 2020
commit 740af6c4364368051a66e6bd9b32fcf7f3336b9b
3 changes: 3 additions & 0 deletions AirLib/include/common/VectorMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ class VectorMathT {

static Vector3T toAngularVelocity(const QuaternionT& start, const QuaternionT& end, RealT dt)
{
if (dt == 0)
return Vector3T(0, 0, 0);

RealT p_s, r_s, y_s;
toEulerianAngle(start, p_s, r_s, y_s);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PidController : public IUpdatable {
if (dt > min_dt_) {
integrator->update(dt, error, last_time_);

float error_der = (error - last_error_) / dt;
float error_der = dt > 0 ? (error - last_error_) / dt : 0;
dterm = error_der * config_.kd;
last_error_ = error;
}
Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/MavLinkTest/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ class PidController
proportionalGain = error * kProportional_;
}
if (kDerivative_ != 0) {
float derivative = (error - previous_error_) / dt;
float derivative = dt > 0 ? (error - previous_error_) / dt : 0;
derivativeGain = derivative * kDerivative_;
}
if (kIntegral_ != 0) {
Expand Down
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ void PawnSimApi::updateKinematics(float dt)
next_kinematics.twist.angular = msr::airlib::VectorMath::toAngularVelocity(
kinematics_->getPose().orientation, next_kinematics.pose.orientation, dt);

next_kinematics.accelerations.linear = (next_kinematics.twist.linear - kinematics_->getTwist().linear) / dt;
next_kinematics.accelerations.angular = (next_kinematics.twist.angular - kinematics_->getTwist().angular) / dt;
next_kinematics.accelerations.linear = dt > 0 ? (next_kinematics.twist.linear - kinematics_->getTwist().linear) / dt : (next_kinematics.twist.linear - next_kinematics.twist.linear) / 1.f;
next_kinematics.accelerations.angular = dt > 0 ? (next_kinematics.twist.angular - kinematics_->getTwist().angular) / dt : (next_kinematics.twist.angular - next_kinematics.twist.angular) / 1.f;

kinematics_->setState(next_kinematics);
kinematics_->update();
Expand Down