ArduPilot / SITL_Models

Models of aircraft for SITL
70 stars 111 forks source link

Add Ignition model for DAF XF 450 Tractor Unit #61

Closed srmainwaring closed 2 years ago

srmainwaring commented 2 years ago

This PR adds an Ignition model for a DAF XF 450 Tractor.

https://user-images.githubusercontent.com/24916364/149665138-f921ac8d-1082-4822-a28c-d2c07f98ccaa.mov

The vehicle is configured to have car steering (i.e. different wheel angles for inner and outer front wheel on the turn) and differential drive on the rear wheels. This requires a Lua script to control the servo mix for ArduPilot which is supplied in the scripts sub-directory.

Usage

Run Gazebo

ign gazebo -v4 -s -r daf_truck_runway.sdf

Run ArduPilot SITL - using sim_vehicle.py

Copy the script daf_xf_450_tractor_mixer.lua to the SITL scripts directory, then start SITL:

sim_vehicle.py -v Rover -f JSON --add-param-file=$HOME/SITL_Models/Ignition/config/daf_xf_450_tractor.param --console --map

You may need to reboot the autopilot to ensure the additional scripting parameters are loaded.

Run ArduPilot SITL - using launch scripts

A launch script launch/runway-daf_xf_450_tractor.sh is provided as an alternative way to run SITL. It sandboxes the SITL environment and Lua scripts and is the approach used when running multi-vehicle simulations.

From the $ARDUPILOT_HOME run:

$HOME/SITL_Models/Ignition/launch/runway-daf_xf_450_tractor.sh

Start MAVProxy in a separate terminal:

mavproxy.py \
--out 127.0.0.1:14550 \
--out 127.0.0.1:14551 \
--master tcp:127.0.0.1:5760 \
--sitl 127.0.0.1:5501 \
--map \
--console

ERB templates

When running multi-vehicle simulations each vehicle must have it's own control port configured in the ArduPilotPlugin xml.

  <plugin name="ArduPilotPlugin"
      filename="libArduPilotPlugin.so">
    <!-- Port settings -->
    <fdm_addr>127.0.0.1</fdm_addr>
    <fdm_port_in>9002</fdm_port_in>
    ...
   </plugin>

The approach recommended in the Ignition tutorials is to use ERB Templates. The template for this model is models/daf_xf_450_tractor/model.sdf.erb. It should be regarded as the primary source for the model.

To generate the model.sdf pass the template to erb on the command line with the sdf=true parameter:

cd models/daf_xf_450_tractor
erb -T 1 sdf=true model.sdf.erb > model.sdf

The template may also be used (without the sdf parameter) to inject a <model>...</model> element into a world template:

Suppose that the template was located at worlds/trucks_world.sdf.erb

<%
  # load templates for the required models 
  def make_tractor_model(model_name, model_pose, fdm_port_in)
    ERB.new(File.read('../models/daf_xf_450_tractor/model.sdf.erb'))
      .result(binding)
  end

  # make the tractor models
  tractor1_pose = '0 0 1.0 0 0 0'
  tractor1_model = make_tractor_model('tractor1', tractor1_pose, 9002)

  tractor2_pose = '10 0 1.0 0 0 0'
  tractor2_model = make_tractor_model('tractor2', tractor2_pose, 9012)
%>
<?xml version="1.0" ?>
<sdf version="1.7">
  <world name="truck_world">

  <!-- other world XML here... -->

  <!-- Inject the truck models -->
  <%= tractor1_model %>
  <%= tractor2_model %>
</sdf>

To generate the trucks_world.sdf from the template:

cd worlds
erb -T 1 trucks_world.sdf.erb > trucks_world.sdf

Credits