【2023.10.21】 casadi debug 常见错误

14 篇文章 0 订阅
2 篇文章 0 订阅

1 索引越界

terminate called after throwing an instance of 'casadi::CasadiException'
  what():  .../casadi/core/mx.cpp:401: Assertion "in_range(kk.nonzeros(), -sz+ind1, sz+ind1)" failed:
Out of bounds error. Got elements in range [2,2], which is outside the range [-2,2).
已放弃 (核心已转储)

casadi::MX 符号矩阵已定义大小,访问索引超出矩阵范围

2 参数未赋值

 max v u min v u : 
opti0_p_2opti0_p_1opti0_p_4opti0_p_3
rhs @1=q[6:12], vertcat((q[:6]+(dt*(@1+((0.5*dt)*qdd)))), (@1+(dt*qdd)))
terminate called after throwing an instance of 'casadi::CasadiException'
  what():  Error in Function::Function for 'accelerationConsistency' [MXFunction] at .../casadi/core/function.cpp:249:
.../casadi/core/function_internal.cpp:146: Error calling MXFunction::init for 'accelerationConsistency':
.../casadi/core/mx_function.cpp:409: accelerationConsistency::init: Initialization failed since variables [umin, uraw, uall, a0, dv0, shatdw0, dw0, w0, te1, p1, a1, p0, shatdw0, r, te2, p2, a2, shatdw0, te3, p3, a3, shatdw0, te4, p4, a4, shatdw0, te5, p5, a5, shatdw0, minp] are free. These symbols occur in the output expressions but you forgot to declare these as inputs. Set option 'allow_free' to allow free variables.
已放弃 (核心已转储)

casasi::MX::sym 符号变量定义后需要初始化矩阵里的数值 = casadi::MX::zeros(m,n)
之后再赋非零值的符号表达,之后才可以用于符号计算

3 不等式约束下不满足运动时间要求


------- i = 2994/3024 ------ 
0 <= 0.00539938 <= 0 (viol 0.00539938)
Opti constraint of shape 12x1
At nonzero 0.
------- i = 2999/3024 ------ 
0 <= 0.00539938 <= 0 (viol 0.00539938)
Opti constraint of shape 12x1
At nonzero 5.
error while solving the optimization
Details:
 Error in Opti::solve [OptiNode] at .../casadi/core/optistack.cpp:157:
.../casadi/core/optistack_internal.cpp:1000: Assertion "return_success(accept_limit)" failed:
Solver failed. You may use opti.debug.value to investigate the latest values of variables. return_status is 'Infeasible_Problem_Detected'

扩大速度力矩约束,或者增加时间

4 矩阵的块操作 slice()

需主要,行列均需要Slice()切块,否则运行过程数据不正确!

using S1 = casadi::Slice;
uall(S1(0, 6), S1(0,10)) = a[0];

5 矩阵的乘法运算 mtimes(a,b)

uall(S1(12, 18), S1(30,40)) = cmx::mtimes( t0e[3]  , a[3]);

6 矩阵的 * 不是标准乘法!!!

casadi document ! ! !
In C++ and Python (but not in MATLAB), the standard multiplication operation *(using ) is reserved for element-wise multiplication (in MATLAB .*). For matrix multiplication, use A @ B or (mtimes(A,B) in Python 3.4+):
c++ 同样使用casadi::mtimes(a,b)

// python example:
print(y*y, y@y)
[[sq(y_0), sq(y_2)], 
 [sq(y_1), sq(y_3)]] 
[[(sq(y_0)+(y_2*y_1)), ((y_0*y_2)+(y_2*y_3))], 
 [((y_1*y_0)+(y_3*y_1)), ((y_1*y_2)+sq(y_3))]]

7 动力学等式约束未建立

u与a 未建立等式连续性约束,导致力矩未参与规划
牛顿欧拉迭代推导的符号表达

    cmx constraint_point ;
    constraint_point = cmx::mtimes( umin , minp) - u;

    return casadi::Function("accelerationConsistency", {qs, u, qdd}, {constraint_point});

缺少等式约束
加入加速度与力矩的等式关系后:
在这里插入图片描述

8 直接配点法 directcolocation 的动力学方程函数参数问题?

输入参数不是符号??

terminate called after throwing an instance of 'casadi::CasadiException'
  what():  Error in Function::Function for 'DCdynamics' [MXFunction] at .../casadi/core/function.cpp:249:
.../casadi/core/function_internal.cpp:146: Error calling MXFunction::init for 'DCdynamics':
.../casadi/core/x_function.hpp:332: For DCdynamics: Xfunction input arguments must be purely symbolic.
Argument 1(i1) is not symbolic.
已放弃 (核心已转储)
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值