Search code examples
c++drake

Reading contact_results creates algebraic loop


I have a working robot simulation in Drake. Now I want to output contact forces. ChatGPT and this post suggest:

const auto& contact_results = 
plant.get_contact_results_output_port().Eval<ContactResults<double>>(plant_context);

However, as soon as I introduce this line of code, Drake complains about an algebraic loop. I understand the concept of an algebraic loop but I am not feeding the values back into the system, I just want to cout them.

Why is this happening and what can I do to fix it?


Solution

  • In the end the problem was that I tried to read the contact information from a different thread without mutexes or anything, so it had nothing to do with an algebraic loop. The correct way to do it is from inside a monitor callback that gets executed every step.