Skip to content

Sitl ap camera#32680

Open
TharakaUJ wants to merge 2 commits into
ArduPilot:masterfrom
TharakaUJ:SITL-AP-Camera
Open

Sitl ap camera#32680
TharakaUJ wants to merge 2 commits into
ArduPilot:masterfrom
TharakaUJ:SITL-AP-Camera

Conversation

@TharakaUJ
Copy link
Copy Markdown
Contributor

@TharakaUJ TharakaUJ commented Apr 4, 2026

Summary

Add a new SITL camera simulation object (SIM_Camera) similar to
existing payload simulations (e.g. sprayer and gripper). The camera
can be triggered via servo output or GPIO and logs image capture events.

Fixes #9396

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Tested in SITL using ArduPlane.

Steps:

  • Build and run SITL
  • Verify camera parameters exist:
param show SIM_CAM_ENABLE
param show SIM_CAM_SRV_PIN
param show SIM_CAM_SRV_PWM
param show SIM_CAM_GPIO
  • Enable camera simulation:
param set SIM_CAM_ENABLE 1

Trigger via servo:

Assign a servo output to camera trigger

param set SERVO9_FUNCTION 0
param set SIM_CAM_SRV_PIN 9

Increase PWM above threshold (SIM_CAM_SRV_PWM)

servo set 9 1800
servo set 9 1000

Observe GCS output:
SITL: Camera image N

Trigger via GPIO:
Set GPIO pin using SIM_CAM_GPIO

param set SIM_CAM_GPIO 9
param set relay1_pin 9

Toggle the corresponding SITL GPIO bit

relay set 0 1
relay set 0 0

Verify image capture message is generated

SITL runs normally and camera trigger events are detected correctly.

Description

This PR introduces a new SIM_Camera object in the SITL framework of ArduPilot.

Features:
New SITL camera simulation class (SIM_Camera)
Enable/disable via SIM_CAM_ENABLE
Trigger mechanisms:

  • Servo-based trigger (SIM_CAM_TRIG_SRV, SIM_CAM_TRIG_PWM)
  • GPIO-based trigger (SIM_CAM_GPIO_PIN)
    Edge-triggered capture detection
    Logs image capture events to GCS

Notes:

  • This implementation provides a basic simulation framework for camera triggering in SITL.
  • It does not yet implement MAVLink camera commands or image generation, but establishes the structure for future extensions.

Edit:

  • I changed the parameter names later, changed the testing steps accordingly.
  • Addition to first camera you can test the second camera using same approach, but use the names prefixed with 'SIM_CAM2', ex:
param set SIM_CAM2_ENABLE 1

Copy link
Copy Markdown
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

I like this idea.

Comment thread libraries/AP_HAL_SITL/SITL_State.cpp Outdated
@@ -54,6 +54,7 @@ void SITL_State::_sitl_setup()
#endif

sitl_model->set_buzzer(&_sitl->buzzer_sim);
sitl_model->set_camera(&_sitl->camera_sim);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please make this add_camera - we support multiple cameras in the main firmware, we should support it out here, too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made the necessary changes. I wasn't sure about how many cameras to support. From what I saw from AP_Camera.h, added support for 2 cameras. Let me know if anytthing needs to be changed. Thanks!

Comment thread libraries/SITL/SIM_Aircraft.cpp Outdated
@@ -1106,6 +1106,11 @@ void Aircraft::update_external_payload(const struct sitl_input &input)
{
external_payload_mass = 0;

// update camera
if (camera && camera->is_enabled()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should become iteration over an array.

Please note our fondness of continue in these loops when putting the enabled() check in

Comment thread libraries/SITL/SITL.cpp
@@ -655,6 +655,10 @@ const AP_Param::GroupInfo SIM::var_info3[] = {
AP_SUBGROUPINFO(vicon, "VICON_", 56, SIM, ViconParms),
#endif // AP_SIM_VICON_ENABLED

// @Group: CAM_
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// @Group: CAM_
#if AP_SIM_CAM_ENABLED
// @Group: CAM_

add the define to SIM_config.h

Obviously add this everywhere :-)

@Hwurzburg Hwurzburg added the WikiNeeded needs wiki update label Apr 4, 2026
@TharakaUJ
Copy link
Copy Markdown
Contributor Author

Updated to support multiple cameras using add_camera() and array iteration, with compile-time guards via AP_SIM_CAM_ENABLED.
Parameter support is currently implemented for up to 2 cameras, kind of followed the pattern in AP_Camera.h

Also added handling for when camera slots are full.
Thank you!

@TharakaUJ
Copy link
Copy Markdown
Contributor Author

I'll fix the rest of the issues and push again.

Add a new SIM_Camera object to SITL, similar to existing Sprayer and
Gripper payload simulations.

The camera simulation can be enabled via SIM_CAM_ENABLE and supports
triggering image capture via:
 - servo output (TRIG_SRV + TRIG_PWM)
 - GPIO pin (GPIO)

When triggered, the camera increments an internal image counter and
sends a GCS message indicating capture.
Add a new SIM_Camera object to SITL, similar to existing Sprayer and
Gripper payload simulations.

The camera simulation can be enabled via SIM_CAM_ENABLE and supports
triggering image capture via:
 - servo output (TRIG_SRV + TRIG_PWM)
 - GPIO pin (GPIO)

When triggered, the camera increments an internal image counter and
sends a GCS message indicating capture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WikiNeeded needs wiki update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SITL: AP_Camera object

3 participants