Script to control train auto stop

Post your questions about object, route and train development here. Be sure to have consulted the documentation first.

Script to control train auto stop

Postby alvinwong on Tue, 29th Sep 2009, 05:18

I am using C++ to write plugin. I want to write a automatic stop. If I know where to stop (dist), how to calcalate the stopping curve and make it stop correctly?

I had made one that is not accurate, and I want to improve.


Thanks for helping!
Problems, solutions, problems, solutions...
Tired on these, and trying to make openBVE train Exterior, then...
Problems... ###again### Crazy...
Please visit http://www.hochun.nets.hk/discuz/index.php
User avatar
alvinwong
 
Posts: 240
Joined: Sat, 24th Jan 2009, 05:16
Location: Hong Kong

Re: Script to control train auto stop

Postby michelle on Tue, 29th Sep 2009, 08:03

If you want to work with a brake curve, you can make use of the following physical identity for uniform acceleration:

velocity = sqrt(2 * acceleration * distance)

where:
  • velocity is the speed of the train (expressed in m/s),
  • acceleration is the (in this case) deceleration of the train (expressed in m/s²),
  • distance is the distance from the stop point to the train (expressed in m),
  • and sqrt is the square root function.
All values used in the above formula should be positive. If you want to work with velocity expressed in km/h and acceleration in km/h/s, you can use:

velocity = sqrt(7.2 * acceleration * distance)

Given the allowed velocity, you can easily check whether the train exceeds it, and then apply the brakes. This, however, is just a starting point. You might want to incorporate that the train can brake at different deceleration levels (brake notches) for a smoother braking performance.

For more information on uniform acceleration, you can also check out the formulas on the respective Wikipedia page. I leave it to you (or to others) to develop this further.
User avatar
michelle
Site Admin
 
Posts: 1147
Joined: Mon, 14th Apr 2008, 20:36

Re: Script to control train auto stop

Postby alvinwong on Wed, 30th Sep 2009, 09:26

Square root is needed...

Thanks for your reply. I will further try to inprove.

How about the AI in openBVE? I think I would also try to refer to it...
Problems, solutions, problems, solutions...
Tired on these, and trying to make openBVE train Exterior, then...
Problems... ###again### Crazy...
Please visit http://www.hochun.nets.hk/discuz/index.php
User avatar
alvinwong
 
Posts: 240
Joined: Sat, 24th Jan 2009, 05:16
Location: Hong Kong


Return to Developing for openBVE

Who is online

Users browsing this forum: No registered users and 0 guests