Why does JSON replace the vehicle frame definition in SITL builds?

I am trying to build ArduCopter for SITL using the JSON interface so I can use my own physics simulation. I don’t want to have to include mission planner as the simulation is also set up to send simple commands like ARM and AUTO. But when I spin up the sitl build it starts with no frame or class defined, meaning I need to manually set the frame parameter and reboot.

Am I missing something here? I’m basically doing this:

cd ardupilot/ArduCopter
../Tools/autotest/sim_vehicle.py -f JSON:127.0.0.1

I would ideally have an -f quad argument in there as well but that causes the build to ignore the JSON interface

Hello,

Just add your default param file to your sim_vehicle.py cmdline.

If you look at what is happening when using -f quad starting output ( or directly the code), you can see that sim_vehicle.py is adding quad default parameters. So you need to do the same for you vehicle as json is not a vehcile type.

A funnier change would be to add your own vehicle type to sim_vehicle.py logic but that is a bit more complex !

1 Like

Thank you for the suggestion!

It looks like sim_vehicle.py is calling param_parse.py which then uses the Parameters.cpp script to generate the default parameters for the frame defined with the -f argument. The script isn’t reading the params directly from a text file like the --add-param-file argument would. So to add a default param file for the json interface I would first need to generate a default param text file for each frame I want to test.

I don’t understand why the json interface overrides the vehicle type in the first place, can’t you generate the default parameters for a prescribed vehicle then make the json changes to those rather than treating json as a completely separate vehicle type?

You can use something like
sim_sim_vehicle.py -v ArduCopter -f octaquad --model JSON --map --console
To auto load the default octaquad parameters and still use the JSON model.

The issue with the JSON model is that we don’t know what is on the other end so we cannot do default parameters simply.
Some simulator got some : you can look on how it is done on Gazebo for example : ardupilot/Tools/autotest/pysim/vehicleinfo.py at master · ArduPilot/ardupilot · GitHub
So just adding your custom vehicle rule here will make it as valid frame into sim_vehicle.py and loads the params you want.

1 Like

Ah this is perfect thank you so much!

I understand you not knowing what’s on the other end, but as a simulation developer I know what I’m simulating and only need JSON to act as an interface between the firmware and the simulation. I needed to be able to define the frame when I spin up sim_vehicle as you showed in your second example. It’s working great for me now.

I’ve submitted a pull request on the JSON read me to swap the -f json for --model json to save future confusion, I hope that’s okay!

1 Like