RuntimeError in ballbot_lerner.py at line 283: K = mpc.getLinearFeedbackGain
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?
Hello, I have encountered the same problem as you before, then I found a solution in the closed issue. The author said to fix it, we need go to the file ocs2_ballbot_example/config/mpc/task.info and look for the property useFeedbackPolicy. The value has to be 1. I changed the value of "useFeedbackPolicy", and it works for me, hope it can work for you too.
Besides, you said that you already successfully trained the example provided in the ocs2_ballbot_mpcnet in the latest version of ocs2. There is a problem for me when I run the train.py in the ocs2_ballbot_mpcnet, it always stuck at waiting for the first data. Detailed content is visible at the issue part(#68) of leggedrobotics/ocs2. Do you have this problem? and if you have, how did you solve it?
Another question is that when i run ballbot_evaluation.py to evaluate the policy generated by the ballbot_learner.py, the results seems not good, do you have the same results? Sorry to bother you much, but it is really hard to find someone who use mpcnet, so please forgive me for asking so many questions, thank you!
Hello, I have encountered the same problem as you before, then I found a solution in the closed issue. The author said to fix it, we need go to the file ocs2_ballbot_example/config/mpc/task.info and look for the property useFeedbackPolicy. The value has to be 1. I changed the value of "useFeedbackPolicy", and it works for me, hope it can work for you too.
Hello Xiao, Your hint really helped me a lot! When I am writing these comments, the ballbot_learner.py is still under training QAQ. Anyway, it's going on the right way. However, I have an important exam tomorrow, so I do not have too much time for checking with your problem. I viewed your comments, but I really do not have relevant memory based on your description. Besides, I am currently using the old version of ocs2, which do not contain the package ocs2_mpcnet. As for the ballbot_evaluation.py, I shall test that once I completed my exam tomorrow. Lastly, thanks for your sincere suggestion!
It is good news for me that this tip helps you.Besides, this source code provided by this GitHub project runs quite slowly for me too(almost 2 minutes for only one iteration), I guess it's due to the slower running speed of the old version of ocs2. I found a similar project(Toto-0/Robotics2-project), using newer version of ocs2 and it runs much quicker than this, what you need to do is just change names of some functions. Hope it can help you and wish you a good result for your exam!
Another question is that when i run ballbot_evaluation.py to evaluate the policy generated by the ballbot_learner.py, the results seems not good, do you have the same results? Sorry to bother you much, but it is really hard to find someone who use mpcnet, so please forgive me for asking so many questions, thank you!
Hello Xiao,
Sorry for delaying some days after the past weekend, as I went in some trouble when running ballbot_evaluation.py. Now I get the plot of the policy, and it seems even more strange than your result QAQ, Currently I have no idea on how to explain this phenomenon, and want to know how do you or anybody explain our graph.
Sorry, I have no idea on this question too. In fact, I spend almost half month trying to solve this question but failed. The result of this github code is not good and i guess maybe there is some trouble in the code. A good news for me is that the train.py of ~/git/ocs2/ocs2_mpcnet/ocs2_ballbot_mpcnet runs well now. Its result looks more normal than this code, maybe you can try ocs2_mpcnet.
Now I'm trying to deploy the mpcnet on the mobile manipulator, referring to the given code of ballbot and legged_robot. Unfortunately, it's a bit difficult and challenging for me as a beginner.
Sorry, I have no idea on this question too. In fact, I spend almost half month trying to solve this question but failed. The result of this github code is not good and i guess maybe there is some trouble in the code. A good news for me is that the train.py of ~/git/ocs2/ocs2_mpcnet/ocs2_ballbot_mpcnet runs well now. Its result looks more normal than this code, maybe you can try ocs2_mpcnet.
Since you mentioned that your data in ocs2_ballbot_mpcnet is much more reasonable, I want to check with your result. By the way, I noticed that your account owns a chinese name, maybe we can communicate in a more convenient way, like sending email directly or wechat QWQ
