-
Notifications
You must be signed in to change notification settings - Fork 17.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AP_Mount, AP_Camera: Load CAMERA_INFORMATION from JSON #27594
AP_Mount, AP_Camera: Load CAMERA_INFORMATION from JSON #27594
Conversation
really great to see this! |
Two issues:
I'll fix them now... |
Allows base AP_Camera driver to send this message if not sent by the AP_Mount driver.
Allows base AP_Camera driver to send this message if not sent by the AP_Mount driver.
01583e5
to
fd46a2f
Compare
@rmackay9: I'll jump on the dev call tomorrow if you want to discuss this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that when compiled out these new features take up approximately no space.
Won't be able to be no space given different return values for some methods now
@@ -462,6 +462,10 @@ bool AP_Camera::send_mavlink_message(GCS_MAVLINK &link, const enum ap_message ms | |||
CHECK_PAYLOAD_SIZE2(CAMERA_CAPTURE_STATUS); | |||
send_camera_capture_status(chan); | |||
break; | |||
case MSG_VIDEO_STREAM_INFO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case MSG_VIDEO_STREAM_INFO: | |
AP_MAVLINK_MSG_VIDEO_STREAM_INFORMATION_ENABLED | |
case MSG_VIDEO_STREAM_INFO: |
.... and generally use it elsewhere. These are defined in GCS_config.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
#endif | ||
|
||
#if AP_CAMERA_JSON_INFO_ENABLED | ||
#include <AP_Filesystem/AP_Filesystem.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't usually indent these lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// fall back to looking for the same folder in ROMFS. | ||
// | ||
// This allocates a AP_JSON::value object that will need to be freed. | ||
AP_JSON::value * AP_Camera_Backend::_load_mount_msg_json(const char* json_filename) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AP_JSON::value * AP_Camera_Backend::_load_mount_msg_json(const char* json_filename) { | |
AP_JSON::value * AP_Camera_Backend::_load_mount_msg_json(const char* json_filename) | |
{ |
similarly elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// This allocates a AP_JSON::value object that will need to be freed. | ||
AP_JSON::value * AP_Camera_Backend::_load_mount_msg_json(const char* json_filename) { | ||
char* romfs_json_path = nullptr; | ||
int alloc = asprintf(&romfs_json_path, "@ROMFS/mav_msg_def/AP_Camera/%s", json_filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do without the local here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it more readable with the local.
} | ||
|
||
// helper function to copy a JSON double into a msg struct | ||
template <typename T> bool AP_Camera_Backend::_copy_json_field_double(const AP_JSON::value* obj, const char* key, T& dst) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template <typename T> bool AP_Camera_Backend::_copy_json_field_double(const AP_JSON::value* obj, const char* key, T& dst) { | |
template <typename T> | |
bool AP_Camera_Backend::_copy_json_field_double(const AP_JSON::value* obj, const char* key, T& dst) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if (!_copy_json_field_string(obj, "cam_definition_uri", camera_info.msg.cam_definition_uri, sizeof(camera_info.msg.cam_definition_uri))) goto err; | ||
|
||
// Populate the fields that shouldn't change. | ||
camera_info.msg.time_boot_ms = AP_HAL::millis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errr.. this one should definitely change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
#undef GET_JSON_DOUBLE | ||
#undef GET_JSON_STR | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these replaced by the template function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they were. Fixed.
@@ -87,7 +87,16 @@ void AP_Camera_Mount::send_camera_information(mavlink_channel_t chan) const | |||
{ | |||
AP_Mount* mount = AP::mount(); | |||
if (mount != nullptr) { | |||
return mount->send_camera_information(get_mount_instance(), chan); | |||
bool sent_by_mount = mount->send_camera_information(get_mount_instance(), chan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool sent_by_mount = mount->send_camera_information(get_mount_instance(), chan); | |
const bool sent_by_mount = mount->send_camera_information(get_mount_instance(), chan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
AP_Mount* mount = AP::mount(); | ||
if (mount != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AP_Mount* mount = AP::mount(); | |
if (mount != nullptr) { | |
AP_Mount* mount = AP::mount(); | |
if (mount == nullptr) { | |
return; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,20 @@ | |||
# This file is used to populate the VIDEO_STREAM_INFORMATION message sent by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHould we put these under an "examples" subdirectory as we do for a lot of other things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer they live in the AP_Camera
folder. The code in the backend makes assumptions about what fields are and aren't present in the JSON.
fd46a2f
to
230a5ca
Compare
Temporarily back to draft -- I need to confirm that this still works on hardware. |
Loads the contents of the following messages from JSON files: - CAMERA_INFORMATION - VIDEO_STREAM_INFORMATION
ArduPilot doesn't disambiguate MAVLink Camera messages between backends, so don't bother supporting multiple JSON definitions.
230a5ca
to
40a132f
Compare
Running on a CubeOrange with debug enabled:
|
@rmackay9, @peterbarker: Closing in favour of #27794 |
This PR allows us to add a
*.json
file to the SD card (or ROMFS) that is used to populate theCAMERA_INFORMATION
andVIDEO_STREAM_INFORMATION
MAVLink messages. These messages are sent forAP_Mount
backends that do not already implement these messages.Sending these messages allows a GCS to auto-configure the video stream to receive video from the payload.