ardupilot/libraries/SITL/examples/JSON/C++
Rhys Mainwaring 6cb4e6b31d SITL: update simpleRover C++ JSON interface example
- Provide a cmake file for cross platform builds
- Modify the example to respond to throttle commands on RC channel 3 (default for Rover)
- Add more detail to readme

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
2021-09-14 09:54:39 +10:00
..
CMakeLists.txt
SocketExample.cpp
SocketExample.h
libAP_JSON.cpp
libAP_JSON.h
minimal.cpp
readme.md
simpleRover.cpp
simpleRover.h

readme.md

C++

This library links a simulator written in C++ with ArduPilot through a UDP JSON interface. This simplifies adding support for ArduPilot to a simulator. A minimal example is included in minimal.cpp. This can be built-in Linux with the command g++ minimal.cpp -o minimal.o. The minimal example shows how each method in the library is used and can be used to test the library as well. The simpleRover.cpp example is a 1-D model of a rover that shows how a physics model can be integrated with this library.

Connection to SITL is made via a UDP link. The physics backend should listen for incoming messages on port 9002. The sim should then reply to the IP and port the messages were received from. This is handled by libAP_JSON. This removes the need to configure the target IP and port for SITL in the physics backend. ArduPilot SITL will send an output message every 10 seconds allowing the physics backend to auto-detect.

After a connection has been made, the optional values should be set. Then the vehicle state can be sent with SendState. This call includes all of the required values. The servo_out array supports 16 servo outputs from ArduPilot.

Running the simpleRover example

The examples can be built using cmake:

$ mkdir build && cd build
$ cmake ..
$ make

Run the simpleRover physics engine:

$ ./simpleRover

Run SITL with the JSON backend:

sim_vehicle.py -v Rover -f JSON --console --map

The rover responds to throttle commands on RC channel 3:

# arm throttle
MANUAL> arm throttle

# move forwards at max throttle (expected velocity 1 m/s)
MANUAL> rc 3 1900

# move backwards at max throttle (expected velocity -1 m/s)
MANUAL> rc 3 1100

# stop
MANUAL> rc 3 1500