@@ -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 {
0 commit comments