locuslab / mpc.pytorch

A fast and differentiable model predictive control (MPC) solver for PyTorch.
https://locuslab.github.io/mpc.pytorch/
MIT License
872 stars 146 forks source link

Gym pendulum example not working #25

Closed LemonPi closed 4 years ago

LemonPi commented 4 years ago

My motivation for trying out box-DDP was the failure of iLQR on the pendulum swing up task. It tries to apply more torque than allowed and always swings back and forth on one side. This project has working pendulum swing ups with the mpc/env_dx/pendulum.py environment, but I haven't been able to get it to work on the gym pendulum environment: https://github.com/LemonPi/mpc.pytorch/blob/master/examples/gym_pendulum.py

It would also swing back and forth on one side and exit some iterations in from not converging. Any ideas why (I can silence the exit with exit_uncoverged=False but I meant why it's not working as the existing pendulum)? ezgif com-video-to-gif

bamos commented 4 years ago

Hmm, sometimes it can be sensitive to having theta as the state rather than the sin/cos transform of theta

LemonPi commented 4 years ago

Ah OK I found the problem - I needed to normalize the angle after taking dynamics (keep between -pi,pi).