Skip to content

Faster than Real -Time support in GZ#23783

Merged
Jaeyoung-Lim merged 5 commits intoPX4:mainfrom
dirksavage88:set_rtf
Feb 26, 2025
Merged

Faster than Real -Time support in GZ#23783
Jaeyoung-Lim merged 5 commits intoPX4:mainfrom
dirksavage88:set_rtf

Conversation

@dirksavage88
Copy link
Copy Markdown
Contributor

Solved Problem

The new GZ simulation real time factor is configurable, however the service request has not been implemented in the GZ bridge.

partially fixes Fixes #23602

Solution

  • Configure the GZ bridge to send a service request with the simulation speedup value environment variable "PX4_SIM_SPEED_FACTOR"

Changelog Entry

For release notes:

Feature: Configurable real time factor in new GZ sim
New parameter: None
Documentation: Configurable via environment variable "PX4_SIM_SPEED_FACTOR"

Alternatives

Change the real time facto in gazebo world sdf manually, or make a world file specific to an increased RTF

Test coverage

Context

Related links, screenshot before/after, video

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
@dirksavage88 dirksavage88 mentioned this pull request Oct 7, 2024
31 tasks
@mrpollo mrpollo requested review from Jaeyoung-Lim and dagar October 7, 2024 15:00
@github-actions github-actions bot added the stale label Nov 7, 2024
@mrpollo
Copy link
Copy Markdown
Contributor

mrpollo commented Nov 8, 2024

@Jaeyoung-Lim @dagar can you please give this a review? seems like a good addition

@github-actions github-actions bot removed the stale label Nov 9, 2024
Copy link
Copy Markdown
Member

@Jaeyoung-Lim Jaeyoung-Lim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing thanks!

  • Just one small nitpick on the order of configuring the physics.

  • More of a question/note: Since we configure the physics in the gz bridge, this might cause problems when running multiple px4 instances. Might be worth taking it out to somewhere else in the future.

Comment thread src/modules/simulation/gz_bridge/GZBridge.cpp Outdated
Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
@hamishwillee
Copy link
Copy Markdown
Contributor

This will good and will need docs hint hint

@dirksavage88
Copy link
Copy Markdown
Contributor Author

@Jaeyoung-Lim is there anything preventing this from going in? I've addressed the comments so far. I think @hamishwillee is right that we will need a docs update after it goes in

@DronecodeBot
Copy link
Copy Markdown

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-sync-q-a-feb-19-2025/43827/3

@DronecodeBot
Copy link
Copy Markdown

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-sync-q-a-feb-19-2025/43827/1

@Jaeyoung-Lim
Copy link
Copy Markdown
Member

Jaeyoung-Lim commented Feb 19, 2025

@dirksavage88 As I commented above, you are configuring the physics only when a model exists.

However, physics is more of a world parameter and therefore should not be related to the model itself, but rather the world. For example, this would break if there are multiple vehicles in the simulation with the gz_bridge

Therefore I think it would be better if the config is done outside of gz_bridge.

@dirksavage88
Copy link
Copy Markdown
Contributor Author

dirksavage88 commented Feb 19, 2025

@Jaeyoung-Lim I'm going push back and say this is a nitpick. What is the functional benefit to placing the physics outside of the gz_bridge? If you have no model and just a world, what is the functional benefit to having physics with nothing for physics to act on?

Also the world services are created in gz_bridge here:

std::string create_service = "/world/" + _world_name + "/create";

Should not the physics also be configured along with the world services?

@Jaeyoung-Lim
Copy link
Copy Markdown
Member

@dirksavage88 Yes, and that needs to change if we want to support multiple vehicles.

@dirksavage88
Copy link
Copy Markdown
Contributor Author

@Jaeyoung-Lim okay that is making sense now. So there should be somewhere else in the code where we can do both world services and physics.

@Jaeyoung-Lim
Copy link
Copy Markdown
Member

@dirksavage88 Probably rethinking this - lets get this in as is, since I dont want to slow you down due to architectural improvements.

But lets put a note somewhere that we need to fix this, so that it flows nicely to multi vehicle support.

@mrpollo
Copy link
Copy Markdown
Contributor

mrpollo commented Feb 19, 2025

Also please create an issue to track this, make sure to assign yourself.

@dakejahl
Copy link
Copy Markdown
Contributor

this would break if there are multiple vehicles in the simulation with the gz_bridge

So this only breaks if each px4-sitl instance has a different value for PX4_SIM_SPEED_FACTOR. Which is probably pretty easy to screw up. I don't think there's a way to set this directly in the world SDF though. I agree we should get it in now and fix later.

@Jaeyoung-Lim Jaeyoung-Lim merged commit 75c0089 into PX4:main Feb 26, 2025
@hamishwillee
Copy link
Copy Markdown
Contributor

@dirksavage88 @Jaeyoung-Lim Re docs, is this as simple as updating https://docs.px4.io/main/en/simulation/#run-simulation-faster-than-realtime to mention Gazebo (GZ) supports this too?

Are there any specific things to think about that are different on GZ?

@dirksavage88
Copy link
Copy Markdown
Contributor Author

@dirksavage88 @Jaeyoung-Lim Re docs, is this as simple as updating https://docs.px4.io/main/en/simulation/#run-simulation-faster-than-realtime to mention Gazebo (GZ) supports this too?

Are there any specific things to think about that are different on GZ?

I think the COM_DL_LOSS_T param still applies, however I do notice that in the new gz with a speed up factor of 10x, I am not able to get local/global position to work. I am not sure if this was also the case for gz classic. I can get the x500 to arm in SITL with a speed up of 5x though

@dakejahl
Copy link
Copy Markdown
Contributor

dakejahl commented Mar 1, 2025

however I do notice that in the new gz with a speed up factor of 10x, I am not able to get local/global position to work

@dirksavage88 the issue is that this PR increases the time step rather than the real_time_factor. I have an open PR which is a large refactor of the the GZBridge and px4-rc.simulator which fixes this. If you want to try it out and leave a review!
#24421

@hamishwillee
Copy link
Copy Markdown
Contributor

hamishwillee commented Mar 6, 2025

Thanks very much.
Guys, when you merge something, please try update the docs. The chances of me missing stuff like this in autopilot PRs is high. I won't miss a PR against docs, even a trivial one.

Needs review: PX4/PX4-user_guide#3628

@dirksavage88 dirksavage88 deleted the set_rtf branch April 9, 2025 15:38
mrpollo pushed a commit that referenced this pull request Nov 24, 2025
* add rtf service to gzbridge

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

* physics before model spawn

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

---------

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(new) GZ Feature tracker

6 participants