Engee documentation

Software control of Ardupilot

This page shows all the available software control functions of Ardupilot in Engee.

To work with the software control functions of Ardupilot in Engee, follow the instructions given in article. After that, perform:

using Main.EngeeDeviceManager.Devices.ARDUPILOT

Next, you need to create an Ardupilot object that will be used to interact with the autopilot.:

ap = ARDUPILOT.Ardupilot()

The constructor can be called with the handle of an existing connection. Then the object will work with this connection without creating a new one.:

ap = ARDUPILOT.Ardupilot(desc)

The descriptor is returned by the function ap.connect(…​).

Methods Ardupilot

ap.close()

Closes the UDP bridge with ArduPilot SITL and frees the UDP socket.

Arguments

None (the method is called from the ArduPilot object).

Examples

ap = ARDUPILOT.Ardupilot()
desc = ap.connect()
# ... data exchange ...
ap.close()
ap.connect()
ap.connect(host, port_out, port_in, visualize_port, visual_ok)

Opens a UDP bridge with ArduPilot SITL: creates a UDP socket on port port_in, begins listening for PWM frames from the autopilot, and returns a connection descriptor. In response to PWM frames, the bridge sends sensor frames to the autopilot, as provided by the ap.send(...) function.

Arguments

  • host::String = "127.0.0.1": the address at which the UDP socket is opened.

  • port_out::Int64 = 9002: reserved for compatibility; not used.

  • port_in::Int64 = 9002: the UDP port on which the bridge listens for ArduPilot PWM frames.

  • visualize_port::Int64 = 14600: the UDP port for sending visualisation data (aircraft position).

  • visual_ok::Bool = false: when true is set, the bridge additionally sends the aircraft’s position to visualize_port.

Return value

desc::Int64: connection descriptor. Pass it to the ARDUPILOT.Ardupilot(desc) constructor to use the same connection from another object.

Examples

using Main.EngeeDeviceManager.Devices.ARDUPILOT

ap = ARDUPILOT.Ardupilot()
desc = ap.connect("127.0.0.1", 9002, 9002, 5040, true)
println("Дескриптор соединения: ", desc)
ap.receive()
ap.receive(timeout)
ap.receive(timeout, async_rpc)

Returns PWM signals from the latest ArduPilot frame. The frame contains 16 or 32 PWM values; the function returns them all.

Arguments

  • timeout::Float64 = 0.01: maximum time to wait for a frame, in seconds.

  • async_rpc::Bool = false: when set to true , the function does not wait for the request to complete and immediately returns control.

Return value

Vector{Float64}: PWM values for the frame (in microseconds of pulse duration). If the frame has not arrived within timeout , an empty vector is returned.

Examples

servos = ap.receive(0.05)
if !isempty(servos)
    println("ШИМ: ", servos[1:4])
end
ap.send(timestamp, gyro, accel, position, attitude, velocity)
ap.send(timestamp, gyro, accel, position, attitude, velocity, async_rpc)

Sends the next frame of sensor data to the autopilot. The frame is sent in response to an ArduPilot PWM frame (lockstep): the autopilot will only send the next PWM frame after receiving this sensor frame.

Arguments

  • timestamp::Float64: model time in seconds.

  • gyro::Vector{Float64}: angular velocities, rad/s (exactly 3 components).

  • accel::Vector{Float64}: accelerations in the bound coordinate system, m/s² (exactly 3 components).

  • position::Vector{Float64}: position in the NED coordinate system, m (exactly 3 components).

  • attitude::Vector{Float64}: orientation angles, rad (exactly 3 components).

  • velocity::Vector{Float64}: velocity in the NED coordinate system, m/s (exactly 3 components).

  • async_rpc::Bool = false: when true , the function does not wait for the request to complete and immediately returns control.

Examples

ap.send(
    0.05,                # timestamp, s
    [0.0, 0.0, 0.1],     # gyro, rad/s
    [0.0, 0.0, -9.81],   # accel, m/s² (fixed coordinate system)
    [0.0, 0.0, 10.0],    # position, m (NED)
    [0.0, 0.1, 0.0],     # attitude, rad
    [0.0, 0.0, 0.0],     # velocity, m/s (NED)
)