Billboard sign electrical problem
An ore cart is not a toy , I suspect.  So there must be some large motor needing 100A or so to change directions.

You need to sense the cart for a stretch to stop at each end and during which the velocity ramp is reduced to zero at a rate the motor can handle. Then toggle the reverse switch and ramp up at the same rate as braking.  So there is still a bunch of work to create the cart sensors, create a ramp voltage compare to zero and toggle the direction relay.
Let the 100A or so Motor speed control do the PWM for you.

Design considerations.

Acceleration forces on chain and battery power consumption changing directions per cycle per hour.
Thermal stress on reverse acceleration
sensor reliability
failsafe endstop.

Can you consider a massive end-spring to return energy back to the cart and save battery power?