Skip to content

RuntimeError in ballbot_lerner.py at line 283: K = mpc.getLinearFeedbackGain #3

@XICharlie

Description

@XICharlie

Hello!
Recently I am trying to replicate your code work to train mpcnet in this program by myself. However, in the latest ocs2 version, the package "ocs2_ballbot_example" have been removed, so I adjusted to the old version of ocs2 from the github repository, which is earlier than the publication of your article. After making several adjustments, I came into an error:

Traceback (most recent call last):
  File "ballbot_learner.py", line 283, in <module>
    K = mpc.getLinearFeedbackGain(t_result[0])
RuntimeError: Feedback gains only available with linear controller

This error pointed to the principle of a function in ocs2 repository named "getLinearFeedbackGain". The code is shown below:

template <size_t STATE_DIM, size_t INPUT_DIM>
void MPC_MRT_Interface<STATE_DIM, INPUT_DIM>::getLinearFeedbackGain(scalar_t time, input_state_matrix_t& K) {
  auto controller = dynamic_cast<LinearController<STATE_DIM, INPUT_DIM>*>(this->currentPrimalSolution_->controllerPtr_.get());
  if (!controller) {
    throw std::runtime_error("Feedback gains only available with linear controller");
  }
  controller->getFeedbackGain(time, K);
}

However, I noticed this function "getLinearFeedbackGain" have be adjusted in the later version of ocs2. So I turned to the later version of ocs2 and built the "ocs2_ballbot" package. The error happened in the same position:

Traceback (most recent call last):
  File "ballbot_learner.py", line 296, in <module>
    K = mpc.getLinearFeedbackGain(t_result[0])
RuntimeError: [MPC_MRT_Interface::getLinearFeedbackGain] Feedback gains only available with linear controller!

This error pointed to the "getLinearFeedbackGain" function in modified ocs2 again:

matrix_t MPC_MRT_Interface::getLinearFeedbackGain(scalar_t time) {
  auto controller = dynamic_cast<LinearController*>(this->getPolicy().controllerPtr_.get());
  if (controller == nullptr) {
    throw std::runtime_error("[MPC_MRT_Interface::getLinearFeedbackGain] Feedback gains only available with linear controller!");
  }
  matrix_t K;
  controller->getFeedbackGain(time, K);
  return K;
}

It seems that the type conversion in the program went wrong in both new and old version of ocs2. However, I have no idea on the error inside the program. Could you please give the solution to this problem, or point out the ocs2 version that you used to run the code in this repository?
================================================================
Also, I have successfully trained the example provided in the ocs2_ballbot_mpcnet in the latest version of ocs2. And I noticed that the package ocs2_mpcnet is contributed based on your article. So I want to know, whether the replication of ocs2_ballbot_mpcnet can replace the training process in the program with your article publication, which I failed to replicate?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions