123 lines
3.3 KiB
C++
123 lines
3.3 KiB
C++
#ifndef AUTO_FTS_MESSAGE_HPP
|
|
#define AUTO_FTS_MESSAGE_HPP
|
|
|
|
#include <lib/geo/geo.h>
|
|
#include <lib/mathlib/mathlib.h>
|
|
#include <lib/matrix/matrix/math.hpp>
|
|
|
|
#include <uORB/Subscription.hpp>
|
|
#include <uORB/topics/airspeed.h>
|
|
#include <uORB/topics/battery_status.h>
|
|
#include <uORB/topics/estimator_selector_status.h>
|
|
#include <uORB/topics/estimator_gps_status.h>
|
|
#include <uORB/topics/geofence_result.h>
|
|
#include <uORB/topics/mission_result.h>
|
|
#include <uORB/topics/position_controller_status.h>
|
|
#include <uORB/topics/tecs_status.h>
|
|
#include <uORB/topics/wind.h>
|
|
#include <uORB/topics/vehicle_attitude_setpoint.h>
|
|
#include <uORB/topics/vehicle_global_position.h>
|
|
#include <uORB/topics/vehicle_thrust_setpoint.h>
|
|
#include <uORB/topics/sensor_gps.h>
|
|
#include <uORB/topics/vehicle_local_position.h>
|
|
#include <uORB/topics/vehicle_status.h>
|
|
#include <uORB/topics/failsafe_flags.h>
|
|
#include <uORB/topics/health_report.h>
|
|
|
|
#include <px4_platform_common/events.h>
|
|
|
|
class MavlinkStreamAftsStatus : public MavlinkStream
|
|
{
|
|
public:
|
|
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAftsStatus(mavlink); }
|
|
|
|
static constexpr const char *get_name_static() { return "AUTO_FTS_MESSAGE"; }
|
|
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_AUTO_FTS_MESSAGE; }
|
|
|
|
const char *get_name() const override { return get_name_static(); }
|
|
uint16_t get_id() override { return get_id_static(); }
|
|
|
|
uORB::Subscription _geofence_sub{ORB_ID(geofence_result)};
|
|
uORB::Subscription _estimator_gps_status_sub{ORB_ID(estimator_gps_status)};
|
|
|
|
hrt_abstime _last_reset_time{0};
|
|
hrt_abstime _last_update_time{0};
|
|
|
|
unsigned get_size() override
|
|
{
|
|
return MAVLINK_MSG_ID_AUTO_FTS_MESSAGE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
}
|
|
|
|
bool const_rate() override { return true; }
|
|
|
|
private:
|
|
explicit MavlinkStreamAftsStatus(Mavlink *mavlink) :
|
|
MavlinkStream(mavlink)
|
|
{
|
|
}
|
|
|
|
bool send() override
|
|
{
|
|
mavlink_auto_fts_message_t msg{};
|
|
set_default_values(msg);
|
|
|
|
write_geofence_result(&msg);
|
|
|
|
write_gps_status(&msg);
|
|
|
|
mavlink_msg_auto_fts_message_send_struct(_mavlink->get_channel(), &msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool write_geofence_result(mavlink_auto_fts_message_t *msg)
|
|
{
|
|
geofence_result_s geofence;
|
|
|
|
if (_geofence_sub.update(&geofence)) {
|
|
if (geofence.primary_geofence_breached) {
|
|
msg->geofence_violated = 1;
|
|
}else {
|
|
msg->geofence_violated = 0;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool write_gps_status(mavlink_auto_fts_message_t *msg)
|
|
{
|
|
estimator_gps_status_s gps_status;
|
|
|
|
if (_estimator_gps_status_sub.update(&gps_status)) {
|
|
//FAIL FLAGS THAT NEED TO BE CLEAR TO INDICATE GPS OK
|
|
if (
|
|
!gps_status.check_fail_gps_fix &&
|
|
!gps_status.check_fail_min_sat_count &&
|
|
!gps_status.check_fail_max_horz_err &&
|
|
!gps_status.check_fail_max_vert_err
|
|
) {
|
|
msg->gps_lock = 1;
|
|
}else {
|
|
msg->gps_lock = 0;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void set_default_values(mavlink_auto_fts_message_t &msg) const
|
|
{
|
|
msg.config_status = 0;
|
|
msg.geofence_loaded = 0;
|
|
msg.gps_lock = 0;
|
|
msg.geofence_violated = 0;
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|