Closed mohamdev closed 4 years ago
I found the solution :) With CppAD, you have to overload the if statement, using CppAD::CondExpOp
.
@mohamdev Hi Adjel, thanks for your question and I'm facing a very similar question when I'm using the aba() function in Pinocchio. Would you mind telling me a bit more details about how to overload the if/else statements? I think these if/else branch are built-in parts of the functions inside pinocchio and I don't how to do the overloading. Your help will be much appreciated! Thanks in advance.
@mohamdev Does this help: https://coin-or.github.io/CppAD/doc/condexp.htm
@bradbell Thanks for your reply! I'm not an expert in CppAd, and I guess what you mean is I have to manipulate the function in which there is an if/else branch, writing it into something like result = CondExpOp(left, right, if_true, if_false)
. However, the if/else seems to be in a function inside a library called Pinocchio and I actually don't want to modify its source code to avoid unexpected errors. I don't know if my understanding is correct and please correct me if I was wrong.
Besides, here is @mohamdev 's question in Pinocchio GitHub issues: https://github.com/stack-of-tasks/pinocchio/issues/1142 . Seems he has solved the problem by using CppAD::CondExpOp
.
@FenglongSong My mistake, I should have directed my comment above to you and not @mohamdev . Yes it does seem to me that @mohamdev has converted his AD comparison operations to conditional expressions. I was just trying to provide clarity as to the purpose and use of conditional expressions.
@bradbell ok I got it. This will be clear to be and thank you very much!
Hello,
First I want to thank you for your awesome work, which is very useful to me. I'm trying to perform some code generation but I have the following exception :
This exception occurs only when I run the code, the latter is indeed compiled with no errors. Here is my code :
I think the problem comes from the function
rotMatToQuaternion()
which converts a rotation matrix into a quaternion, but inside this function there are someGreaterThanZero()
tests. Here is the function :As you can see, the
GreaterThan
tests are performed on the values of the rotation matrix, which are not a part of the independent variables vector X. I think that is probably why the exception saysGreaterThanZero cannot be called for non parameters
. Indeed, this rotation matrix R is calculated from the independent variables vector X usingpinocchio::forwardKinematics(ad_model, ad_data, X);
. And then, once the forward Kinematics performed, I get the rotation matrix usingADRotMat R; R = ad_data.oMi[model.nq].rotation();
. Actually, I really need to convert the rotation matrix R into a quaternion because I want to compute the gradient of my Quaternion relatively to the vector X, that is why I haveCppAD::ADFun<CGScalar> fun(X,Quat_ad)
. I hope I was clear enough, otherwise feel free to ask me further questions. Thank you again :)