DAIRLab / dairlib

MIT License
66 stars 26 forks source link

dircon segfault adding post impact velocity constrain when no impact #218

Open ShaneRozenLevy opened 3 years ago

ShaneRozenLevy commented 3 years ago

I recently encountered a very strange bug in dircon.cc. When adding the impact constraint when their is not impact (pre_impact_velocity == post_impact_velocity) the code will segfault (Line 252). This does not seem to happen for every robot (planar walker is fine), but it does effect both Spirit and Cassie.

I found that changing line 249/250 from: auto pre_impact_velocity = state_vars(i_mode - 1, pre_impact_index) .tail(plant_.num_velocities()); to: auto pre_impact_state = state_vars(i_mode - 1, pre_impact_index); auto pre_impact_velocity = pre_impact_state.tail(plant_.num_velocities());

Fixes the issue. I don't understand why this fixes the issue because at a glance the code should do the same thing.

Here is a branch where examples/Spirit:run_spirit_jump fails due to this bug: https://github.com/KodlabPenn/dairlib/tree/dircon_segfault_post_impact_vel_demo

yangwill commented 3 years ago

Haven't looked too deeply yet, but I think it's possible that the auto keyword is responsible.

yangwill commented 3 years ago

Declaring pre_impact_velocity as auto makes it type Eigen::Block and declaring it as a VectorXDecisionVariable makes it type Eigen::PlainObjectBase. The Eigen::Block declaration seems to cause issues in the drake symbolic formula.

mposa commented 3 years ago

Yes--coming to the same conclusion here as well. I'll open a quick PR.