Hello I have a issue with my simulation. I need to move a train with SimTalk from one Lane to another. I read in the Help that it is not possible to move a Train with the argument @.move, but why? Actually, as Help says, it just work with the exit control of a lane, but that is not a option for me.
In the attached file you will realize it is simple, just a sensor on a track that calls a method with the function @.move (destination). The second transporter is hitched to the first one. If I unhitch the second one, the method works great but due to that transporter is not a tractor, it will not move.
It's not possible to move a whole train, which consists of multiple individual objects, with one move-action. What you would probably have to do is:
Quite cumbersome, and of course you also have to ensure that there is enough free space on the target lane for all your transporters/tractors before moving them!
Couldn't resist Check out the attached example, not sure whether you can open it, though... In case you can't, here's the source code of my sensor-method:
(SensorID : integer; Front : boolean) is rStartPos : real; oDestTrack : object; rTrainLength : real; olTrain : list[object]; oTrailer : object; oCheckMU : object; do -- target position on other lane rStartPos := 15; oDestTrack := Track_Drain; -- move individual vehicles, if not part of a train if not @.isTractor then debug; if not @.insert(oDestTrack, rStartPos) then debug; end; return; end; -- train is at least as long as the tractor rTrainLength := @.MULength; -- get whole train olTrain.create; oTrailer := @.getRearWagon; while (oTrailer /= void) loop -- add to train list olTrain.append(oTrailer); -- add to train length rTrainLength := rTrainLength + oTrailer.MULength; -- get next trailer, if any oTrailer := oTrailer.getRearWagon; end; -- check that there is enough space for an insert .ModelObjects.DummyVehicle.MULength := rTrainLength + 0.001 * olTrain.Dim; oCheckMU := .ModelObjects.DummyVehicle.create(oDestTrack, rStartPos); if (oCheckMU = void) then -- not enough free space! debug; return; else -- enough space, delete the check-vehicle oCheckMU.delete; end; -- unhitch all trailers and insert them into other track, start at end for local i := olTrain.Dim downto 1 loop -- get trailer oTrailer := olTrain.read(i); -- unhitch from train oTrailer.unhitchFront; -- update (remaining) train-length rTrainLength := rTrainLength - oTrailer.MULength; -- move to destination track (leave a small gap, so that the collision-control will be called) if not oTrailer.insert(oDestTrack, rStartPos - rTrainLength - 0.001) then debug; end; -- restore trailer-velocity (seems to be set to zero after the insert...!?) oTrailer.speed := oTrailer.class.speed; next; -- move the tractor and let it wait until its train is completely re-hitched @.a_iTargetNumTrailers := olTrain.Dim; @.a_iNumTrailers := 0; if not @.insert(oDestTrack, rStartPos) then debug; end; @.stopped := true; end;
The tractor is stopped after being moved to the new track. In the collision-control of the trailers/wagons, I check whether the original train has been re-hitched completely, and then un-stop the tractor. That's "all".
Thanks and sorry for the delay. I didn't use your solution but it helped me to develop my own. Basically what I was trying to do is to move a train within the same track when it collides with a stopped train. I realized that @.move doesn't work with trains so what is nessesary to do is to unhitch every cart, move it forward, and hitch again by itself.
My code seems like this:
var vagon:object var tractor:object var rearVagon:object var i:length i:=1.6 tractor:=@ //debug if @.FrontMU.getTractor.stopped=true or @.FrontMU.getTractor.collided=true and @.IsTractor=true //and Ocupado=false if @.~.Ocupado=false @.unhitchrear vagon:=@.RearMU @.insert(@.getLane,@.~.TractorEntrega.FrontPos+8) repeat rearVagon:=vagon.getRearWagon vagon.unhitchrear vagon.insert(@.getLane,tractor.FrontPos-i) vagon.speed:=1.1 vagon:=rearVagon i:=i+1.6 until rearVagon = Void end end