Path: blob/master/libraries/AC_Avoidance/AC_Avoidance_Logging.cpp
4182 views
#include <AP_Logger/AP_Logger_config.h>12#if HAL_LOGGING_ENABLED34#include <AP_AHRS/AP_AHRS.h>5#include "AC_Avoid.h"6#include "AP_OADijkstra.h"7#include "AP_OABendyRuler.h"8#include <AP_Logger/AP_Logger.h>9#include <AP_AHRS/AP_AHRS.h>1011#if AP_OAPATHPLANNER_BENDYRULER_ENABLED12void AP_OABendyRuler::Write_OABendyRuler(const uint8_t type, const bool active, const float target_yaw, const float target_pitch, const bool resist_chg, const float margin, const Location &final_dest, const Location &oa_dest) const13{14auto &logger = AP::logger();1516float oa_dest_alt;17if (!oa_dest.get_alt_m(Location::AltFrame::ABOVE_ORIGIN, oa_dest_alt)) {18oa_dest_alt = logger.quiet_nanf();19}20float final_alt;21if (!final_dest.get_alt_m(Location::AltFrame::ABOVE_ORIGIN, final_alt)) {22final_alt = logger.quiet_nanf();23}2425const struct log_OABendyRuler pkt{26LOG_PACKET_HEADER_INIT(LOG_OA_BENDYRULER_MSG),27time_us : AP_HAL::micros64(),28type : type,29active : active,30target_yaw : (uint16_t)wrap_360(target_yaw),31yaw : (uint16_t)wrap_360(AP::ahrs().get_yaw_deg()),32target_pitch: (uint16_t)target_pitch,33resist_chg : resist_chg,34margin : margin,35final_lat : final_dest.lat,36final_lng : final_dest.lng,37final_alt : final_alt,38oa_lat : oa_dest.lat,39oa_lng : oa_dest.lng,40oa_alt : oa_dest_alt41};42logger.WriteBlock(&pkt, sizeof(pkt));43}44#endif // AP_OAPATHPLANNER_BENDYRULER_ENABLED4546#if AP_OAPATHPLANNER_DIJKSTRA_ENABLED47void AP_OADijkstra::Write_OADijkstra(const uint8_t state, const uint8_t error_id, const uint8_t curr_point, const uint8_t tot_points, const Location &final_dest, const Location &oa_dest) const48{49const struct log_OADijkstra pkt{50LOG_PACKET_HEADER_INIT(LOG_OA_DIJKSTRA_MSG),51time_us : AP_HAL::micros64(),52state : state,53error_id : error_id,54curr_point : curr_point,55tot_points : tot_points,56final_lat : final_dest.lat,57final_lng : final_dest.lng,58oa_lat : oa_dest.lat,59oa_lng : oa_dest.lng60};61AP::logger().WriteBlock(&pkt, sizeof(pkt));62}63#endif6465#if AP_OAPATHPLANNER_ENABLED66void AP_OADijkstra::Write_Visgraph_point(const uint8_t version, const uint8_t point_num, const int32_t Lat, const int32_t Lon) const67{68const struct log_OD_Visgraph pkt{69LOG_PACKET_HEADER_INIT(LOG_OD_VISGRAPH_MSG),70time_us : AP_HAL::micros64(),71version : version,72point_num : point_num,73Lat : Lat,74Lon : Lon,75};76AP::logger().WriteBlock(&pkt, sizeof(pkt));77}78#endif7980#if AP_AVOIDANCE_ENABLED81void AC_Avoid::Write_SimpleAvoidance(const uint8_t state, const Vector3f& desired_vel, const Vector3f& modified_vel, const bool back_up) const82{83const struct log_SimpleAvoid pkt{84LOG_PACKET_HEADER_INIT(LOG_SIMPLE_AVOID_MSG),85time_us : AP_HAL::micros64(),86state : state,87desired_vel_x : desired_vel.x * 0.01f,88desired_vel_y : desired_vel.y * 0.01f,89desired_vel_z : desired_vel.z * 0.01f,90modified_vel_x : modified_vel.x * 0.01f,91modified_vel_y : modified_vel.y * 0.01f,92modified_vel_z : modified_vel.z * 0.01f,93backing_up : back_up,94};95AP::logger().WriteBlock(&pkt, sizeof(pkt));96}97#endif9899#endif // HAL_LOGGING_ENABLED100101102