Here are a few potential options to start with, particularly if you don't mind using electronics to accomplish the task:
1.) DZ-1240 Auto Stop & Reverse Module by Z-Stuff for Trains
2.) Blinking Auto-Reverse Controller by trainelectronics.com
3.) AC Auto Reverse Unit, Model ARUE by Pocono Mountain Lines
The ARUE is quite old, and I believe they may be out of production, but can occasionally be found at train shows.
4.) For something more sophisticated, and particularly if your haven't purchased the trolley yet, you also have the option of using one of several made by MTH, and streetcars as well, which have this kind of functionality, along with station stop announcements, built-in to them (and programmable).
5.) Also on the more sophisticated side check out this thread if you're looking to use loops at the ends of your trolley line:
It refers to using SuperStreets vehicles (taxis) instead of trolleys, but they work in the same way.
6.) Finally, if you'd prefer non-electronic instead there's always the classic bump-n-go trolleys that reverse using electromechanical means by running into bumping posts at each end of the line. No auto-stop for 30 seconds here though.