From 78d88d11a3fcff40775c2e88485384ebc0dc3cc8 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Fri, 23 Aug 2024 14:54:59 +0900 Subject: [PATCH] AP_Camera: add change settings --- libraries/AP_Camera/AP_Camera.cpp | 13 +++++++++++++ libraries/AP_Camera/AP_Camera.h | 3 +++ libraries/AP_Camera/AP_Camera_Backend.h | 3 +++ libraries/AP_Camera/AP_Camera_Mount.cpp | 12 ++++++++++++ libraries/AP_Camera/AP_Camera_Mount.h | 5 +++++ libraries/AP_Camera/AP_Camera_shareddefs.h | 6 ++++++ 6 files changed, 42 insertions(+) diff --git a/libraries/AP_Camera/AP_Camera.cpp b/libraries/AP_Camera/AP_Camera.cpp index b3869c4818..c37243723e 100644 --- a/libraries/AP_Camera/AP_Camera.cpp +++ b/libraries/AP_Camera/AP_Camera.cpp @@ -780,6 +780,19 @@ bool AP_Camera::get_state(uint8_t instance, camera_state_t& cam_state) } return backend->get_state(cam_state); } + +// change camera settings not normally used by autopilot +bool AP_Camera::change_setting(uint8_t instance, CameraSetting setting, float value) +{ + WITH_SEMAPHORE(_rsem); + + auto *backend = get_instance(instance); + if (backend == nullptr) { + return false; + } + return backend->change_setting(setting, value); +} + #endif // #if AP_CAMERA_SCRIPTING_ENABLED // return backend for instance number diff --git a/libraries/AP_Camera/AP_Camera.h b/libraries/AP_Camera/AP_Camera.h index dd9f4ddfde..28a27b0fa3 100644 --- a/libraries/AP_Camera/AP_Camera.h +++ b/libraries/AP_Camera/AP_Camera.h @@ -181,6 +181,9 @@ public: // accessor to allow scripting backend to retrieve state // returns true on success and cam_state is filled in bool get_state(uint8_t instance, camera_state_t& cam_state); + + // change camera settings not normally used by autopilot + bool change_setting(uint8_t instance, CameraSetting setting, float value); #endif // Return true and the relay index if relay camera backend is selected, used for conversion to relay functions diff --git a/libraries/AP_Camera/AP_Camera_Backend.h b/libraries/AP_Camera/AP_Camera_Backend.h index 6c5543cf82..d52944f5c0 100644 --- a/libraries/AP_Camera/AP_Camera_Backend.h +++ b/libraries/AP_Camera/AP_Camera_Backend.h @@ -130,6 +130,9 @@ public: // accessor to allow scripting backend to retrieve state // returns true on success and cam_state is filled in virtual bool get_state(AP_Camera::camera_state_t& cam_state) { return false; } + + // change camera settings not normally used by autopilot + virtual bool change_setting(CameraSetting setting, float value) { return false; } #endif protected: diff --git a/libraries/AP_Camera/AP_Camera_Mount.cpp b/libraries/AP_Camera/AP_Camera_Mount.cpp index 29f0759116..b472d068eb 100644 --- a/libraries/AP_Camera/AP_Camera_Mount.cpp +++ b/libraries/AP_Camera/AP_Camera_Mount.cpp @@ -109,4 +109,16 @@ void AP_Camera_Mount::send_camera_capture_status(mavlink_channel_t chan) const } } +#if AP_CAMERA_SCRIPTING_ENABLED +// change camera settings not normally used by autopilot +bool AP_Camera_Mount::change_setting(CameraSetting setting, float value) +{ + AP_Mount* mount = AP::mount(); + if (mount != nullptr) { + return mount->change_setting(get_mount_instance(), setting, value); + } + return false; +} +#endif + #endif // AP_CAMERA_MOUNT_ENABLED diff --git a/libraries/AP_Camera/AP_Camera_Mount.h b/libraries/AP_Camera/AP_Camera_Mount.h index d001cb979d..b3dd450652 100644 --- a/libraries/AP_Camera/AP_Camera_Mount.h +++ b/libraries/AP_Camera/AP_Camera_Mount.h @@ -69,6 +69,11 @@ public: // send camera capture status message to GCS void send_camera_capture_status(mavlink_channel_t chan) const override; + +#if AP_CAMERA_SCRIPTING_ENABLED + // change camera settings not normally used by autopilot + bool change_setting(CameraSetting setting, float value) override; +#endif }; #endif // AP_CAMERA_MOUNT_ENABLED diff --git a/libraries/AP_Camera/AP_Camera_shareddefs.h b/libraries/AP_Camera/AP_Camera_shareddefs.h index 6543eff0bc..7579878c54 100644 --- a/libraries/AP_Camera/AP_Camera_shareddefs.h +++ b/libraries/AP_Camera/AP_Camera_shareddefs.h @@ -36,3 +36,9 @@ enum class TrackingType : uint8_t { TRK_RECTANGLE = 2 // tracking a rectangle }; +// camera settings not normally used by the autopilot +enum class CameraSetting { + THERMAL_PALETTE = 0, // set thermal palette + THERMAL_GAIN = 1, // set thermal gain, value of 0:low gain, 1:high gain + THERMAL_RAW_DATA = 2, // enable/disable thermal raw data +};