How to connect to a local gazebo on a remote machine and spawn the model

asked 2019-08-21 23:17:59 -0500

LSGman gravatar image

Hello, I'm working on spawning a px4 model on multiple machines in a single gazebo simulator. Using two computers (both Ubuntu 16.04), I have run a gazebo simulator and two px4 drones on one computer, and the px4 drone on the same gazebo simulation on another computer.

It was successful to sitl with the Gazebo simulator and two px4 drones on the first computer(local machine), but spawning the px4 drone on another computer(remote machine) failed.

Below is part of my .bashrc.

local machine

#set ROS Network
export ROS_MASTER_URI=http://192.168.0.6:11311
export ROS_HOSTNAME=192.168.0.6

export GAZEBO_MASTER_URI=http://192.168.0.6:11345

remote machine

#set ROS Network
export ROS_MASTER_URI=http://192.168.0.6:11311
export ROS_HOSTNAME=192.168.0.2

export GAZEBO_MASTER_URI=http://192.168.0.6:11345

And the launch file is run on each computer.

local machine

<?xml version="1.0"?>
<launch>
    <!-- MAVROS posix SITL environment launch script -->
    <!-- launches Gazebo environment and 2x: MAVROS, PX4 SITL, and spawns vehicle -->
    <!-- vehicle model and world -->
    <arg name="est" default="ekf2"/>
    <arg name="vehicle" default="iris"/>
    <arg name="uav_number" default="uav0"/>
    <arg name="world" default="$(find mavlink_sitl_gazebo)/worlds/empty.world"/>
    <!-- gazebo configs -->
    <arg name="gui" default="true"/>
    <arg name="debug" default="false"/>
    <arg name="verbose" default="false"/>
    <arg name="paused" default="false"/>
    <!-- Gazebo sim -->
    <include file="$(find gazebo_ros)/launch/empty_world.launch">
        <arg name="gui" value="$(arg gui)"/>
        <arg name="world_name" value="$(arg world)"/>
        <arg name="debug" value="$(arg debug)"/>
        <arg name="verbose" value="$(arg verbose)"/>
        <arg name="paused" value="$(arg paused)"/>
    </include>
    <!-- UAV0 -->
    <group ns="uav0">
        <!-- MAVROS and vehicle configs -->
        <arg name="ID" value="0"/>
        <arg name="fcu_url" default="udp://:14540@192.168.0.6:14550"/>
        <arg name="gcs_url" value=""/>
        <!-- PX4 SITL and vehicle spawn -->
       <include file="$(find px4)/launch/single_vehicle_spawn.launch">
           <arg name="x" value="0"/>
           <arg name="y" value="0"/>
           <arg name="z" value="1"/>
           <arg name="R" value="0"/>
           <arg name="P" value="0"/>
           <arg name="Y" value="0"/>
           <arg name="vehicle" value="$(arg vehicle)"/>
           <arg name="mavlink_udp_port" value="14560"/>
           <arg name="mavlink_tcp_port" value="4560"/>
           <arg name="ID" value="$(arg ID)"/>
       </include>
       <!-- MAVROS -->
       <include file="$(find mavros)/launch/px4custom.launch">
           <arg name="uav_number" value="uav0"/>
           <arg name="fcu_url" value="$(arg fcu_url)"/>
           <arg name="gcs_url" value="$(arg gcs_url)"/>
           <arg name="tgt_system" value="$(eval 1 + arg('ID'))"/>
           <arg name="tgt_component" value="1"/>
       </include>
   </group>
   <!-- UAV1 -->
   <group ns="uav1">
       <!-- MAVROS and vehicle configs -->
       <arg name="ID" value="1"/>
       <arg name="fcu_url" default="udp://:14541@192.168.0.6:14551"/>
       <arg name="gcs_url" value=""/>
       <!-- PX4 SITL and vehicle spawn -->
       <include file="$(find ...
(more)
edit retag flag offensive close merge delete

Comments

I found the answer. In single_vehicle_spawn.launch of the launch file running on each machine, the mavlink_addr address name can be directly parameterized to the IP address of the computer.(basic inaddr_any) Thank you.

LSGman gravatar image LSGman  ( 2019-08-22 23:49:17 -0500 )edit