-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
Multiple instances of PX4 SITL #6408
Comments
Also, if this feature is not currently implemented, I can probably add it myself if you could point me to the correct source file for that node. The directory structure is different than the typical ROS packages that I am used to and I'm having a hard time trying to figure out which source files generate the ROS nodes. Thanks |
I'll share my progress in case anyone is trying to do something similar. The files in this folder are the startup scripts for the simulated px4 (e.g., this file is the default script), in which the port parameters for mavlink are set. Starting up multiple instances of the px4 in there own ROS namespaces works fine as far as ROS and Gazebo are concerned, however the quads in the simulation fly erratically. I think this is because the uORB topics are not grouped into their own namespace, and so the two px4's are interfering with each other. If only 1 px4 is launched (even within a namespace), everything works perfectly. Looking through the uORB code, there doesn't seem to be an easy way to push all the topic names down into a namespace like can be done in ROS launch files. Ideally, one would be able to pass a namespace parameter to the If anyone more familiar with uORB has any suggestions, it would be greatly appreciated. |
Hi @anuppari uORB is used for intra-process communication on Linux. What you need is to start multiple |
I think I'm doing something equivalent to the script, but through roslaunch. Here is the main launch file I call ( <launch>
<!-- Start Gazebo world -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="headless" value="false"/>
<arg name="gui" value="true"/>
<arg name="world_name" value="$(find mavlink_sitl_gazebo)/worlds/empty.world" />
<arg name="debug" value="false" />
<arg name="verbose" value="false" />
<arg name="paused" value="false" />
</include>
<!-- Start first instance of px4 and gazebo model-->
<group ns="uas1">
<include file="$(find asap_gazebo_sim)/launch/quad.launch">
<arg name="name" value="uas1" />
<arg name="rcS" value="$(find asap_gazebo_sim)/px4-configs/lpe/iris1"/>
<arg name="fcu_url" value="udp://:14540@localhost:14557"/>
<arg name="x" value="0"/>
<arg name="y" value="0"/>
<arg name="z" value="0"/>
</include>
</group>
<!-- Start second instance of px4 and gazebo model-->
<group ns="uas2">
<include file="$(find asap_gazebo_sim)/launch/quad.launch">
<arg name="name" value="uas2" />
<arg name="rcS" value="$(find asap_gazebo_sim)/px4-configs/lpe/iris2"/>
<arg name="fcu_url" value="udp://:14541@localhost:14559"/>
<arg name="x" value="1"/>
<arg name="y" value="0"/>
<arg name="z" value="0"/>
</include>
</group>
</launch> The <launch>
<!-- Parameters -->
<arg name="name" default="uas" />
<arg name="x" default="0"/>
<arg name="y" default="0"/>
<arg name="z" default="0"/>
<arg name="est" default="lpe"/>
<arg name="vehicle" default="iris"/>
<arg name="sdf" default="$(find mavlink_sitl_gazebo)/models/$(arg vehicle)/$(arg vehicle).sdf"/>
<arg name="rcS" default="$(find px4)/posix-configs/SITL/init/$(arg est)/$(arg vehicle)"/>
<arg name="fcu_url" default="udp://:14540@localhost:14557"/>
<!-- px4 instance -->
<node name="sitl" pkg="px4" type="px4" output="screen" args="$(find px4) $(arg rcS)" />
<!-- load model in gazebo -->
<node name="$(anon vehicle_spawn)" output="screen" pkg="gazebo_ros" type="spawn_model"
args="-sdf -file $(arg sdf) -model $(arg name) -x $(arg x) -y $(arg y) -z $(arg z) -R 0 -P 0 -Y 0"/>
<!-- mavros instance for ROS communication -->
<include file="$(find mavros)/launch/px4.launch">
<arg name="fcu_url" value="$(arg fcu_url)" />
</include>
</launch> The
iris2:
So from my understanding, I am starting multiple instances of px4, each with their own mavlink ports. Though I did notice that when I run I also noticed that when launching 2 instances, I get a |
The erratic behavior leads me to believe there is some cross-talk somewhere. The ROS topics are all isolated, so I think it might be in the uORB topics. This tutorial seems to suggest that there is only one global topic for each msg type, unless you include modifications presented here. However, most of the msg definitions do not include a From my understanding, uORB uses a file abstraction (e.g., this page explains that the subscriber handles are file descriptors), so is it possible that the multiple instances of uORB are reading/writing to the same "files"? |
Gazebo plugin is communicating with PX4 |
Thanks @nicolaerosia, that fixed the |
You're welcome! |
Thanks, that fixed it. For anyone else interested, the additional changes I made were adding the port argument (i.e., By the way, the base xacro file used to generate the iris sdf has a small typo. The arguments defined on L7-L8 are not used in the macro on L35-L36. |
Would you mind sending a pull request? |
No problem, see PX4/PX4-SITL_gazebo-classic#83 |
what port number do I have to use in |
Should anyone find it useful, I've written a gazebo plugin (https://github.com/dennisss/tansa/blob/master/src/gazebo/swarm_plugin.cpp) for hot-loading models into an open gazebo world at arbitrary positions and starting the SITL instances. The instance starting is based on the previously mentioned sitl_multiple_run.sh modified to work with the latest master (https://github.com/dennisss/tansa/blob/master/scripts/start_sim.sh). |
@Doolly, as mentioned here, port 14560 is already used for communications from gazebo to the simulator/px4, so you need to use different ports for communication between px4 and ROS. Your two lines are correct in the sense that it should be: arg name="fcu_url" value="udp://:{port1}@localhost:{port2}" |
Can anyone explain why there are two mavlink streams, i.e., in iris there is:
What is the first stream on port 14556 for? Currently each instance requires keeping track of, and editing files, with 4 different ports, I'm hoping to streamline this a bit if possible. |
@anuppari There is one port for connection between Gazebo and PX4 module, and the other is for connection between PX4 module with ROS. |
@anuppari IMO The first port is for Ground Control Station communication, while the second one, "onboard" is for the companion computer, which in your case is ROS |
Hello, have your problem be solved ? i would like to consult you how to run multiple UAV in gazebo, look forward to your reply, best wishes! |
@anuppari Gazebo defaults to mavlink udp port 14560. https://github.com/PX4/sitl_gazebo/blob/a8f57664c7bf6f4d8ab7a0c01d65181455151ca0/include/gazebo_mavlink_interface.h#L55 PX4 starts streaming mavlink here (This was also declared in solo.sdf files): https://github.com/PX4/Firmware/blob/master/posix-configs/SITL/init/ekf2/plane#L72 |
@dennisss Can you give instructions on how to run after running sitl_multiple_run.sh please? |
@anuppari @nicolaerosia any idea how can I do the same for the erle copter tutorial. I have managed to spawn multiple erle copters in Gazebo but as there is only one MAVlink that links to them so they fly away erratically. Please help, I am new to this so a step by step solution would be appreciated. |
If anyone wants a turn key solution to this, I implemented a solution to this in my research platform here (https://github.com/dennisss/tansa/tree/master/doc/examples/gazebo_spawn), given a list of positions, an rcS file, and a single sdf file, it will programmatically hot load models into the world. It takes about 10 lines of code to use. This has substantially sped up our development speed. This works by having a gazebo plugin (https://github.com/dennisss/tansa/blob/master/src/gazebo/swarm_plugin.cpp) which modifies the position, port assignments etc. of a single sdf in order to adapt it to many unique instances. It is accompanied by a helper class on the client side (https://github.com/dennisss/tansa/blob/master/src/gazebo/gazebo.cpp#L141) which sends protobuf messages to the plugin to request new drones to be spawned / respawned. PX4 instances are created using a templated rcS file like https://github.com/dennisss/tansa/blob/master/config/models/x340/rcS and a modified version of stitl_multiple.run.sh here https://github.com/dennisss/tansa/blob/master/scripts/start_many_instances.sh . Feel free to adapt to your particular projects. |
@dennisss I tried your solution, following the steps I tried to make build. First I got the erro to update CMake , after resolving that I got error to update BOOST and after removing all my packages and updating boost to 1.55 I got this getting this error:
|
@AliSiddiqui4 assuming you are on Ubuntu, you can try doing |
@dennisss ok that helped but I am getting another error now:
|
@AliSiddiqui4 please see https://github.com/dennisss/tansa/blob/master/config/docker/dev/Dockerfile for a full list of all the commands we use to install our system (Ignoring the RUN at the start of each line). There's a lot more in there than you probably need. I think you just need to do |
@dennisss I am using ubuntu 14.04 maybe that's the problem. I can upgrade it but can you please elaborate on what this Swarm solution is? Can I easily simulate Swarm of Quads in Gazebo using it and write code for pattern formation and obstacle avoidance for it? |
@AliSiddiqui4 I don't see why it wouldn't work on 14.04, if you use the same list of dependencies I don't think that much has changed between that and 16.04. The spawning of models in gazebo is fairly easy with that example code. We have our own not yet well documented drivers for formation flight, although just about any other tool would work once they are spawned into gazebo. Similarly to sitl_multiple_run.sh in the PX4/Firmware repo, it will start every firmware instance for a unique mavlink instance sending packets to udp port 14550 + i*10, so just about any tool such as mavros or whatever that supports mavlink can be configured to listen on that port can be used. |
@dennisss Could you advise on how to add support for planes? |
@paan2097 the only thing vehicle type specific is the rcS and sdf files. In my code I specify them in main.cpp rcS file: sdf file: these are a little bit more complicated, but sitl_gazebo has many examples. see the Tools/sitl_gazebo/models/plane/plane.sdf file with respect to the Firmware directory for one example. If there is one that works well for you in a single instance for you, then these should be easy to find, although I haven't set up the tooling for finding them automatically yet. |
@dennisss Thanks! Adding the sdf and rcS-like plane files in the same locations along with altering the mavlink lines in rcS and adding two mavlink_udp_port lines from the sdf got it to work. Thanks! |
@dennisss I have built everything but stll unable to run the simulation:
|
@AliSiddiqui4 not sure why the make target isn't being recognized. You can try bypassing it and just running Although it looks like the |
@dennisss Thanks for providing this script. I have successfully instanced two planes. I'm not trying to connect to each plane to control it with Dronekit scripts. However, I do not know what the IP and port numbers would be for the connection strings to each plane. I've tried local loopback and my localhost addresses with both 14550 and 14560 but I get a timeout on dronekit. I also ran sockstat on each of the processes. Only the 14550 process occupies a UDP port according to sockstat. How can I find the connection IP/port addresses so that I may connect and control the planes via Dronekit? |
@mago3421 the ports are configured for an instance right here (https://github.com/dennisss/tansa/blob/master/scripts/start_instance.sh#L25) to be 14550 and 14560, and that's what has been working for me on localhost. Each instance spits out error logs into |
@dennisss So I copied over the plane sdf and rcS file and transfered the MAINPORT lines. but the two instances stop on Please start the flight simulator to proceed, even though I'm running make runSim and ./spawner and see the two planes in gazebo. I noticed there is plugins in the x340_base.xacro file, do you know what other files i need to incorporate? |
@dennisss Both error logs are empty. Do you use any particular options in Dronekit's connect call? |
@paan2097 The important part in the sdf file is that the mavlink plugin exists. If it works with stock px4 single drone simulation, then it should work here @mago3421 I've never used Dronekit, but it should work with 127.0.0.1:14550 and 127.0.0.1:14560 etc. Some other notes to try for both of you: In the rcS file, the line that starts the simulator should be templated like this: The line that starts the mavlink interface should look like this: |
@dennisss AH I switched over all the mavlink lines in the rcS file but didn't have the simulator start -s -u SIMPORT line copied over, thanks. I'll be testing the multi plane SITL for awhile and will let you know of any issues. Thanks a bunch! |
@dennisss Hey so I finally was able to get the planes to takeoff but they immediately crash, the err.log file is empty but here is an out.log file, the only difference between the two vehicles is that one had a positive tone_alarm. I'm running make runSim from the /tansa level and then ./spawner from the tansa/doc/../gazebo_spawn level. On my dronekit script im receiving this message and it seems to pop up after takeoff:
Here is the out.log file: data path: /home/pat/tansa/scripts/../lib/Firmware | ___ \ \ \ / / / | px4 starting. ERROR [param] importing from 'rootfs/eeprom/parameters' failed (-1) Exiting... |
@dennisss, what IP address and UDP port number can I use to connect to each instance using QGroundControl? I would like to monitor the planes and see why they are crashing. |
Sorry, I meant this PR
#7235
…On May 15, 2017 10:48 PM, "mago3421" ***@***.***> wrote:
Hi @mzahana <https://github.com/mzahana>, I don't see anything on #7225
<#7225>. Did you want me to post
there?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6408 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIZT6897xj9C5dPVeSprBetShg-B28lGks5r6LoHgaJpZM4Lp2Qb>
.
|
Hi @anuppari
I have seen these lines : |
Hey, this issue has been closed because the label (This is an automated comment from GitMate.io.) |
I'm trying to run a simulation with multiple quadrotors in Gazebo with ROS. I think I can just spawn multiple gazebo models and corresponding px4 nodes in separate namespaces, however they will all publish MAVLink messages to the same port number, and each instance of mavros won't be able to distinguish messages from the individual px4 nodes.
Does the px4 node (i.e., the one launched here) take a port number parameter, or is there anywhere else I can specify port numbers?
Thanks!
The text was updated successfully, but these errors were encountered: