Here is a version that works in 2.79 (and up).
The same rig I used in 4.0 did not work in 2.79. This version does not work up and down hills/ramps (It will cause glitches) , it is fine on a flat curve (floor).
I used a more simple rig but the whole thing is still complex.
Here is the file:
Casters279.blend (862.4 KB)
Explanation:
The rig
Each wheel has a rig that determines the direction of the casters. The rig is 2 bones. One is shrinkwapped to a circle the other has an IK constraint that points to the shrinkwrapped bone and copies the location of the circles.
Due to some slight glitches I added an additional “track to” constraint to the IK bone to stabilize it.
The IK bone gives the direction of the casters and wheels. This gives you the “flip”.
The curve.
The setup needs to use a curve to get a distance traveled value to rotate the wheels correctly with the distance traveled.
I have used a curve and a curve modifier (not a path and follow path).
This is because I have always ran into problems with the follow path method, getting the wheels to rotate correctly when the “trolley” goes over 180º (they stop and start going backwards).
The casters shake a little due to the curves resolution if you increase its resolution they will be smoother, I left the shake because real world casters do shake a bit.
The “drive control arrow” is what you have to keyframe to get the trolley moving (the wheels will roll accordingly). You have to move it on its y axis only (backwards and forwards) I have locked the other axis’s.
The real movement of the “drive control arrow” is only on its y axis (even though it is deformed by the curve), so I needed a drivebone that copies the location of one vertex group at the back of the “drive control arrow” and tracks another at the front. As this bone follows the vertex groups it will send the trolley around the curve.
Edit
-The trolley and the shrink wrap circles are parented to an empty which is parented to the drivebone (you could do it without the empty)-
The ik bones copy the location of the circles.
The driver:
The wheels rotate thanks to a driver on each wheel, (in Blender 2.79 you have to enable python auto-execution in the file preferences)
The driver looks like this.
The wheels will automatically speed up slow down and stop when the trolley moves.
To change the general speed of the rotation (it will vary depending on the size of the wheels) you just have to change the last multiplication factor. In my case *3 (I did not calculate the circumference of the wheels exactly I just set it more or less)
The first part of the driver is what I was so happy about when you posted the question.
It give me a positive 1 and a -1 when the casters flip so that the wheels rotate in the right direction when you push the trolley backwards and forwards before and after the flips of the casters.
I think that is about it, I know it is still not simple, but the result is lovely!
If you find a more simple way to get the same effect please post it (be sure to get the casters flipping and wheel rotation right!)