I am sorry that this small step does not seem to help get some progress toward your goal. Many JMRI users run scripts without understanding the internal workings, only the results.
It is not clear to me that I understand the context of your intended application or your question.
Let me ask a trivial question that is, nevertheless, not clear to me: How many
sensors does your first example need for moving two locomotives?
As written, the two examples at the end of the script each control a single hypothetical locomotive and have a sensor at each end of some undefined physically selected route. Each "object" of the class named "BnFModTest" provides an expanded capability to duplicate of the ability to control a locomotive, as was done in the BackAndForth.py script. It also allows one to provide customized forward and reverse speed settings for each train.
Part of what I inferred from your original post was that you have at least two trains running back and forth on two separate locations on your layout, each with two physically separated sensors. Total of four sensors for two trains, or six sensors for three trains. Did I misunderstand that part of the post?
Also, I thought that I understood that you wanted the ability to take advantage of your RailCom sensors and decoders to allow other trains to cross into or just through one of those routes without causing a false trigger to the back and forth train running in the same region. I did not question how you were going to manage the intrusion of a manually controlled train into the automatically controlled route, and just assumed that you have a large enough space between the two ends of the route to allow a sufficient time interval to avoid unpleasant results. Perhaps I got that wrong too?
Our club is strongly considering the use of the Digitrax Transponders on a new expansion that is still in the planning stage, and I have made several stabs at understanding the Reporter capabilities in JMRI. Clearly, without any hands-on experience, I have a long way to go. JMRI seems to treat the incompatible Transponder and RailCom in manner that allows common software.
We have used a variation of the BackAndForth script for a small portion of the existing layout from time to time and again for a scenic animation device that only rotates back and forth.
Any further information or questions will be appreciated,
Cliff