https://en.m.wikipedia.org/wiki/Dynamic_braking
Btw, many passenger trains have something like that as well, especially in the metro or tube: the stations are deliberately built slightly higher than the normal lines, so that you can convert kinetic and potential energy back and forth.
https://en.m.wikipedia.org/wiki/Dynamic_braking