Skip to content

Scripting OSD#32045

Open
andyp1per wants to merge 14 commits intoArduPilot:masterfrom
andyp1per:pr-scripting-osd
Open

Scripting OSD#32045
andyp1per wants to merge 14 commits intoArduPilot:masterfrom
andyp1per:pr-scripting-osd

Conversation

@andyp1per
Copy link
Copy Markdown
Contributor

@andyp1per andyp1per commented Jan 29, 2026

This is a rebase of #18000

Summary

Adds Lua scripting bindings for OSD, allowing scripts to write custom content to OSD displays.

Features

  • osd:write(col, row, text) - Write text at position
  • osd:clear() - Clear OSD buffer
  • osd:flush() - Push buffer to display
  • osd:draw_screen() - Request screen redraw
  • osd:get_backend_count() - Get number of backends
  • osd:get_backend_type(i) - Get backend type

Example Script

See libraries/AP_Scripting/examples/osd.lua for a full example demonstrating:

  • Flight mode display
  • Battery status with symbol
  • Altitude and ground speed
  • GPS status
  • Waypoint navigation info (when in AUTO mode with mission)
  • Support for both MAX7456 and MSP DisplayPort symbol tables

Testing

Running the autotest with SFML OSD display

To see the OSD window during testing, build SITL with SFML support:

# Configure with SFML OSD enabled
./waf configure --board sitl --enable-sfml --sitl-osd

# Build copter
./waf copter

# Run the ScriptingOSD test at slow speed (SIM_SPEEDUP=5 for visibility)
Tools/autotest/autotest.py test.Copter.ScriptingOSD

The test will:

  1. Enable scripting and OSD
  2. Install the example OSD script
  3. Load a waypoint mission
  4. Arm and fly the mission in AUTO mode
  5. Display custom OSD content including waypoint distance

The SFML window shows the OSD output in real-time.

Manual testing

# Start SITL with OSD
Tools/autotest/sim_vehicle.py -v ArduCopter --osd

# In MAVProxy console:
param set SCR_ENABLE 1
reboot

# Copy the example script
# scripts/osd.lua -> APM/scripts/osd.lua

# Reboot to load script
reboot
image

@andyp1per andyp1per requested a review from IamPete1 January 29, 2026 15:31
@andyp1per andyp1per force-pushed the pr-scripting-osd branch 5 times, most recently from d4c7dfb to 3c94840 Compare January 29, 2026 16:01
@LupusTheCanine
Copy link
Copy Markdown

LupusTheCanine commented Jan 29, 2026

Can this be used together with standard MSP canvas OSD?

The ScriptingOSD test requires SFML which is not available in
the CI environment. Add it to disabled_tests() so CI skips it
cleanly rather than failing.
Copy link
Copy Markdown
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect there should be some semaphores in here somewhere.

I never was very happy with how this ended up. What do you need for your use case? Would it be better to have a scripting page rather than take over the whole OSD?

Comment thread libraries/AP_OSD/AP_OSD.cpp Outdated
Comment thread libraries/AP_Scripting/generator/description/bindings.desc
…word

Use the existing literal singleton pattern instead of adding a new get
keyword to the generator. This makes the bindings.desc more verbose but
avoids adding new generator features.
Remove redundant type check since both branches returned false.
Add get_semaphore() to AP_OSD_Backend that delegates to the parent
AP_OSD semaphore. Add semaphore keyword to scripting bindings so that
all OSD method calls from Lua are thread-safe with respect to the
OSD update thread.
Use customise_SITL_commandline to pass --osd flag so SITL actually
creates the OSD window when running the test.
The OSD binding exists when OSD_ENABLED is true, but the underlying
backend may be nullptr at runtime (e.g., when SITL is not built with
SFML support). The simple "if not osd" check only verifies the binding
exists, not whether the backend is valid.

Add a pcall-based check that tests if a method call succeeds, which
properly detects when the backend is unavailable.
- Remove --osd flag and customise_SITL_commandline as SFML may not
  be available
- Remove SIM_SPEEDUP change that was only needed for visual testing
- Remove ScriptingOSD from disabled_tests since the test now properly
  detects and handles missing OSD backend gracefully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants