Gazebo resources: Tutorials | Q&A | Documentation | Blog

Limits of the Simulation

Hi there!

I working on a simulation of train using Gazebo. The idea is to import a track from openstreetmap (or openrailwaymap) and create and load the needed models dynamically. In other words I planning to create the railway from waypoints (x y z roll pitch) and place objects around the railway like houses, bridges, signs, etc… Also the surface should be roughly created. It is not important to have a photo realistic simulation. At least I will mount some sensors in front of the train to be able to test assistant systems, up to a autonomous train.

So my questions to the community are now:

  • How big a world can be? Is the memory the only limitation or is/are there more. For example will the FPS drops if the world is to big?
  • My basic approach is to spawn objects in front of the train (~700m in front of) and delete the objects behind the train. Do I run in trouble? Can I use dynamically spawning or is it better to load all objects at the begin?
  • I not sure about if I should simulate the railway itself or just move the train (without physics, static object). What do you think? I guess to simulate a normal train driving on a railway will end up in some problems. At least I need swinging and bumping train for the sensor quality. I think it is possible to apply forces to the sensor without do it to the whole train. Of course then the sensors and the train would be different objects.

What do you think about the planned simulation? Is Gazebo the right tool? I’d appreciate your view!


Christian Merkl

1 Like

Hi Christian,

That sounds like a fun project, I’ve never seen a train on Gazebo :slightly_smiling_face:

  • The FPS will drop depending on how many models you have on the camera’s frustum. You should be able to tweak the camera’s near and far clipping planes to limit how many models it is trying to process.

  • Another number which will drop as you add more models is the physics’ real time factor (RTF). You should make sure the models you add to the sides of the track are marked as <static>, so the physics engine ignores them for dynamics purposes. Depending on the sensors you’ll be using, you could also get rid of <collision>s so there is no collision checking against them.

  • Dynamically spawning and deleting objects on demand sounds like the right way to go for your use case. We did that in a smaller scale for the Space Robotics Challenge and it worked well.

  • If you’ll have a lot of sensors of different types which should be generating data that is consistent across them, I think it makes sense to let the physics simulation take care of the train. Of course, the simulation can be made arbitrarily complex, so it will be up to you on how much fidelity you want to put in. For example, you won’t have the train just sliding on a prismatic joint because there won’t be any swinging, but on the other hand, modeling the real track parts and the mechanical interactions between them could be overkill. It’s all about finding the right balance for your use-case.

Hope this helps!

Thank you for the reply,

Your answer helps me. I performed some performance tests and it seems only the memory is a limit in the simulation (without using the GUI. I think the camera of the GUI has no frustum limitation). But I got problems during the model spawning. Every time a model is spawned the simulation halts for short moment. I’m using a ROS service for spawning.

Is there a better way to spawn objects? Maybe I can use a plugin. How do you would spawn the models?



You can change the near and far clipping planes on the left panel under GUI, or you could have a plugin change it programmatically.

That would need some deeper investigation. I can’t think of a reason for the ROS to service to be less efficient than other methods unless it is blocking for some reason. The most likely reason is that the model is large and takes a bit to spawn. You could try spawning with the gz model command line tool and see if it makes a difference. Also, make sure you’re not using meshes which are more complex than they need to be.

Thanks again! Ok according your answer I think it is not a good idea to spawn continuously models, because I don’t know the final model size. Btw I used for the performance tests “house 1”, “house 2” and “house 3” from the gazebo model database.

Maybe it is better to pause the simulation after specific distances and spawn a group of models. Then go on with simulation. FYI I spawned a 10km long railway. On left and right side houses were placed. I moved a train on the railway including a lidar and camera up to velocity of 100m/s and it looks great. The camera published constant with the expected frequency.


Hello @knueppl

I’m new to gazebo, could you please explain how you were able to create those rail tracks. Thanks

Hi Paul,

we wrote a rail mesh generator. And we wrote a plugin to move on the railway, too. I would like to share the code, but unfortunately the code was written for a customer. I can’t share that one!



Thanks for the response @knueppl

Oh I see. I was wondering if it is possible to use a .dae file of rail tracks in gazebo because all I want to do is create a railway track environment for a drone.


Our first meshes were created using Blender. You can simply create a cross section/profile (I don’t know the right English word) and extrude that along a path. I were able to do that after some tutorials.



@knueppl Thanks again

I Will look into how to create that cross profile in blender. So far, I’ve been able to simulate the tracks. I did this by creating a .world file with the .dae file included in it under the tag. Now i’m looking to add the erle-copter to that environment just like the way it is here but instead of the drone being in an office, I would like it to be on the rail track I imported to gazebo. Any ideas how to do that?

@knueppl Good morning! Our of curiosity did you find an answer to your question on how big the world can be? What is the largest world you have implemented successfully at a reasonable frame rate? Thanks and good work, looks like a cool project!

Hi @knueppl and all!
I have recently started learning about Gazebo for railway simulation as well and found this topic by accident when trying to find an approach or maybe even the solution to my problem:

How can I make my robot/train follow an arbitrary path, e.g. a path or profile I imported from openrailway or just generated with a CAD tool? Or is there another way to simulate the track guidance?

Using a camera and image processing to detect the path and make the robot “follow” it is not railway-appropriate. I was hoping that I could define a virtual point of the robot/train that always lies on a static profile/curve (which will be the track axle) and then I just apply an unidirectional velocity to the robot/train. But I couldn’t find a way to do so in the last 2 months… :frowning:
I even thought of just placing a rail track and using a rail vehicle with wheelsets then appyling a velocity. But then the vehicle will show a sinusoidal run due to the conical wheel shape?

Thanks in advance for any suggestions or thoughts!!


Hey there!

I implemented a plugin that moves the train on the track. This was really fun. But I can’t share that code, because a customer paid for it.

But it isn’t hard. One day work and all will be fine.

You don’t need to share the actual code but could you share the basic idea of the approach please (like what boundary conditions or types of joints)?

Well I hope I can do that. So lets try:

What kind of train we are talking about? With fixed or rotating bogies? For example here rotating bogies.

Thank you for trying!!

I see in your picture that you successfully made the bogie rotate around its z- and y-axis, lovely!

Actually I will need both later: a wagon with two bogies (each bogie has two wheelsets) that rotate around their z-axis and a wagon with two wheelsets which in my opinion could be simplified as one rotating bogie.
There will be one vehicle/locomotive with two wheelsets. This loco pulls freight wagons. A freight wagon may have either two wheelsets or two bogies.

But for now - if I may suggest - I would like to start with just with one vehicle with two wheelsets (see picture) which is the same as one vehicle with one fixed bogie.

That is a nice bogie :stuck_out_tongue: Okay lets try:

  • estimate the position of the first axis (simply move the distance on the trajectory)
  • use a circle or sphere (2d or 3d) and calculate the position of the next axis. The radius of the c/s is the distance between the axes. Intersection equations can be found on the internet if you are not familiar with math.
  • calculate the position of the bogie ((position axis 1 + position axis 2) / 2)
  • calculate the orientation of the bogie. The two axes positions give you an orientation.

Thats it!


I am not sure if I got you correctly because I don’t know how to calculate the intersection between a circle with known radius and an arbitrary curve section:

a)-b) Just move the front axis’ central point along the trajectory (arbitrary track) for a given distance.
c) In 2D: put a circle with radius equals to the distance between the two wheelsets on the new front axis’ central point. Calculate the intersection between the circle and the trajectory which is the new rear axis’ central point.
d) Connect these two new points and get the orientation of the bogie, also the new position of the bogie’s central point.?


  • If I can just move the front axis’ central point along the trajectory, can I not also just move the rear axis’ central point for the same distance as a) along the trajectory?
  • Have you turned off the gazebo’s physics engine and do you feed the calculated position into the bogie’s pose?
  • How did you compose your rail track? A set of small linear sections (discrete), a continuous curve or a set of straight and curved (with known radii) track sections?

Thank you very much :slight_smile:


your drawing looks great! That is exactly what I mean.

I used a set of short straight line as trajectory. I start with a rough trajectory and smoothed it every time using splines (for example libeigen provides these kind of functions). After the train movement is pretty good.

To calculate the intersections is easy actually. You can find a lot of equations on the internet. The problem is just you will get two solutions, because of the circle equation (x² + y² = r²). So you have to walk in the right direction on your trajectory :stuck_out_tongue:

By the way, that approach works in 3D too. The only thing have to change is a sphere equations has to be used. But the algorithm is exactly the same.