Skip to content

Commit

Permalink
Replaced member variable with local.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewie-donckers committed Feb 16, 2022
1 parent 7f18225 commit e107cb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
3 changes: 0 additions & 3 deletions include/path_tracking_pid/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,6 @@ class Controller
double c_lat_ = 1.;
double c_ang_ = 1.;

// Used to check for tan(0)==>NaN in the filter calculation
double tan_filt_ = 1.;

// MPC settings
int mpc_max_fwd_iter_; // Define # of steps that you look into the future with MPC [-]
int mpc_max_vel_optimization_iter_; // Set maximum # of velocity bisection iterations
Expand Down
24 changes: 12 additions & 12 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,28 +514,28 @@ geometry_msgs::Twist Controller::update(const double target_x_vel,
if (cutoff_frequency_lat_ != -1)
{
// Check if tan(_) is really small, could cause c = NaN
tan_filt_ = tan((cutoff_frequency_lat_ * 6.2832) * dt.toSec() / 2);
auto tan_filt = tan((cutoff_frequency_lat_ * 6.2832) * dt.toSec() / 2);

// Avoid tan(0) ==> NaN
if ((tan_filt_ <= 0.) && (tan_filt_ > -0.01))
tan_filt_ = -0.01;
if ((tan_filt_ >= 0.) && (tan_filt_ < 0.01))
tan_filt_ = 0.01;
if ((tan_filt <= 0.) && (tan_filt > -0.01))
tan_filt = -0.01;
if ((tan_filt >= 0.) && (tan_filt < 0.01))
tan_filt = 0.01;

c_lat_ = 1 / tan_filt_;
c_lat_ = 1 / tan_filt;
}
if (cutoff_frequency_ang_ != -1)
{
// Check if tan(_) is really small, could cause c = NaN
tan_filt_ = tan((cutoff_frequency_ang_ * 6.2832) * dt.toSec() / 2);
auto tan_filt = tan((cutoff_frequency_ang_ * 6.2832) * dt.toSec() / 2);

// Avoid tan(0) ==> NaN
if ((tan_filt_ <= 0.) && (tan_filt_ > -0.01))
tan_filt_ = -0.01;
if ((tan_filt_ >= 0.) && (tan_filt_ < 0.01))
tan_filt_ = 0.01;
if ((tan_filt <= 0.) && (tan_filt > -0.01))
tan_filt = -0.01;
if ((tan_filt >= 0.) && (tan_filt < 0.01))
tan_filt = 0.01;

c_ang_ = 1 / tan_filt_;
c_ang_ = 1 / tan_filt;
}

controller_state_.filtered_error_lat.at(2) = controller_state_.filtered_error_lat.at(1);
Expand Down

0 comments on commit e107cb9

Please sign in to comment.