Combine two working models for gz sim

I have two models that run in gazebo. The first doesn’t using ardupilot and is a three wheel robot that can be controlled with keys. It’s the moving robot tutorial.

The second model is iris runway that is part of ardupilot / gazebo.

I’m using gazebo garden.

I would like have the iris track the moving robot at a fixed offset (range, elevation, azimuth).

My current attempt is

<?xml version="1.0" ?> model_iris://iris_runway.sdf 0.3 0.5 0.9 0 0 0

This file is in the same folder as the two models, iris_runway.sdf and moving_robot.sdf.

Current error is

[Err] [Server.cc:159] Error Code 8: [/sdf/world[@name=“quad_rover_world”]/model[@name=“quad_rover”]/include[0]/uri:/home/john/ardupilot_gazebo/worlds/quad_rover_1.sdf:L9]: Msg: Failed to find top level / / for

Hello @jvorwald, it should be straightforward to add another model to the iris_runway.sdf world:

  • start with iris_runway.sdf.
  • copy the elements defining the moving robot in the tutorial to iris_runway.sdf.
  • adjust the pose so it doesn’t conflict with the iris.

The files iris_runway.sdf and moving_robot.sdf are world files, not models, so you won’t be able to include models defined in these files in another world. For that you’d need to create a separate model (see the iris_with_standoffs as an example) and then ensure that model is included in the GZ_SIM_RESOURCE_PATH.

Thanks, @rhys. Let me provide more details. I’m puzzled as to where the error is, or how to debug.

The framework is the truck-quadplane-landing.sh`example. Objective is 2 Iris quads each with 3 axis fpv with two cameras, flying fixed azimuth/elevation/range position relative to moving truck.

Status, iris shows up on the truck, but mavproxy only shows two vehicles, rover/rover instead of three, rover/rover/quad.

Error is most likely in the iris_with_autopilot.sdf.erb file. Here are the steps to create the erb file.

 1. Change to model directory
       mkdir ~/simulation/SITL_Models/Gazebo/models/iris_with_ardupilot
       cd ~/simulation/SITL_Models/Gazebo/models/iris_with_ardupilot
       cp ~/ardupilot_gazebo/models/iris_with_ardupilot/*.*

 2. Backup model.sdf
    (a) Copy files
       cp model.sdf model.sdf.bac

    (b) Note the xml and sdf version numbers in the model.sdf file
       <?xml version='1.0'?>
       <sdf version="1.9">

 3. Create empty file model.sdf.erb.
       touch model.sdf.erb
       code model.sdf.erb

    (a) Add these lines at the top.  Use the xml and sdf versions from above
       <%
         # defaults
         if !defined?(model_name) then model_name = 'iris_with_ardupilot' end
         if !defined?(model_pose) then model_pose = '0 0 0 0 0 0' end
         if !defined?(fdm_addr) then fdm_addr = '127.0.0.1' end
         if !defined?(fdm_port_in) then fdm_port_in = 9002 end
       
         # sdf header and footer
         header=''
         footer=''
         if defined?(sdf)
           header='<?xml version="1.0" ?>
       <!--
       DO NOT EDIT. This file is generated from an ERB template.
       
         erb -T 1 sdf=true model.sdf.erb > model.sdf
       
       -->
       <sdf version="1.9">'
           footer='</sdf>'
         end
       %>
       <%= header %>

 4. Add to the bottom of model.sdf.erb.all the lines from model.sdf

 5. From filemodel.sdf.erb remove the two lines added, 
       <?xml version="1.0"?>
       <sdf version="1.9">

 6. Find “model name”
    (a) Fix the model name
         i. change <model name="iris_with_ardupilot">
         ii. to <model name="<%= model_name %>">
 7. In the model level, before including “<uri>model://iris_with_standoffs</uri>”
    (a) Add the pose
         i. <pose><%= model_pose %></pose>

 8. Go down to ArduPilotPlugin section
    (a) Replace
          <fdm_addr>127.0.0.1</fdm_addr>
             <fdm_port_in>9002</fdm_port_in>

    (b) with
           <fdm_addr><%= fdm_addr %></fdm_addr>
           <fdm_port_in><%= fdm_port_in %></fdm_port_in>

 9. At the bottom of model.sdf.erb
    (a) Replaced
       </sdf>

    (b) with
       <%= footer %>

To run and see the error

 I. Terminal 1: Create SITL simulation files
   cd ~/ardupilot
   rm -rf sitl
   # mv sitl sitl_iris_1
   ./SITL_Models/Gazebo/launch/truck-quad_iris-landing.sh

 II. Terminal 2: Run world simulation
   cd ~/ardupilot/sitl/worlds
   gz sim -v 4 -r truck_quad_iris_landing.sdf

 III. Optional Terminal 3: Start QGroundControl (not done this time)
   cd ~/Desktop/
   QGroundControl.AppImage 

 IV.  Terminal 4 start mavproxy
   cd ~/ardupilot
   ./SITL_Models/Gazebo/launch/mavproxy-multi-vehicle.sh 3 

 V. There seems to be an error at this point.  Mavproxy console indicates a loop
   height 5

pre-arm good
height 589
pre-arm fail

You can get the errors to stop generating by typing vehicle 3 in mavproxy terminal.
Also, if you click on vehicle in mavproxy console, only shows two vehicles instead of three.

Attached zip file should contain all needed files. Generated with command executed in home directory

$ zip ./err_iris_truck.zip ./ardupilot/SITL_Models/Gazebo/launch/truck-quad_iris-landing.sh ./simulation/SITL_Models/Gazebo/worlds/truck_quad_iris_landing.sdf.erb ./simulation/SITL_Models/Gazebo/models/iris_with_ardupilot/.
adding: ardupilot/SITL_Models/Gazebo/launch/truck-quad_iris-landing.sh (deflated 65%)
adding: simulation/SITL_Models/Gazebo/worlds/truck_quad_iris_landing.sdf.erb (deflated 64%)
adding: simulation/SITL_Models/Gazebo/models/iris_with_ardupilot/model.config (deflated 56%)
adding: simulation/SITL_Models/Gazebo/models/iris_with_ardupilot/model.sdf (deflated 92%)
adding: simulation/SITL_Models/Gazebo/models/iris_with_ardupilot/model.sdf.bac (deflated 92%)
adding: simulation/SITL_Models/Gazebo/models/iris_with_ardupilot/model.sdf.erb (deflated 92%)
err_iris_truck.zip (9.7 KB)

Here is a copy of output from mavproxy console

online system 1
Mode INITIALISING
Init ArduRover V4.5.0-dev (4a181ede)
Free RAM: 131072
Booting 0/0
Firmware change: erasing EEPROM...
done.

load_all took 21706999us

0 0 0 AP_Logger_File: buffer size=204800
Init ArduCopter V4.5.0-dev (4a181ede)

Free RAM: 13107

Booting 0/0
Firmware change: erasing EEPROM...
done.

load_all took 21706999us

0 0 0 AP_Logger_File: buffer size=204800
AP: Barometer 1 calibration complete
AP: Barometer 2 calibration complete
AP: Beginning INS calibration. Do not move vehicle
AP: Barometer 1 calibration complete
AP: Barometer 2 calibration complete
AP: ArduPilot Ready
AP: AHRS: DCM active
Lua: State memory usage: 4824 + 20458
AP: Airspeed 1 calibration started
AP: ArduPilot Ready
AP: car_steer_mixer.lua is running
AP: AHRS: DCM active
fence present

AP: ArduRover V4.5.0-dev (4a181ede)
AP: 379f5722ae6b4310a9ad0bdc5e567e75
AP: Airspeed 1 calibrated
AP: EKF3 IMU0 initialised
AP: EKF3 IMU1 initialised
AP: AHRS: EKF3 active
AP: EKF3 IMU0 initialised
AP: EKF3 IMU1 initialised

Mode STABILIZE

AP: EKF3 IMU1 tilt alignment complete
AP: EKF3 IMU0 tilt alignment complete
AP: EKF3 IMU0 MAG0 initial yaw alignment complete
AP: EKF3 IMU1 MAG0 initial yaw alignment complete
AP: EKF3 IMU0 tilt alignment complete
AP: EKF3 IMU1 tilt alignment complete
AP: EKF3 IMU0 MAG0 initial yaw alignment complete
AP: EKF3 IMU1 MAG0 initial yaw alignment complete

Mode MANUAL

AP: GPS 1: detected as u-blox at 230400 baud
Mode STABILIZE

AP: PreArm: Motors: Check frame class and type
AP: PreArm: Accels inconsistent
Mode MANUAL
Mode STABILIZE
Mode MANUAL
Mode STABILIZE
Mode MANUAL

AP: EKF3 IMU1 origin set
AP: Field Elevation Set: 584m
AP: EKF3 IMU0 origin set
AP: EKF3 IMU1 origin set
AP: Field Elevation Set: 585m

Mode STABILIZE
Mode MANUAL

pre-arm good
pre-arm fail
pre-arm good

Mode STABILIZE

pre-arm fail
pre-arm good
pre-arm fail

Mode MANUAL

pre-arm good
pre-arm fail
pre-arm good

AP: PreArm: Motors: Check frame class and type

pre-arm fail
pre-arm good
pre-arm fail

pre-arm good
(I ENTERED VEHICLE 3 AT SOME POINT)

AP: EKF3 IMU0 is using GPS
AP: EKF3 IMU1 is using GPS

Mode STABILIZE

pre-arm fail
pre-arm good
pre-arm fail
pre-arm good

AP: EKF3 IMU0 is using GPS
AP: EKF3 IMU1 is using GPS
AP: AHRS: EKF3 active

pre-arm fail
height 589
pre-arm good
height 5
pre-arm fail
height 589
pre-arm good
height 5

pre-arm fail

height 589

The following warning may be important.

PreArm: Motors: Check frame class and type

Hi John,

Just so I can get a baseline, did you manage to run the truck-quadplane-landing.sh example as is, or is that not working for you either. It’s been a while since I’ve reviewed this, but have just checked the script and it’s running with the latest plugins etc (I’m now using Gazebo Harmonic, but that should not be a factor in whether the example works or not).

I’ll try to replicate your proposed example next.

Hi Rhys,
I ran the truck-quadplane-runway.sh example. Then I compared model.sdf file to model.sdf.erb to identify the process needed to create .erb from .sdf. Then I applied the process to the iris quadcopter. Also tried to switch from plane to copter. One thing I didn’t do is create a config.param file for iris.
Rhys, the goal is to model two cameras mounted on a gremsy t3 v3 gimbal, on a quad copter.
I used gazebo garden.
My guess is either somewhere I’m still using plane instead copter or I need the config.param file for iris to specify the frame class and type.

John

Hi John,

Ok - that’s good as it means the system’s working (just saw the discord post as well).

I’ll see if I can get the example you want up and running and maybe add a PR with the extra scripts needed. So it’s two iris quads with gimbal on the truck trailer. I think the landing script is quadplane only - but that’s not the immediate problem, we’ll start with getting all the vehicles present and visible in mavproxy and take it from there.

Fantastic. But it’s two cameras on one vehicle, 3 axis gimbal. The cameras have lens with different focal lengths. But, I will fly two UAV at once to reduce clock time required. So you can implement two iris on the back of the truck. Later this has to be implemented on a harbour tug, instead of a truck at an airport, in rough seas.

Hi John,

Ok - got it working (mostly). Need to update the launch script to set the copter defaults. Sub in this for the last section.

#--------------------------------------------------------------------
# Copter 1

COPTER1_NAME=iris

mkdir -p sitl/$COPTER1_NAME

COPTER_DEFAULTS="$ROOTDIR/Tools/autotest/default_params/gazebo-iris.parm"

# additional parameter file for the iris
cat <<EOF > sitl/$COPTER1_NAME/follower.param
SYSID_THISMAV 3
FOLL_ENABLE 1
FOLL_OFS_X -5
FOLL_OFS_Y 0
FOLL_OFS_Z 10
FOLL_OFS_TYPE 1
FOLL_SYSID 2
FOLL_DIST_MAX 1000
FOLL_YAW_BEHAVE 2
FOLL_ALT_TYPE 1
EOF

(cd sitl/$COPTER1_NAME && $COPTER -S --model JSON --home=$HOMELAT,$HOMELONG,$HOMEALT,0 --speedup 1 --instance 2 --defaults $COPTER_DEFAULTS,follower.param) &

wait

There’s an issue with the orientation - some of the models (including the truck) had the wrong mapping from Gazebo ENU to ArduPilot NED. If all the models are consistent you don’t notice until using a compass or navsat sensor. It looks like the iris and runway (which have been fixed in ardupilot_gazebo) are inconsistent with the truck. The model pose needs a 90 deg z rotation, and the transform pose in the ArduPilotPlugin needs an extra z-rotation by 90 deg as well. This is why the copter is zooming off to the east in the map when the truck goes north. In Gazebo the iris is on the trailer.

Update:

Oh - that will be easy to set up. We can add another camera sensor to the gimbal on the iris with gimbal model.

That we can do also. We have a nice wave simulation - if you have a CAD model for the boat I can set something up. I put together a model for a large research vessel for tridge when investigating the quadplane, the physics didn’t scale quite right for that vessel (70+m), but something intermediate may behave better.

Wow, impressive response! Thank you.

1 Like

I have ship motion data, can that be used in the simulation. I would just scale the existing tugboat model. Put the tugboat in waves and let me control the amplitude of the waves. And let the tugboat be driven by data in a file.

Could do, or we can use the wave simulation I developed where you can specify the wave amplitude via a parameter (and control wave direction relative to the wind). The boat motion is governed by non-linear hydrostatic restoring physics, so it’s fairly realistic. The advantage then is that you can command a mission for the boat and the boat motion takes care of itself.

@rhys Can you add 3 axis Gimbal, t3 v3, and two cameras, mounted beneath the iris

Updated in the branch given above:

  • Iris with 3-axis servo gimbal with 2 RGB cameras (different HFOV)

The following params enable the gimbal with direct RC control

MNT1_TYPE        1.000000 0.000000 # Servo (DEFAULT: None)
SERVO5_MIN       1000.000000 1100.000000
SERVO5_MAX       2000.000000 1900.000000
SERVO5_FUNCTION  8.000000 0.000000 # Mount1Roll (DEFAULT: Disabled)
SERVO6_MIN       1000.000000 1100.000000
SERVO6_MAX       2000.000000 1900.000000
SERVO6_FUNCTION  7.000000 0.000000 # Mount1Pitch (DEFAULT: Disabled)
SERVO7_MIN       1000.000000 1100.000000
SERVO7_MAX       2000.000000 1900.000000
SERVO7_FUNCTION  6.000000 0.000000 # Mount1Yaw (DEFAULT: Disabled)
RC6_OPTION       212.000000 0.000000 # Mount1 Roll (DEFAULT: Do Nothing)
RC7_OPTION       213.000000 0.000000 # Mount1 Pitch (DEFAULT: Do Nothing)
RC8_OPTION       214.000000 39.000000 # Mount1 Yaw (DEFAULT: PrecLoiter Enable)

Config details:

Update

You may also be interested in: Add camera zoom plugin by srmainwaring · Pull Request #57 · ArduPilot/ardupilot_gazebo · GitHub which just merged and provides a zoom capability to the simulated camera.

@rhys Now I can’t run simulation. The block

    <include>
      <uri>model://gimbal_small_3d</uri>
      <name>gimbal</name>
      <pose degrees="true">0 -0.01 0.070 90 0 90</pose>    
    </include>

generates error

[Err] [Server.cc:159] Error Code 14: [/sdf/world[@name=“truck_quad_landing”]/model[@name=“quad”]/include[1]/uri:/home/john/ardupilot/sitl/worlds/truck_quad_iris_landing.sdf:L1469]: Msg: Unable to find uri[model://gimbal_small_3d]

path is

/home/john/simulation/SITL_Models/Gazebo/models/gimbal_small_3d

Tried fixing with

export GAZEBO_MODEL_PATH=/home/john/simulation/SITL_Models/Gazebo/models

@rhys Never mind, wrong version of gazebo.

This path command works

export GZ_SIM_RESOURCE_PATH=$GZ_SIM_RESOURCE_PATH:/home/john/simulation/SITL_Models/Gazebo/models

To add models and worlds to the resource path in Gazebo Garden use:

export GZ_SIM_RESOURCE_PATH=$GZ_SIM_RESOURCE_PATH:/home/john/simulation/SITL_Models/Gazebo/models

GAZEBO_MODEL_PATH is for Gazebo 11 and earlier.

Beat me to it!