Skip to content

Commit 9b08b0c

Browse files
Tomas BacaTomas Baca
authored andcommitted
cleaned up the rampup bug fix
1 parent 85d5b31 commit 9b08b0c

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/mpc_controller.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ bool MpcController::activate(const ControlOutput &last_control_output) {
663663
rampup_duration_ = std::abs(throttle_difference) / _rampup_speed_;
664664

665665
RCLCPP_INFO(node_->get_logger(), "[%s]: activating rampup with initial throttle: %.4f, target: %.4f", name_.c_str(), throttle_last_controller.value(), hover_throttle);
666-
667666
}
668667

669668
first_iteration_ = true;
@@ -1670,24 +1669,26 @@ void MpcController::MPC(const mrs_msgs::msg::UavState &uav_state, const mrs_msgs
16701669

16711670
if (rampup_active_) {
16721671

1673-
double rampup_dt = (clock_->now() - rampup_last_time_).seconds();
1672+
// deactivate the rampup when the times up
1673+
if (std::abs((clock_->now() - rampup_start_time_).seconds()) >= rampup_duration_) {
16741674

1675-
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
1675+
rampup_active_ = false;
16761676

1677-
rampup_last_time_ = clock_->now();
1677+
RCLCPP_INFO(node_->get_logger(), "[%s]: rampup finished", name_.c_str());
16781678

1679-
throttle = rampup_throttle_;
1679+
} else {
16801680

1681-
RCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 100, "[%s]: ramping up throttle, %.4f", name_.c_str(), throttle);
1681+
double rampup_dt = (clock_->now() - rampup_last_time_).seconds();
16821682

1683-
// deactivate the rampup when the times up
1684-
if (std::abs((clock_->now() - rampup_start_time_).seconds()) >= rampup_duration_) {
1683+
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
16851684

1686-
rampup_active_ = false;
1685+
rampup_last_time_ = clock_->now();
16871686

1688-
RCLCPP_INFO(node_->get_logger(), "[%s]: rampup finished", name_.c_str());
1687+
RCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 100, "[%s]: ramping up throttle, %.4f", name_.c_str(), throttle);
16891688
}
16901689

1690+
throttle = rampup_throttle_;
1691+
16911692
} else {
16921693

16931694
if (desired_thrust_force >= 0) {

src/se3_controller.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,24 +1533,26 @@ void Se3Controller::SE3Controller(const mrs_msgs::msg::UavState& uav_state, cons
15331533

15341534
} else if (rampup_active_) {
15351535

1536-
double rampup_dt = (clock_->now() - rampup_last_time_).seconds();
1536+
// deactivate the rampup when the times up
1537+
if (std::abs((clock_->now() - rampup_start_time_).seconds()) >= rampup_duration_) {
15371538

1538-
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
1539+
rampup_active_ = false;
15391540

1540-
rampup_last_time_ = clock_->now();
1541+
RCLCPP_INFO(node_->get_logger(), "[Se3Controller]: rampup finished");
15411542

1542-
throttle = rampup_throttle_;
1543+
} else {
15431544

1544-
RCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 100, "[Se3Controller]: ramping up throttle, %.4f", throttle);
1545+
double rampup_dt = (clock_->now() - rampup_last_time_).seconds();
15451546

1546-
// deactivate the rampup when the times up
1547-
if (std::abs((clock_->now() - rampup_start_time_).seconds()) >= rampup_duration_) {
1547+
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
15481548

1549-
rampup_active_ = false;
1549+
rampup_last_time_ = clock_->now();
15501550

1551-
RCLCPP_INFO(node_->get_logger(), "[Se3Controller]: rampup finished");
1551+
RCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 100, "[Se3Controller]: ramping up throttle, %.4f", throttle);
15521552
}
15531553

1554+
throttle = rampup_throttle_;
1555+
15541556
} else {
15551557

15561558
if (desired_thrust_force >= 0) {

0 commit comments

Comments
 (0)