Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with the Carvallo-Whipple Bicycle Model #446

Open
moorepants opened this issue Oct 23, 2020 · 4 comments
Open

Issues with the Carvallo-Whipple Bicycle Model #446

moorepants opened this issue Oct 23, 2020 · 4 comments

Comments

@moorepants
Copy link
Member

moorepants commented Oct 23, 2020

This example is live: https://pydy.readthedocs.io/en/latest/examples/carvallo-whipple.html. It mostly works but there are some hanging issues that should be addressed in that example and are related to the issues in #122

  • There is a divide-by-zero if q7 (steer angle) initial condition is set to zero. This returns nan from the underlying c-code.
  • The simulation is very sensitive to the epsilon value of the initial condition q7. It runs on some machines and not on others. Gives different results with a change in decimal place, 1e-7 instead of 1e-8.
  • It isn't clear the simulation results are reproducible across machines with q7 set to an epsilon that works on one machine.
  • There are some uses of 0.0 in the symbolic derivation (setting velocities to zero and inertia scalars to zero). If I change these to 0 or sympy.S(0) I get different simulation results (stable to unstable for example). I'm not sure why these would change the behavior.
  • Make sure that the dependent speed initial conditions are properly set. If u4 is nonzero, then u3, u5, and u8 are very likely to be non-zero because they depend on u4.
@moorepants
Copy link
Member Author

Here is some code to get the initial dependent u's:

eval_nonholonomic = sm.lambdify((u3, u5, u8, u4, u6, u7, q4, q5, q7, d1, d2, d3, rf, rr), nonholonomic)
def eval_nonholonomic_vector(u_dep, u4, u6, u7, q4, q5, q7, d1, d2, d3, rf, rr):
    u3 = u_dep[0]
    u5 = u_dep[1]
    u8 = u_dep[2]
    return eval_nonholonomic(u3, u5, u8, u4, u6, u7, q4, q5, q7, d1, d2, d3, rf, rr)
res = fsolve(eval_nonholonomic_vector,
       [0.0, 0.0, -initial_speed/sys.constants[rf]],  # guess
       args=(initial_roll_rate,
             -initial_speed/sys.constants[rr],
             0.0,
             0.0,
             initial_pitch_angle,
             initial_steer_angle,
             sys.constants[d1],
             sys.constants[d2],
             sys.constants[d3],
             sys.constants[rf],
             sys.constants[rr]))
initial_yaw_rate = res[0]
initial_pitch_rate = res[1]
initial_front_wheel_rate = res[2]

Quick an dirty way. For only setting an initial roll rate and rear wheel rate this doesn't change the results. Only u8 is non-zero and it can be calculated as I have it in the notebook.

@oliverlee
Copy link
Contributor

I'm getting very different results across two machines - which are also differing from the example.

@moorepants
Copy link
Member Author

I'm not surprised. You can see more lengthy explorations of issues here: #122 (which you helped on years ago). I think we should get the idea in PR #462 working to see if that solves things. If it does, then I need to rework PyDy's internals to match for the general case.

@moorepants
Copy link
Member Author

moorepants commented Feb 7, 2022

Also, the model gives the correct answers if Symengine is used to evaluate to arbitrary precision. So it is some kind of numerical rounding error.

Edit: see this comment #122 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants