Skip to content

Commit 85d5b31

Browse files
Tomas BacaTomas Baca
authored andcommitted
fixed rampup bug in Se3 and Mpc
1 parent aacd77e commit 85d5b31

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/mpc_controller.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,15 @@ bool MpcController::activate(const ControlOutput &last_control_output) {
655655
rampup_direction_ = 0;
656656
}
657657

658-
RCLCPP_INFO(node_->get_logger(), "[%s]: activating rampup with initial throttle: %.4f, target: %.4f", name_.c_str(), throttle_last_controller.value(), hover_throttle);
659-
660658
rampup_active_ = true;
661659
rampup_start_time_ = clock_->now();
662660
rampup_last_time_ = clock_->now();
663661
rampup_throttle_ = throttle_last_controller.value();
664662

665663
rampup_duration_ = std::abs(throttle_difference) / _rampup_speed_;
664+
665+
RCLCPP_INFO(node_->get_logger(), "[%s]: activating rampup with initial throttle: %.4f, target: %.4f", name_.c_str(), throttle_last_controller.value(), hover_throttle);
666+
666667
}
667668

668669
first_iteration_ = true;
@@ -1669,24 +1670,22 @@ void MpcController::MPC(const mrs_msgs::msg::UavState &uav_state, const mrs_msgs
16691670

16701671
if (rampup_active_) {
16711672

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

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

1677-
RCLCPP_INFO(node_->get_logger(), "[%s]: rampup finished", name_.c_str());
1678-
1679-
} else {
1677+
rampup_last_time_ = clock_->now();
16801678

1681-
double rampup_dt = (clock_->now() - rampup_last_time_).seconds();
1679+
throttle = rampup_throttle_;
16821680

1683-
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
1681+
RCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 100, "[%s]: ramping up throttle, %.4f", name_.c_str(), throttle);
16841682

1685-
rampup_last_time_ = clock_->now();
1683+
// deactivate the rampup when the times up
1684+
if (std::abs((clock_->now() - rampup_start_time_).seconds()) >= rampup_duration_) {
16861685

1687-
throttle = rampup_throttle_;
1686+
rampup_active_ = false;
16881687

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

16921691
} else {

src/se3_controller.cpp

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

15341534
} else if (rampup_active_) {
15351535

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

1539-
rampup_active_ = false;
1540-
1541-
RCLCPP_INFO(node_->get_logger(), "[Se3Controller]: rampup finished");
1538+
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
15421539

1543-
} else {
1540+
rampup_last_time_ = clock_->now();
15441541

1545-
double rampup_dt = (clock_->now() - rampup_last_time_).seconds();
1542+
throttle = rampup_throttle_;
15461543

1547-
rampup_throttle_ += double(rampup_direction_) * _rampup_speed_ * rampup_dt;
1544+
RCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 100, "[Se3Controller]: ramping up throttle, %.4f", throttle);
15481545

1549-
rampup_last_time_ = clock_->now();
1546+
// deactivate the rampup when the times up
1547+
if (std::abs((clock_->now() - rampup_start_time_).seconds()) >= rampup_duration_) {
15501548

1551-
throttle = rampup_throttle_;
1549+
rampup_active_ = false;
15521550

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

15561554
} else {

0 commit comments

Comments
 (0)