Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Camera/AP_Camera_Logging.cpp
9352 views
1
#include "AP_Camera_Backend.h"
2
#include <AP_Mount/AP_Mount.h>
3
#include <AP_Logger/AP_Logger_config.h>
4
5
#if AP_CAMERA_ENABLED && HAL_LOGGING_ENABLED
6
7
#include <AP_Logger/AP_Logger.h>
8
#include <AP_GPS/AP_GPS.h>
9
#include <AP_AHRS/AP_AHRS.h>
10
11
// Write a Camera packet. Also writes a Mount packet if available
12
void AP_Camera_Backend::Write_CameraInfo(enum LogMessages msg, uint64_t timestamp_us)
13
{
14
// exit immediately if no logger
15
AP_Logger *logger = AP_Logger::get_singleton();
16
if (logger == nullptr) {
17
return;
18
}
19
20
// exit immediately if should not log camera messages
21
if (!logger->should_log(_frontend.get_log_camera_bit())) {
22
return;
23
}
24
25
const AP_AHRS &ahrs = AP::ahrs();
26
27
Location current_loc;
28
if (!ahrs.get_location(current_loc)) {
29
// completely ignore this failure! AHRS will provide its best guess.
30
}
31
32
int32_t altitude_cm = 0;
33
int32_t altitude_rel_cm = 0;
34
if (current_loc.initialised()) {
35
// ignore failures to get altitude
36
IGNORE_RETURN(current_loc.get_alt_cm(Location::AltFrame::ABSOLUTE, altitude_cm));
37
IGNORE_RETURN(current_loc.get_alt_cm(Location::AltFrame::ABOVE_HOME, altitude_rel_cm));
38
}
39
40
int32_t altitude_gps_cm = 0;
41
const AP_GPS &gps = AP::gps();
42
if (gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
43
if (!gps.location().get_alt_cm(Location::AltFrame::ABSOLUTE, altitude_gps_cm)) {
44
// ignore this problem...
45
}
46
}
47
48
// if timestamp is zero set to current system time
49
if (timestamp_us == 0) {
50
timestamp_us = AP_HAL::micros64();
51
}
52
53
const struct log_Camera pkt{
54
LOG_PACKET_HEADER_INIT(static_cast<uint8_t>(msg)),
55
time_us : timestamp_us,
56
instance : _instance,
57
image_number: image_index,
58
gps_time : gps.time_week_ms(),
59
gps_week : gps.time_week(),
60
latitude : current_loc.lat,
61
longitude : current_loc.lng,
62
altitude : altitude_cm,
63
altitude_rel: altitude_rel_cm,
64
altitude_gps: altitude_gps_cm,
65
roll : ahrs.get_roll_deg(),
66
pitch : ahrs.get_pitch_deg(),
67
yaw : ahrs.get_yaw_deg()
68
};
69
AP::logger().WriteCriticalBlock(&pkt, sizeof(pkt));
70
71
#if HAL_MOUNT_ENABLED
72
auto *mount = AP_Mount::get_singleton();
73
if (mount!= nullptr) {
74
mount->write_log(get_mount_instance(), timestamp_us);
75
}
76
#endif
77
}
78
79
// Write a Camera packet
80
void AP_Camera_Backend::Write_Camera(uint64_t timestamp_us)
81
{
82
Write_CameraInfo(LOG_CAMERA_MSG, timestamp_us);
83
}
84
85
// Write a Trigger packet
86
void AP_Camera_Backend::Write_Trigger()
87
{
88
Write_CameraInfo(LOG_TRIGGER_MSG, 0);
89
}
90
91
#endif // AP_CAMERA_ENABLED && HAL_LOGGING_ENABLED
92
93