Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone px4 stable #22467

Merged
merged 16 commits into from
Dec 18, 2023
Merged

Standalone px4 stable #22467

merged 16 commits into from
Dec 18, 2023

Conversation

frede791
Copy link
Contributor

@frede791 frede791 commented Nov 30, 2023

Solved Problem

When launching PX4 using make px4_sitl you will always launch Gazebo as well. Historically, this was a hack in order to simplify the procedure of getting a simulation started. Over time this led to more and more encroachment of Gazebo models and worlds on PX4. This PR ends this. All gazebo models and worlds are outsourced to PX4/PX4-gazebo-models and PX4 will only know the airframe name and number that can then be transmitted to Gazebo using gz-transport.

It proposes two primary ways of starting PX4:

make px4_sitl gz_x500

This will start PX4 and Gazebo as it used to. The only difference is that now the models and worlds are placed in a submodule that is fetched from PX4-gazebo-models.

The second way, extends current functionality and can be run with:

PX4_GZ_STANDALONE=1 make px4_sitl gz_x500

This will start just PX4 and, if gz-server has not been started, will print a message that Gazebo cannot be found.
image
This warning disappears once Gazebo has been started.
In order to start Gazebo, a script called simulation-gazebo can be called from the PX4-gazebo-models repository. This script will download all models and worlds, if not detected, and place them in a folder called ~/.simulation-gazebo.
It is the primary proposed way of starting Gazebo, as it cleanly separates PX4 and Gazebo, requiring minimal exchange between the two.

All existing functionality regarding the various environmental variables that can be set (e.g GZ_WORLD or PX4_GZ_MODEL_POSE) can still be used as they have been up to now.

CMake targets for the worlds are now made from the submodule. There is no longer CMake magic relating to the model sdf files, but instead only in relation to the airframe numbers.

This PR would eliminate the need for PRs #22473 and #22437 to be merged.

Changelog Entry

For release notes: Ability to launch Gazebo independently of PX4.

New parameter: PX4_GZ_STANDALONE Used to start PX4 in standalone mode

Signed-off-by: frederik <[email protected]>
Signed-off-by: frederik <[email protected]>
ThomasDebrunner
ThomasDebrunner previously approved these changes Dec 1, 2023
Copy link
Member

@ThomasDebrunner ThomasDebrunner left a comment

Choose a reason for hiding this comment

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

Tested on my system, works fine

make px4_sitl gz_x500 --> Runs gazebo from PX4 like before

STANDALONE=1 make px4_sitl gz_x500 --> runs px4 without gazebo, waits for gazebo

Dropping from 1m leads to movement in the rc_cessna. Dropping from 0.5m leads to no movement.
ThomasDebrunner
ThomasDebrunner previously approved these changes Dec 1, 2023
@dagar
Copy link
Member

dagar commented Dec 1, 2023

If we want to truly untangle this going forward then this is backwards. PX4 launching standalone should be the normal case, then on top of that we should be able to optionally launch gzserver (as a convenience), and optionally spawn the entity (vehicle model).

Adding special environment variables to a launch is what contributed to this mess in the first place.

@frede791
Copy link
Contributor Author

frede791 commented Dec 1, 2023

@dagar Sure this can be done by reversing the conditions described in the changes. The question is then how you want to tell PX4 what it should launch (other than using env variables).

@frede791 frede791 marked this pull request as draft December 6, 2023 09:00
@frede791 frede791 requested a review from dagar December 6, 2023 16:30
@frede791 frede791 marked this pull request as ready for review December 6, 2023 16:31
@frede791
Copy link
Contributor Author

frede791 commented Dec 7, 2023

@dagar This is for review alongside the PRs in px4-gazebo models.

@frede791
Copy link
Contributor Author

frede791 commented Dec 7, 2023

Tested on my system, works fine

make px4_sitl gz_x500 --> Runs gazebo from PX4 like before

STANDALONE=1 make px4_sitl gz_x500 --> runs px4 without gazebo, waits for gazebo

This is outdated and no longer reflects the proposed functionality.

@frede791
Copy link
Contributor Author

frede791 commented Dec 7, 2023

@beniaminopozzan Could you test the different args please? I think i have tested them all successfully but maybe there is some cases I'm forgetting about.

@frede791 frede791 mentioned this pull request Dec 7, 2023
1 task
@frede791
Copy link
Contributor Author

@beniaminopozzan Ok I have reverted to the old structure. So now if you run make px4_sitl gz_x500 it will check if the .simulation-gazebo repo exists and if not download all models and worlds from PX4/PX4-gazebo-models and store them there.

Signed-off-by: frederik <[email protected]>
@frede791
Copy link
Contributor Author

Reverted back to using gz submodule rather than downloading at runtime. Keeps simulation-gazebo script the old way (so there is still a /.simulation-gazebo directory that the helper script will use at runtime, but only if its running in standalone mode.

@frede791
Copy link
Contributor Author

@dagar Please make sure to squash-merge this PR.

Copy link
Member

@beniaminopozzan beniaminopozzan left a comment

Choose a reason for hiding this comment

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

Thanks @frede791
I tested:

  • All standard make px4_sitl gz_* targets, all working as expected.
  • All the examples in the user guide, all working as expected

@frede791
Copy link
Contributor Author

@beniaminopozzan Thanks for the addition.

@ThomasDebrunner ThomasDebrunner merged commit 65e5328 into PX4:main Dec 18, 2023
87 checks passed
timzarhansen pushed a commit to timzarhansen/PX4-Autopilot that referenced this pull request Sep 3, 2024
simulation gazebo: move the gazebo models to submodule, allow for operation with external gazebo instance, independent of startup order. Allows drag an drop of models from gazebo fuel.

* rolled back updates

Signed-off-by: frederik <[email protected]>

* fixing empy

Signed-off-by: frederik <[email protected]>

* Update GZBridge.cpp to lower drop position

Dropping from 1m leads to movement in the rc_cessna. Dropping from 0.5m leads to no movement.

* Update STANDALONE env variable.

* Update STANDALONE env_variable on GZBridge

* Update src/modules/simulation/gz_bridge/GZBridge.cpp

Co-authored-by: Daniel Agar <[email protected]>

* test removal of x500

Signed-off-by: frederik <[email protected]>

* removed all models and reworked logic

Signed-off-by: frederik <[email protected]>

* remove model path in set_sdf_filename

Signed-off-by: frederik <[email protected]>

* filter resource path for world sdf

Signed-off-by: frederik <[email protected]>

* updated structure to keep old make px4_sitl

Signed-off-by: frederik <[email protected]>

* remove gz tools

Signed-off-by: frederik <[email protected]>

* import gz as submodule and reverse rc simulator logic

Signed-off-by: frederik <[email protected]>

* [gz-sim]: source GZ_SIM_RESOURCE_PATH only if PX4 starts gz server

Signed-off-by: Beniamino Pozzan <[email protected]>

* Typo fix

---------

Signed-off-by: frederik <[email protected]>
Signed-off-by: frederik <[email protected]>
Signed-off-by: Beniamino Pozzan <[email protected]>
Co-authored-by: Daniel Agar <[email protected]>
Co-authored-by: Beniamino Pozzan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants