Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Camera/AP_Camera_Logging.cpp
Views: 1798
#include "AP_Camera_Backend.h"1#include <AP_Mount/AP_Mount.h>2#include <AP_Logger/AP_Logger_config.h>34#if AP_CAMERA_ENABLED && HAL_LOGGING_ENABLED56#include <AP_Logger/AP_Logger.h>7#include <AP_GPS/AP_GPS.h>8#include <AP_AHRS/AP_AHRS.h>910// Write a Camera packet. Also writes a Mount packet if available11void AP_Camera_Backend::Write_CameraInfo(enum LogMessages msg, uint64_t timestamp_us)12{13// exit immediately if no logger14AP_Logger *logger = AP_Logger::get_singleton();15if (logger == nullptr) {16return;17}1819// exit immediately if should not log camera messages20if (!logger->should_log(_frontend.get_log_camera_bit())) {21return;22}2324const AP_AHRS &ahrs = AP::ahrs();2526Location current_loc;27if (!ahrs.get_location(current_loc)) {28// completely ignore this failure! AHRS will provide its best guess.29}3031int32_t altitude_cm = 0;32if (!current_loc.get_alt_cm(Location::AltFrame::ABSOLUTE, altitude_cm)) {33// ignore this problem...34}35int32_t altitude_rel_cm = 0;36if (!current_loc.get_alt_cm(Location::AltFrame::ABOVE_HOME, altitude_rel_cm)) {37// ignore this problem...38}394041int32_t altitude_gps_cm = 0;42const AP_GPS &gps = AP::gps();43if (gps.status() >= AP_GPS::GPS_OK_FIX_3D) {44if (!gps.location().get_alt_cm(Location::AltFrame::ABSOLUTE, altitude_gps_cm)) {45// ignore this problem...46}47}4849// if timestamp is zero set to current system time50if (timestamp_us == 0) {51timestamp_us = AP_HAL::micros64();52}5354const struct log_Camera pkt{55LOG_PACKET_HEADER_INIT(static_cast<uint8_t>(msg)),56time_us : timestamp_us,57instance : _instance,58image_number: image_index,59gps_time : gps.time_week_ms(),60gps_week : gps.time_week(),61latitude : current_loc.lat,62longitude : current_loc.lng,63altitude : altitude_cm,64altitude_rel: altitude_rel_cm,65altitude_gps: altitude_gps_cm,66roll : (int16_t)ahrs.roll_sensor,67pitch : (int16_t)ahrs.pitch_sensor,68yaw : (uint16_t)ahrs.yaw_sensor69};70AP::logger().WriteCriticalBlock(&pkt, sizeof(pkt));7172#if HAL_MOUNT_ENABLED73auto *mount = AP_Mount::get_singleton();74if (mount!= nullptr) {75mount->write_log(get_mount_instance(), timestamp_us);76}77#endif78}7980// Write a Camera packet81void AP_Camera_Backend::Write_Camera(uint64_t timestamp_us)82{83Write_CameraInfo(LOG_CAMERA_MSG, timestamp_us);84}8586// Write a Trigger packet87void AP_Camera_Backend::Write_Trigger()88{89Write_CameraInfo(LOG_TRIGGER_MSG, 0);90}9192#endif // AP_CAMERA_ENABLED && HAL_LOGGING_ENABLED939495