Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Missing Topic: How to integrate customised Gazebo copter models into the code base #398

Open
hamishwillee opened this issue Dec 21, 2017 · 73 comments
Assignees

Comments

@hamishwillee
Copy link
Collaborator

From #391 "Another nice to have would be how to integrate customised gazebo quadcopter models into the code base. Took me a bit to figure that out and I’m still not sure that I’m following best practices."

  • Do we have advice on that?
  • Who is best person to ask how that should be done
  • Where best place to document that?
  • What are the sections/sub questions that would need to be answered for this - e.g. how to dimension the motor models
@hamishwillee
Copy link
Collaborator Author

@jannsta1 ,@TSC21 suggested we open a standalone issue for your question in #391. Do you think you might be able to share the approach that you used to seed our documentation efforts? My experience is that it is much easier to get feedback if you say "I did it this way, is that right" than to ask for someone to start the docs from scratch.

@jannsta1
Copy link

Hello @hamishwillee, perhaps this is a useful starting point?:

Creating custom gazebo models for use with px4 sitl

There are 2 situations where this is useful. Specifying a new physical model and/or specifying a new px4 software environment. These can be achieved independently but both cases require a rebuild of the posix-configs build.

Incorporating a custom physics model

  • Guides for creating compatable models can be found elsewhere (e.g. on the rotors website. Looking at the existing models in /Firmware/Tools/sitl_gazebo/models is also a good starting point).

  • Once created, the custom model is added to /Firmware/Tools/sitl_gazebo/models along with any related mesh and .sdf files.

  • we also must create a world in /Firmware/Tools/sitl_gazebo/worlds

    • it appears like this has to match the name of the model??

Defining the px4 modules / parameters

  • a config file must be added to; Firmware/posix-configs/SITL/init/lpe (copying and renaming an existing config is a good way to start).
  • nb lpe is an example, this must be changed to the desired build type.
  • this config file is where sitl modules and initial px4 parameters are specified. Again these files are relatively self-explanatory so looking at existing files in this location a good way of understanding how they work.

Building with the custom model

  • Once created or modified, the whole posix-configs build must be repeated in order for the model to become available.

  • the model target name must be added to: Firmware/src/firmware/posix/sitl_target.cmake

    • it is added to the following line (currently line 84 in release 1.6.5):
set(models none iris iris_opt_flow ... rover hippocampus <add your model name here>)
  • The model is parsed by /Firmware/Tools/sitl_run.sh so it is worth examining this bash script for an understanding of what happens in the build process.

Comments:

  • It would be beneficial if the step of adding to the list of models in the .cmake file was not necessary.
  • I think the solution to this as it stands is to fork rather than clone the repo but this involves merging/rebasing for each update.
  • More flexible .world file usage may be of interest for some users (those not launching gazebo and mavros seperately).

@hamishwillee
Copy link
Collaborator Author

Yes @jannsta1 - definitely. I will have a proper look at this after Xmas (away today). Thank you!

@TSC21 in the meantime, can you look at the advice above and comment

  • what else needs to be said/what would you like to say
  • are there better ways to do the above
  • can we address any of those comments?
  • is there anyone else you suggest we involve in this discussion?

@hamishwillee
Copy link
Collaborator Author

@TSC21 Appreciate you may be off on holiday. Do you think you could ETA when you might have time to discuss this/ and suggest others that might be interested in being involved?

@TSC21
Copy link
Member

TSC21 commented Dec 27, 2017

@hamishwillee Sorry I missed the above. I will have write some comment soon.

@hamishwillee
Copy link
Collaborator Author

Thanks @TSC21 - I'm watching you :-)

@TSC21
Copy link
Member

TSC21 commented Jan 3, 2018

Yeah just cleaning and tightening some stuff on sitl_gazebo now and will get back to docs after, including this.

@mamariomiamo
Copy link

is there any update with this issue? :)

@hamishwillee
Copy link
Collaborator Author

is there any update with this issue? :)

@TSC21 ?

@kuiskas
Copy link

kuiskas commented Sep 26, 2018

Hi,
did the procedure change? I have been working in an older version, but now I wanted to upgrade to 1.8 and there is no ekf2 or lpe config files... in the step Defining the px4 modules / parameters as it used to be under posix-configs/init.
Can somebody tell me how to implement now the px4 parameters for sitl?
thanks in advance

@kuiskas
Copy link

kuiskas commented Sep 26, 2018

I found it (I believe) it is moved to ROMFS/px4fmu_common/init.d-posix, is that right?

@hamishwillee
Copy link
Collaborator Author

@kuiskas I think so. The recent changes for startup in posix and nuttx are captured in System Startup

@lamping7
Copy link
Member

lamping7 commented Sep 28, 2018

Some of that above is not necessary depending on what is being done or what the objective is. LPE normally shouldn't be used, you don't need a world, and you don't need to touch make. Just follow the existing models as a guide and edit models, rcs, and launch params approperately.

@jannsta1
Copy link

@lamping7 - could you confirm the directory that a custom rcs file for a posix_sitl_default build should go (running with sitl/gazebo)? Have tried putting my custom file, 'bee', in Firmware/build/posix_sitl_default/tmp/rootfs/etc/init.d-posix but I get the following error:

INFO  [Unknown] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
Error: Unknown model 'bee'
etc/init.d-posix/rcS: 48: exit: Illegal number: -1
ERROR [Unknown] Startup script returned with return value: 512```

@lamping7
Copy link
Member

lamping7 commented Sep 29, 2018

@jannsta1 it doesn't matter where you put it if you're just using a launch file to spin all this up as long as you change the parameters in the launch file to point there. You can also look at the supplied launch files to find the default location and put it there (not after v1.8.0).

@jannsta1
Copy link

Oh yeah, makes sense, thanks! - sorry should have gotten that. The updates to the build procedure is apparently making the code much easier to use / interface with. Its just a bit of overhead rejigging launch files and unlearning my work arounds from before.

@ChuplesKai
Copy link

I've also been trying to work through this and make it work, but I'm not having much luck. In addition to the above instructions, I noticed that there's also a CMakeLists.txt in the configuration folder (Firmware/ROMFS/px4fmu_common/init.d). Changing this has not helped get things running.

@lamping7 When you say that you need launch files to point to the model, which argument to the script are you referring to (the first argument or what comes after the -s)?

@lamping7
Copy link
Member

lamping7 commented Oct 2, 2018

@bkueng Did some magic getting all this cleaned up, but it still essentially works the same, from what I can see (correct me if I'm wrong Beat, I haven't tried my custom models with master yet (still on v1.8.0)). Here are the main PRs: PX4/PX4-Autopilot#10173, PX4/PX4-Autopilot#10222; with some minor documentation changes here #600.

One new thing with launching the px4 app with a custom model is the -s for specifying the startup file. Before it was more of a positional arg. Anyway, just put the whole path and name of the startup file after the -s: https://github.com/PX4/Firmware/blob/181b2f69ed53d3c4d011f2b5465fac4c16e0ecd9/platforms/posix/src/main.cpp#L558 and https://github.com/PX4/Firmware/blob/181b2f69ed53d3c4d011f2b5465fac4c16e0ecd9/platforms/posix/src/main.cpp#L205

The cool thing that was added (that you normally won't be using with a custom model is the auto rcs loading): https://github.com/PX4/Firmware/blob/719bfd10730310f3b897dd7f6f0c44d24eb3d19a/ROMFS/px4fmu_common/init.d-posix/rcS#L42. So, by default it loads the generic startup and auto selects the right one according to the vehicle. None of this matters for your custom model though.

@lamping7
Copy link
Member

lamping7 commented Oct 2, 2018

Additionally, in regards to "where to put the startup file" you can't just drop it in a folder anymore, like you used to be able to (my comment a few above this, may be misleading) PX4/PX4-Autopilot@273988c#diff-277741a901ccb3e1f2c296310691a8e6. You have to change the arg manually. Perhaps we should put the rcS arg back in the launch file? This will allow users to avoid having to directly modify the launch file. Any opinions here?

@bkueng
Copy link
Member

bkueng commented Oct 2, 2018

Previously the way people did it was to copy an existing rcS file and do their modifications. That partially worked because the file was self-contained. However this was never a good solution because:

  • when upstream added/removed modules the copied rcS file would break
  • changed parameters in the upstream rcS files could lead to more subtle errors, like bad tuning gains.

Essentially you would have to maintain the whole rcS file yourself.

I see 2 solutions with the new structure:

@lamping7
Copy link
Member

lamping7 commented Oct 2, 2018

Yeah. That makes sense. But for now users can just maintain the whole rcS as how it previously was.

@jannsta1
Copy link

jannsta1 commented Oct 2, 2018

I get some errors from a custom sdf file that previously worked OK - my sdf file is called bee but is pretty much the same as the old typhoon_h480 sdf. If I set -s etc/init.d-posix/bee when launching the px4 node I get:

etc/init.d-posix/bee: 105: etc/init.d-posix/bee: vmount: not found
etc/init.d-posix/bee: 106: etc/init.d-posix/bee: camera_trigger: not found
etc/init.d-posix/bee: 108: etc/init.d-posix/bee: mavlink: not found
etc/init.d-posix/bee: 109: etc/init.d-posix/bee: replay: not found

@lamping7
Copy link
Member

lamping7 commented Oct 2, 2018

You need to either revert back to 1.8.0 or fix your startup file according to the new way all this is arranged. Those modules are not in the same place. See the PRs I posted above.

@ChuplesKai
Copy link

After reading through some of the recent comments I've made some progress on this, but I'm not sure I'm understanding the whole process. I now have files for my custom airframe in both px4fmu_common/init.d and px4fmu_common/init.d-posix (since I'm trying to do SITL over our custom SDF), and both are using the unique identifier 0001 (is that allowed as an autostart ID?).

PX4 no longer seems to complain about finding the vehicle, but now I am getting Error: no autostart file found as an error. I thought that it should use some generic autostart script, but it seems I was mistaken. Where do I need to add this custom autostart?

@bkueng
Copy link
Member

bkueng commented Oct 3, 2018

@ChuplesKai What you are doing sounds correct, but I'd have to see all your changes to be able to diagnose it. 0001 should be fine. What are your file names and what vehicle names do you use?
The file in init.d-posix (you are doing it in-tree, right?) needs to be named 0001_<vehicle>.

@jannsta1
Copy link

jannsta1 commented Oct 3, 2018

OK, for a sanity check is $ make posix_sitl_default gazebo_typhoon_h480 currently working without any warning messages? I see:

INFO  [Unknown] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
Error: no autostart file found
etc/init.d-posix/rcS: 155: exit: Illegal number: -1
ERROR [Unknown] Startup script returned with return value: 512

I think this was working before (post the build changes discussed here) but I've tried completely wiping and re-cloning the firmware and all submodules and rebuilding and I still see this error.

@bkueng
Copy link
Member

bkueng commented Oct 3, 2018

0001 should be fine.

Just had another look, you cannot use 0001, because the preceding 0's will be stripped.

OK, for a sanity check is $ make posix_sitl_default gazebo_typhoon_h480 currently working without any warning messages? I see:

Indeed, I broke that :/ I'll look into it, it's because of the additional 6011_typhoon_h480.post file.

@bkueng
Copy link
Member

bkueng commented Oct 3, 2018

Fix is up: PX4/PX4-Autopilot#10631

@lamping7
Copy link
Member

lamping7 commented Oct 8, 2018

Have you looked at the gazebo output when passing the verbose flag in the launch file?

@ChuplesKai
Copy link

@lamping7 thanks for the advice! I didn't think Gazebo was having trouble, but putting that verbose flag true reveals a very different story. Hopefully this will let me fix whatever is upset.

@taleteorganista
Copy link

Hello, does anyone know how to set and launch px4 sitl using a user-defined world file?
I'd like to use a custom world file but I do not know how to make posix it... I do not want to artificially modify an existing world (as I've done so far...) I didn't find any documentation, I would appreciate any suggestions.

@jannsta1
Copy link

There is an argument 'world' in the px4 launch files (e.g. see posix_sitl.launch) you can pass the file path of your custom world to this parameter in the usual way.

@taleteorganista
Copy link

@jannsta1 Thank-you, it works!

@hamishwillee
Copy link
Collaborator Author

@lamping7 you make a very good point where you say:

I'm not really sure what is confusing you: I think it's the 10 month old info at the top.

@lamping7 @jannsta1

We're at the point now that the current state of this needs to be a PR. That we can work through and test. Then future change and issues can be discussions against a clear baseline. Can one of you guys volunteer to create a PR based on our current knowledge? Then we'll ask the other and @ChuplesKai if they can test those instructions.

Looking at this.

NOTE In general I am wary of tutorials. They are great if every step is very similar for all cases, but have a tendency to miss things that are off that centre path. So what I propose here is that whether or not we use a tutorial to illustrate, we start with the "these are the topics that we want to cover" as headings, and then start filling them in. @jannsta1 seems to have done that well but I'm not the right one to judge.

Thoughts?

@hamishwillee
Copy link
Collaborator Author

PS. We know we want the structure to include topics related to modelling the motors. @TSC21 proposed some topics needed: importing an URDF from SolidWorks and convert it to an SDF, what plugins to include in the model, modelling the motors, modelling the control surfaces ...

I am happy for many of these to be just TBD in the PR. But would be good if we could capture all the topic headings that we eventually intend to populate. So if there are any you would like to see, please add here.

@hamishwillee
Copy link
Collaborator Author

@lamping7 @TSC21 - Jan does not feel confident to create the initial structure of topics. Would you be willing to do so and populate with the current steps? (As discussed above: #398 (comment))

@TSC21
Copy link
Member

TSC21 commented Nov 26, 2018

@hamishwillee Yeah I will do that along this week.

@taleteorganista
Copy link

I would appreciate a documnetation on how to add sensors to the copter sdf file. I'd like also to understand how to perform multi-vehicle simulation with custom sensors (i.e. one copter with camera, another with laser scanner and so on...) and how to model my own drone. Thankyou

@hamishwillee
Copy link
Collaborator Author

@TSC21

Yeah I will do that along this week.

Nag nag nag

@TSC21
Copy link
Member

TSC21 commented Dec 3, 2018

@hamishwillee I have a initial structure for it but I still feel some things are missing. Been out of bandwidth, sorry.

@hamishwillee
Copy link
Collaborator Author

@TSC21 That's fine :-) I'll keep nagging.

@Veilkrand
Copy link

What I do for using my own models without creating additional PX4 is to keep the same target and vehicle name iris and pass my model path with the sdf argument.

@hamishwillee
Copy link
Collaborator Author

@TSC21 And here I am again :-)

@TSC21
Copy link
Member

TSC21 commented Dec 12, 2018

What I do for using my own models without creating additional PX4 is to keep the same target and vehicle name iris and pass my model path with the sdf argument.

This is not the point of the discussion here. This is rather if one wants to have a proper simulation of their vehicle, how can one add it to the PX4 SITL pipeline and Gazebo.

@TSC21 And here I am again :-)

@hamishwillee ahah I know sorry, have been quite busy lately.

@RicardoM17
Copy link
Contributor

Any progress here @hamishwillee ?? now it's my turn to nag 😝

@hamishwillee
Copy link
Collaborator Author

@RicardoM17 That's a question for @TSC21 :-) I'm not going to even attempt to progress this without him.

@Oliver-ss
Copy link

I'm not really sure what is confusing you @jannsta1 and @ChuplesKai: I think it's the 10 month old info at the top. I also don't think it is understood how the setup and launching works. The basic thing to know that might remove some confusion is that there are two main ways to launch PX4 and Gazebo. One is with make and the other is with roslaunch. I play around with ROS, so I'm going to only touch on that.

Let's do a simple example: I'm going to show you how to make a copy of the iris model and launch it, explaining it a bit on the way. I'll call this new vehicle iris-copy. Hopefully this will show you what parts are important, where they live, and what changes are required.

Prerequisites:

1. Clone PX4 Firmware

2. Enter PX4 Firmware directory

3. Build the firmware
   `make posix_sitl_default`

4. Build sitl_gazebo, and do not launch gazebo yet
   `make posix_sitl_default sitl_gazebo`

5. Setup your environment. For example, this is in my `~/.bashrc`:
# PX4
export PX4_SRC_DIR=~/px4/Firmware
source ${PX4_SRC_DIR}/Tools/setup_gazebo.bash ${PX4_SRC_DIR} ${PX4_SRC_DIR}/build/posix_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:${PX4_SRC_DIR}:${PX4_SRC_DIR}/Tools/sitl_gazebo

Here we go:

1. Go to the models directory in your PX4 Firmware directory
   `cd ~/Firmware/Tools/sitl_gazebo/models`

2. Copy the model directory, and enter it
   `cp -R iris iris-copy`
   `cd iris-copy`

3. Rename the file and some bits inside them
   `mv iris.sdf iris-copy.sdf`
   `sed -i 's/iris/iris-copy/g' model.config`
   `sed -i 's/name='"'"'iris'"'"'/name='"'"'iris-copy'"'"'/g' iris-copy.sdf`

4. Go to the startup (rcS) file directory
   `cd ../../../../ROMFS/px4fmu_common/init.d-posix`

5. Make a copy
   `cp 10016_iris 10017_iris-copy`

6. Enjoy!
   `roslaunch px4 posix_sitl.launch vehicle:=iris-copy`

Hi, I just wondering if I want to use my own custom model, how could I create my model file after cd ../../../../ROMFS/px4fmu_common/init.d-posix

@hamishwillee
Copy link
Collaborator Author

@TSC21 Would be nice to progress this ...
I know you are always busy, so what can we do to make it more of a priority? If you will never have time available, is there someone else you can recommend to help with this?

@imagotechteam
Copy link

imagotechteam commented May 21, 2019

roslaunch px4 posix_sitl.launch vehicle:=iris-copy

What would that be to launch a custom vehicle with make ?

@hamishwillee
Copy link
Collaborator Author

@imagotechteam YOu post above is a technical support query, and not particularly relevant to this post. Please post on the discussion boards.

@tuloski
Copy link

tuloski commented May 27, 2019

Can also someone explain how the .sdf are generated from the .xacro? For example for the iris model it seems that the .sdf are automagically generated from .xacro (inside the /models/rotor_description/urdf) which is much more readable.

@jannsta1
Copy link

Did you read the gazebo help pages about URDF? e.g. http://gazebosim.org/tutorials/?tut=ros_urdf. I think it's explained quite comprehensively there. I haven't used them a lot but the way I think of it is that the URDF gets converted into the .sdf, xacros are a feature of URDF. e.g. https://answers.ros.org/question/202162/urdf-or-xacro/

@tuloski
Copy link

tuloski commented May 27, 2019

Yeah, but I'd like to understand which script (I think there is one) in the px4 firmare builds the .sdf from the .xacro and how to add custom .xacro that will build automatically the .sdf for new models.

@RicardoM17
Copy link
Contributor

@tuloski https://github.com/PX4/sitl_gazebo/blob/a0b0eb8df12b11e8f63d3cc766dee97cefa32ab7/scripts/xacro.py

But please if you have further questions move this to discuss. ;) This thread is not the place for it.

@tuloski
Copy link

tuloski commented May 27, 2019

@RicardoM17 I think this is the thread, because in the documentation of how to integrate customized models I'd like to see explained how to use xacro instead of sdf.

Moreover on discuss none ever answer :) .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests