As exposed in this topic in ACADO forum, there is a bug when you try to use OnlineData variables. In my case I am using C++ code instead of MATLAB interface and have 7 OnlineData variables. In the topic mentioned before they propose using the function SetNOD but using C++ I can't call the function. I cannot access the official forum in sourcefourge because they have some problems and I would appreciate your help.
The abbreviated code is:
int main{
USING_NAMESPACE_ACADO
//Variables
DifferentialState x, y, z, dx, dy, dz, roll, pitch, yaw, droll, dpitch, dyaw;
Control u1, u2, u3, u4;
OnlineData yaw0, obsx, obsy, obsz, obsrx, obsry, obsrz;
. . .
//Create Optimal Control Problem object
OCP ocp(t_start, t_end, N); //50 number of discretization intervals
//Fixing the bug
//Alternatives I tried
ocp.SetNOD(7);//Error A
//ocp.ModelContainer.SetNOD(7);//Error B
//Objective Function
ocp.minimizeLSQ(Q, h);
ocp.minimizeLSQEndTerm(QN, hN);
/* Constraints */
//Model constraint
ocp.setModel( f );
/* Export OCP */
OCPexport mpc( ocp );
...
if (mpc.exportCode( "path_qp_export_oases" ) != SUCCESSFUL_RETURN)
exit( EXIT_FAILURE );
return 0;
}
Error A:
/.../path_qp_generated_oases.cpp: In function ‘int main()’: /.../path_qp_generated_oases.cpp:321:9: error: ‘class ACADO::OCP’ has no member named ‘SetNOD’ ocp.SetNOD(7);
make[2]: [.../CMakeFiles/my_examples_path_qp_generated_oases.dir/my_examples/path_qp_generated_oases.cpp.o] Error 1 make1: .../CMakeFiles/my_examples_path_qp_generated_oases.dir/all] Error 2 make: [all] Error 2
Error B:
/.../path_qp_generated_oases.cpp: In function ‘int main()’: /.../path_qp_generated_oases.cpp:320:10: error: invalid use of ‘ACADO::ModelContainer::ModelContainer’ ocp.ModelContainer.SetNOD(7);
make2: [examples/CMakeFiles/my_examples_path_qp_generated_oases.dir/my_examples/path_qp_generated_oases.cpp.o] Error 1 make1:[examples/CMakeFiles/my_examples_path_qp_generated_oases.dir/all] Error 2 make: all Error 2
I am using the version of acado-master downloaded today: Branch: master Commit: 2cde3c748856ca16a4460e05149c1e5de362526f Remote: acado/acado
Also have the same problem with acado-stable downloaded today: ~/ACADOtoolkit$ git rev-parse HEAD e0cc4b058e1dc60c4e57f306dc7c7db41a582451
Thank you very much!!
答案 0 :(得分:1)
我遇到了同样的问题
ACADO Toolkit目前存在一个错误,它有时会错误计算或完全忽略用于定义问题的OnlineData
变量。
该方法是setNOD()
,带有小写的“s”。
以下是一些可以帮助其他人的示例代码......
首先确保从github安装最新的ACADO源。
为ACADO定义非线性优化问题,如documentation:
所示DifferentialState x;
DifferentialState y;
Control u;
DifferentialEquation f;
f << dot(x) == 1.0*u;
f << dot(y) == 2.0*u;
OnlineData d0;
OnlineData d1;
OnlineData d2;
etc.
OCP ocp(0.0, steps*Ts, steps);
ocp.minimizeLSQ(W, h);
ocp.minimizeLSQEndTerm(W, h);
ocp.setModel(f);
ocp.setNOD(3);
OCPexport mpc(ocp);
您必须手动计算OnlineData
的号码,并将该号码加入setNOD()
。
然后编译,生成代码等,如文档中所述。
现在,您可以搜索导出目录中的代码,以查找以前被忽略的OnlineData
变量:
grep -R "od\[" *
另请注意,test.c
程序不会设置这些变量。
在您自己的代码中,您需要设置它们的值
如果您有3个OnlineData
,则将它们设置为沿着控制范围的每个步骤都是相同的,如下所示:
for (int i = 0; i < (N + 1); ++i)
{
acadoVariables.od[i * NOD + 0] = 1.0;
acadoVariables.od[i * NOD + 1] = 9.0;
acadoVariables.od[i * NOD + 2] = 5.0;
}
希望这有帮助!