Skip to content

Commit

Permalink
Make speed_limiters unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jan 9, 2025
1 parent 4054b86 commit 7a28c7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class DiffDriveController : public controller_interface::ControllerInterface
std::queue<TwistStamped> previous_commands_; // last two commands

// speed limiters
SpeedLimiter limiter_linear_;
SpeedLimiter limiter_angular_;
std::unique_ptr<SpeedLimiter> limiter_linear_;
std::unique_ptr<SpeedLimiter> limiter_angular_;

bool publish_limited_velocity_ = false;
std::shared_ptr<rclcpp::Publisher<TwistStamped>> limited_velocity_publisher_ = nullptr;
Expand Down
17 changes: 5 additions & 12 deletions diff_drive_controller/src/diff_drive_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ using hardware_interface::HW_IF_POSITION;
using hardware_interface::HW_IF_VELOCITY;
using lifecycle_msgs::msg::State;

DiffDriveController::DiffDriveController()
: controller_interface::ControllerInterface(),
// dummy limiter, will be created in on_configure
// could be done with shared_ptr instead -> but will break ABI
limiter_angular_(std::numeric_limits<double>::quiet_NaN()),
limiter_linear_(std::numeric_limits<double>::quiet_NaN())
{
}
DiffDriveController::DiffDriveController() : controller_interface::ControllerInterface() {}

const char * DiffDriveController::feedback_type() const
{
Expand Down Expand Up @@ -241,9 +234,9 @@ controller_interface::return_type DiffDriveController::update(

auto & last_command = previous_commands_.back().twist;
auto & second_to_last_command = previous_commands_.front().twist;
limiter_linear_.limit(
limiter_linear_->limit(
linear_command, last_command.linear.x, second_to_last_command.linear.x, period.seconds());
limiter_angular_.limit(
limiter_angular_->limit(
angular_command, last_command.angular.z, second_to_last_command.angular.z, period.seconds());

previous_commands_.pop();
Expand Down Expand Up @@ -365,13 +358,13 @@ controller_interface::CallbackReturn DiffDriveController::on_configure(
std::numeric_limits<double>::quiet_NaN();
}
// END DEPRECATED
limiter_linear_ = SpeedLimiter(
limiter_linear_ = std::make_unique<SpeedLimiter>(
params_.linear.x.min_velocity, params_.linear.x.max_velocity,
params_.linear.x.max_acceleration_reverse, params_.linear.x.max_acceleration,
params_.linear.x.max_deceleration, params_.linear.x.max_deceleration_reverse,
params_.linear.x.min_jerk, params_.linear.x.max_jerk);

limiter_angular_ = SpeedLimiter(
limiter_angular_ = std::make_unique<SpeedLimiter>(
params_.angular.z.min_velocity, params_.angular.z.max_velocity,
params_.angular.z.max_acceleration_reverse, params_.angular.z.max_acceleration,
params_.angular.z.max_deceleration, params_.angular.z.max_deceleration_reverse,
Expand Down

0 comments on commit 7a28c7e

Please sign in to comment.