2014-03-01 00:16:51 +04:00
|
|
|
/****************************************************************************
|
2012-10-14 17:59:15 -07:00
|
|
|
*
|
2017-05-06 12:38:28 +02:00
|
|
|
* Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
|
2014-03-01 00:16:51 +04:00
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file mavlink_messages.cpp
|
2017-05-06 12:38:28 +02:00
|
|
|
* MAVLink 2.0 message formatters implementation.
|
2014-03-01 00:16:51 +04:00
|
|
|
*
|
2015-02-11 17:42:51 +01:00
|
|
|
* @author Lorenz Meier <lorenz@px4.io>
|
2014-03-01 00:16:51 +04:00
|
|
|
* @author Anton Babushkin <anton.babushkin@me.com>
|
2012-10-14 17:59:15 -07:00
|
|
|
*/
|
|
|
|
|
|
2014-02-27 13:54:55 +04:00
|
|
|
#include <stdio.h>
|
2015-06-13 16:36:00 +02:00
|
|
|
#include <errno.h>
|
2018-01-26 13:17:08 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
#include <float.h>
|
2014-07-24 12:10:21 +02:00
|
|
|
|
2016-06-27 10:16:24 -04:00
|
|
|
#include "mavlink_main.h"
|
|
|
|
|
#include "mavlink_messages.h"
|
2017-07-05 16:13:42 +02:00
|
|
|
#include "mavlink_command_sender.h"
|
2018-04-10 09:57:03 +02:00
|
|
|
#include "mavlink_simple_analyzer.h"
|
2018-04-10 14:42:30 +02:00
|
|
|
#include "mavlink_high_latency2.h"
|
2016-06-27 10:16:24 -04:00
|
|
|
|
2014-02-26 00:24:14 +04:00
|
|
|
#include <commander/px4_custom_mode.h>
|
2016-06-27 10:16:24 -04:00
|
|
|
#include <drivers/drv_pwm_output.h>
|
|
|
|
|
#include <drivers/drv_rc_input.h>
|
2018-03-19 00:33:20 -04:00
|
|
|
#include <lib/ecl/geo/geo.h>
|
2016-06-27 10:16:24 -04:00
|
|
|
#include <mathlib/mathlib.h>
|
|
|
|
|
#include <px4_time.h>
|
|
|
|
|
#include <systemlib/err.h>
|
|
|
|
|
#include <systemlib/mavlink_log.h>
|
|
|
|
|
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/actuator_armed.h>
|
|
|
|
|
#include <uORB/topics/actuator_controls.h>
|
|
|
|
|
#include <uORB/topics/actuator_outputs.h>
|
|
|
|
|
#include <uORB/topics/airspeed.h>
|
|
|
|
|
#include <uORB/topics/att_pos_mocap.h>
|
|
|
|
|
#include <uORB/topics/battery_status.h>
|
|
|
|
|
#include <uORB/topics/camera_trigger.h>
|
2017-05-01 11:23:02 +02:00
|
|
|
#include <uORB/topics/camera_capture.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/cpuload.h>
|
|
|
|
|
#include <uORB/topics/debug_key_value.h>
|
2017-06-07 15:37:25 +02:00
|
|
|
#include <uORB/topics/debug_value.h>
|
2017-06-07 15:45:55 +02:00
|
|
|
#include <uORB/topics/debug_vect.h>
|
2016-06-21 14:12:13 +02:00
|
|
|
#include <uORB/topics/differential_pressure.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/distance_sensor.h>
|
|
|
|
|
#include <uORB/topics/estimator_status.h>
|
2016-06-27 10:16:24 -04:00
|
|
|
#include <uORB/topics/fw_pos_ctrl_status.h>
|
2018-01-30 18:04:37 +01:00
|
|
|
#include <uORB/topics/geofence_result.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/home_position.h>
|
|
|
|
|
#include <uORB/topics/manual_control_setpoint.h>
|
|
|
|
|
#include <uORB/topics/mavlink_log.h>
|
|
|
|
|
#include <uORB/topics/optical_flow.h>
|
|
|
|
|
#include <uORB/topics/position_setpoint_triplet.h>
|
2014-02-28 23:44:51 +04:00
|
|
|
#include <uORB/topics/sensor_combined.h>
|
2017-09-21 16:24:53 -04:00
|
|
|
#include <uORB/topics/sensor_bias.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/tecs_status.h>
|
|
|
|
|
#include <uORB/topics/telemetry_status.h>
|
|
|
|
|
#include <uORB/topics/transponder_report.h>
|
2014-02-28 23:44:51 +04:00
|
|
|
#include <uORB/topics/vehicle_attitude.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/vehicle_attitude_setpoint.h>
|
|
|
|
|
#include <uORB/topics/vehicle_command.h>
|
2017-08-17 09:49:21 -04:00
|
|
|
#include <uORB/topics/vehicle_control_mode.h>
|
2014-02-26 22:47:19 +04:00
|
|
|
#include <uORB/topics/vehicle_global_position.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/vehicle_gps_position.h>
|
|
|
|
|
#include <uORB/topics/vehicle_land_detected.h>
|
2014-02-28 23:44:51 +04:00
|
|
|
#include <uORB/topics/vehicle_local_position.h>
|
|
|
|
|
#include <uORB/topics/vehicle_local_position_setpoint.h>
|
|
|
|
|
#include <uORB/topics/vehicle_rates_setpoint.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/vehicle_status.h>
|
2018-01-30 18:04:37 +01:00
|
|
|
#include <uORB/topics/vehicle_status_flags.h>
|
2016-04-22 21:45:34 -04:00
|
|
|
#include <uORB/topics/vtol_vehicle_status.h>
|
2016-06-27 10:16:24 -04:00
|
|
|
#include <uORB/topics/wind_estimate.h>
|
2016-11-28 18:48:09 +01:00
|
|
|
#include <uORB/topics/mount_orientation.h>
|
2016-11-16 18:45:07 +01:00
|
|
|
#include <uORB/topics/collision_report.h>
|
2018-01-05 11:41:26 +01:00
|
|
|
#include <uORB/topics/sensor_accel.h>
|
|
|
|
|
#include <uORB/topics/sensor_gyro.h>
|
2018-02-18 11:44:21 -05:00
|
|
|
#include <uORB/topics/vehicle_air_data.h>
|
|
|
|
|
#include <uORB/topics/vehicle_magnetometer.h>
|
2016-06-27 10:16:24 -04:00
|
|
|
#include <uORB/uORB.h>
|
2015-12-07 13:30:38 -08:00
|
|
|
|
2014-02-27 13:54:55 +04:00
|
|
|
static uint16_t cm_uint16_from_m_float(float m);
|
2018-04-10 14:42:30 +02:00
|
|
|
|
2018-04-10 09:57:03 +02:00
|
|
|
static void get_mavlink_mode_state(const struct vehicle_status_s *const status, uint8_t *mavlink_state,
|
2016-08-26 23:43:33 +02:00
|
|
|
uint8_t *mavlink_base_mode, uint32_t *mavlink_custom_mode);
|
2014-02-27 13:54:55 +04:00
|
|
|
|
2014-02-26 22:47:19 +04:00
|
|
|
uint16_t
|
|
|
|
|
cm_uint16_from_m_float(float m)
|
|
|
|
|
{
|
|
|
|
|
if (m < 0.0f) {
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
} else if (m > 655.35f) {
|
|
|
|
|
return 65535;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (uint16_t)(m * 100.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 09:57:03 +02:00
|
|
|
void get_mavlink_navigation_mode(const struct vehicle_status_s *const status, uint8_t *mavlink_base_mode,
|
|
|
|
|
union px4_custom_mode *custom_mode)
|
2014-02-27 13:54:55 +04:00
|
|
|
{
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->data = 0;
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_base_mode = 0;
|
|
|
|
|
|
|
|
|
|
/* HIL */
|
2015-01-28 07:58:42 +01:00
|
|
|
if (status->hil_state == vehicle_status_s::HIL_STATE_ON) {
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_HIL_ENABLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* arming state */
|
2018-03-27 16:04:17 -04:00
|
|
|
if (status->arming_state == vehicle_status_s::ARMING_STATE_ARMED) {
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* main state */
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
|
|
|
|
|
|
2016-06-14 13:30:59 -04:00
|
|
|
const uint8_t auto_mode_flags = MAV_MODE_FLAG_AUTO_ENABLED
|
2016-08-26 23:43:33 +02:00
|
|
|
| MAV_MODE_FLAG_STABILIZE_ENABLED
|
|
|
|
|
| MAV_MODE_FLAG_GUIDED_ENABLED;
|
2014-03-01 00:16:51 +04:00
|
|
|
|
2016-06-14 13:30:59 -04:00
|
|
|
switch (status->nav_state) {
|
2016-08-26 23:43:33 +02:00
|
|
|
case vehicle_status_s::NAVIGATION_STATE_MANUAL:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED
|
|
|
|
|
| (status->is_rotary_wing ? MAV_MODE_FLAG_STABILIZE_ENABLED : 0);
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_MANUAL;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_ACRO:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_ACRO;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_RATTITUDE:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_RATTITUDE;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_STAB:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED
|
|
|
|
|
| MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_STABILIZED;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_ALTCTL:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED
|
|
|
|
|
| MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_ALTCTL;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_POSCTL:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED
|
|
|
|
|
| MAV_MODE_FLAG_STABILIZE_ENABLED
|
|
|
|
|
| MAV_MODE_FLAG_GUIDED_ENABLED; // TODO: is POSCTL GUIDED?
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_POSCTL;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_MISSION;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_LOITER;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
2018-04-07 01:48:04 +03:00
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-04-11 15:49:57 -04:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_PRECLAND;
|
2018-04-07 01:48:04 +03:00
|
|
|
break;
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_RTL:
|
|
|
|
|
|
|
|
|
|
/* fallthrough */
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_RCRECOVER:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_RTL;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_LAND:
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_LANDENGFAIL:
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_LANDGPSFAIL:
|
|
|
|
|
|
|
|
|
|
/* fallthrough */
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_DESCEND:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_LAND;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_AUTO_RTGS:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
|
|
|
|
|
custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_RTGS;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_TERMINATION:
|
|
|
|
|
*mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_MANUAL;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_OFFBOARD:
|
|
|
|
|
*mavlink_base_mode |= auto_mode_flags;
|
2018-02-09 14:34:19 +01:00
|
|
|
custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_OFFBOARD;
|
2016-08-26 23:43:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vehicle_status_s::NAVIGATION_STATE_MAX:
|
|
|
|
|
/* this is an unused case, ignore */
|
|
|
|
|
break;
|
2014-07-12 18:42:25 +02:00
|
|
|
|
2014-02-27 13:54:55 +04:00
|
|
|
}
|
2018-02-09 14:34:19 +01:00
|
|
|
}
|
2014-02-27 13:54:55 +04:00
|
|
|
|
2018-04-10 09:57:03 +02:00
|
|
|
void get_mavlink_mode_state(const struct vehicle_status_s *const status, uint8_t *mavlink_state,
|
2018-02-09 14:34:19 +01:00
|
|
|
uint8_t *mavlink_base_mode, uint32_t *mavlink_custom_mode)
|
|
|
|
|
{
|
|
|
|
|
*mavlink_state = 0;
|
|
|
|
|
*mavlink_base_mode = 0;
|
|
|
|
|
*mavlink_custom_mode = 0;
|
|
|
|
|
|
|
|
|
|
union px4_custom_mode custom_mode;
|
2018-04-10 09:57:03 +02:00
|
|
|
get_mavlink_navigation_mode(status, mavlink_base_mode, &custom_mode);
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_custom_mode = custom_mode.data;
|
|
|
|
|
|
|
|
|
|
/* set system state */
|
2015-01-28 07:58:42 +01:00
|
|
|
if (status->arming_state == vehicle_status_s::ARMING_STATE_INIT
|
|
|
|
|
|| status->arming_state == vehicle_status_s::ARMING_STATE_IN_AIR_RESTORE
|
|
|
|
|
|| status->arming_state == vehicle_status_s::ARMING_STATE_STANDBY_ERROR) { // TODO review
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_state = MAV_STATE_UNINIT;
|
2014-03-01 00:16:51 +04:00
|
|
|
|
2015-01-28 07:58:42 +01:00
|
|
|
} else if (status->arming_state == vehicle_status_s::ARMING_STATE_ARMED) {
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_state = MAV_STATE_ACTIVE;
|
2014-03-01 00:16:51 +04:00
|
|
|
|
2015-01-28 07:58:42 +01:00
|
|
|
} else if (status->arming_state == vehicle_status_s::ARMING_STATE_STANDBY) {
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_state = MAV_STATE_STANDBY;
|
2014-03-01 00:16:51 +04:00
|
|
|
|
2015-01-28 07:58:42 +01:00
|
|
|
} else if (status->arming_state == vehicle_status_s::ARMING_STATE_REBOOT) {
|
2014-02-27 13:54:55 +04:00
|
|
|
*mavlink_state = MAV_STATE_POWEROFF;
|
2014-03-01 00:16:51 +04:00
|
|
|
|
2014-02-27 13:54:55 +04:00
|
|
|
} else {
|
|
|
|
|
*mavlink_state = MAV_STATE_CRITICAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-03-01 00:16:51 +04:00
|
|
|
class MavlinkStreamHeartbeat : public MavlinkStream
|
|
|
|
|
{
|
2014-02-26 21:28:35 +04:00
|
|
|
public:
|
2014-05-13 16:04:02 +02:00
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamHeartbeat::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
2014-02-26 21:28:35 +04:00
|
|
|
{
|
|
|
|
|
return "HEARTBEAT";
|
|
|
|
|
}
|
2013-09-21 10:17:00 +02:00
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-04-07 22:36:28 +04:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HEARTBEAT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-20 20:34:32 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
2014-02-26 21:28:35 +04:00
|
|
|
{
|
2014-07-20 20:34:32 +02:00
|
|
|
return new MavlinkStreamHeartbeat(mavlink);
|
2014-02-26 21:28:35 +04:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 11:11:49 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HEARTBEAT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
bool const_rate()
|
|
|
|
|
{
|
2014-07-23 11:11:49 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-26 21:28:35 +04:00
|
|
|
private:
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_status_sub;
|
2014-02-26 21:28:35 +04:00
|
|
|
|
2014-07-16 23:41:13 -04:00
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamHeartbeat(MavlinkStreamHeartbeat &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamHeartbeat &operator = (const MavlinkStreamHeartbeat &);
|
2014-07-16 23:41:13 -04:00
|
|
|
|
2014-02-26 21:28:35 +04:00
|
|
|
protected:
|
2014-07-20 20:34:32 +02:00
|
|
|
explicit MavlinkStreamHeartbeat(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2016-06-10 10:33:56 -04:00
|
|
|
_status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status)))
|
2014-07-16 23:41:13 -04:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-03-01 00:16:51 +04:00
|
|
|
{
|
2017-02-17 12:36:52 -05:00
|
|
|
struct vehicle_status_s status = {};
|
2014-05-13 16:04:02 +02:00
|
|
|
|
2014-06-26 12:54:33 +02:00
|
|
|
/* always send the heartbeat, independent of the update status of the topics */
|
2014-07-23 23:10:10 +02:00
|
|
|
if (!_status_sub->update(&status)) {
|
2014-06-26 22:41:35 +02:00
|
|
|
/* if topic update failed fill it with defaults */
|
|
|
|
|
memset(&status, 0, sizeof(status));
|
2014-06-26 22:37:11 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-13 14:53:47 +02:00
|
|
|
uint8_t base_mode = 0;
|
|
|
|
|
uint32_t custom_mode = 0;
|
|
|
|
|
uint8_t system_status = 0;
|
2016-06-10 10:33:56 -04:00
|
|
|
get_mavlink_mode_state(&status, &system_status, &base_mode, &custom_mode);
|
2014-07-23 11:11:49 +02:00
|
|
|
|
2016-05-13 14:53:47 +02:00
|
|
|
mavlink_msg_heartbeat_send(_mavlink->get_channel(), _mavlink->get_system_type(), MAV_AUTOPILOT_PX4,
|
2016-08-26 23:43:33 +02:00
|
|
|
base_mode, custom_mode, system_status);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2013-11-13 22:30:39 +04:00
|
|
|
}
|
2014-02-26 21:28:35 +04:00
|
|
|
};
|
|
|
|
|
|
2014-07-24 12:10:21 +02:00
|
|
|
class MavlinkStreamStatustext : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamStatustext::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "STATUSTEXT";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-24 12:10:21 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_STATUSTEXT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-24 12:10:21 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamStatustext(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-03-15 18:21:52 +00:00
|
|
|
return _mavlink->get_logbuffer()->empty() ? 0 : (MAVLINK_MSG_ID_STATUSTEXT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES);
|
2014-07-24 12:10:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamStatustext(MavlinkStreamStatustext &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamStatustext &operator = (const MavlinkStreamStatustext &);
|
2016-03-15 18:21:52 +00:00
|
|
|
|
2014-07-24 12:10:21 +02:00
|
|
|
protected:
|
2016-04-25 15:35:22 +02:00
|
|
|
explicit MavlinkStreamStatustext(Mavlink *mavlink) : MavlinkStream(mavlink)
|
2014-07-24 12:10:21 +02:00
|
|
|
{}
|
|
|
|
|
|
2018-05-18 00:10:13 -04:00
|
|
|
~MavlinkStreamStatustext() = default;
|
2016-03-22 19:25:46 +01:00
|
|
|
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-24 12:10:21 +02:00
|
|
|
{
|
2017-07-09 13:52:50 +02:00
|
|
|
if (!_mavlink->get_logbuffer()->empty() && _mavlink->is_connected()) {
|
2014-07-24 12:10:21 +02:00
|
|
|
|
2017-02-17 12:36:52 -05:00
|
|
|
struct mavlink_log_s mavlink_log = {};
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2016-03-22 19:25:46 +01:00
|
|
|
if (_mavlink->get_logbuffer()->get(&mavlink_log)) {
|
2014-07-24 12:10:21 +02:00
|
|
|
|
2017-05-06 12:38:28 +02:00
|
|
|
mavlink_statustext_t msg;
|
2016-03-22 19:25:46 +01:00
|
|
|
msg.severity = mavlink_log.severity;
|
|
|
|
|
strncpy(msg.text, (const char *)mavlink_log.text, sizeof(msg.text));
|
2016-04-17 20:03:48 +02:00
|
|
|
msg.text[sizeof(msg.text) - 1] = '\0';
|
2014-07-24 12:10:21 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_statustext_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-24 12:10:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2016-03-15 18:21:52 +00:00
|
|
|
}
|
2014-07-24 12:10:21 +02:00
|
|
|
};
|
|
|
|
|
|
2014-07-23 15:37:56 +02:00
|
|
|
class MavlinkStreamCommandLong : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamCommandLong::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "COMMAND_LONG";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-23 15:37:56 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_COMMAND_LONG;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-23 15:37:56 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamCommandLong(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-07-24 12:10:21 +02:00
|
|
|
return 0; // commands stream is not regular and not predictable
|
|
|
|
|
}
|
2014-07-23 15:37:56 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_cmd_sub;
|
|
|
|
|
uint64_t _cmd_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamCommandLong(MavlinkStreamCommandLong &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamCommandLong &operator = (const MavlinkStreamCommandLong &);
|
2014-07-23 15:37:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamCommandLong(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-23 23:10:10 +02:00
|
|
|
_cmd_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_command))),
|
2014-07-23 15:37:56 +02:00
|
|
|
_cmd_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-23 15:37:56 +02:00
|
|
|
{
|
2017-05-06 12:38:28 +02:00
|
|
|
struct vehicle_command_s cmd;
|
2017-07-23 18:28:02 +02:00
|
|
|
bool sent = false;
|
2014-07-23 15:37:56 +02:00
|
|
|
|
2017-07-13 16:37:28 -07:00
|
|
|
if (_cmd_sub->update_if_changed(&cmd)) {
|
2017-07-05 16:13:42 +02:00
|
|
|
|
2017-07-13 15:11:51 -07:00
|
|
|
if (!cmd.from_external) {
|
2018-01-13 18:52:00 +01:00
|
|
|
PX4_DEBUG("sending command %d to %d/%d", cmd.command, cmd.target_system, cmd.target_component);
|
2017-07-08 19:36:00 +02:00
|
|
|
|
2017-07-06 09:05:22 +02:00
|
|
|
MavlinkCommandSender::instance().handle_vehicle_command(cmd, _mavlink->get_channel());
|
2017-07-23 18:28:02 +02:00
|
|
|
sent = true;
|
2017-07-06 09:05:22 +02:00
|
|
|
|
|
|
|
|
} else {
|
2018-01-13 18:52:00 +01:00
|
|
|
PX4_DEBUG("not forwarding command %d to %d/%d", cmd.command, cmd.target_system, cmd.target_component);
|
2017-07-06 09:05:22 +02:00
|
|
|
}
|
2014-07-23 15:37:56 +02:00
|
|
|
}
|
2017-07-05 16:13:42 +02:00
|
|
|
|
|
|
|
|
MavlinkCommandSender::instance().check_timeout(_mavlink->get_channel());
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return sent;
|
2014-07-23 15:37:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
2014-02-26 21:28:35 +04:00
|
|
|
|
2014-03-01 00:16:51 +04:00
|
|
|
class MavlinkStreamSysStatus : public MavlinkStream
|
|
|
|
|
{
|
2014-02-26 21:28:35 +04:00
|
|
|
public:
|
2014-05-13 16:04:02 +02:00
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamSysStatus::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 11:11:49 +02:00
|
|
|
static const char *get_name_static()
|
2014-02-26 21:28:35 +04:00
|
|
|
{
|
|
|
|
|
return "SYS_STATUS";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-04-07 22:36:28 +04:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_SYS_STATUS;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-23 11:11:49 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamSysStatus(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
2014-02-26 21:28:35 +04:00
|
|
|
{
|
2014-07-23 11:11:49 +02:00
|
|
|
return MAVLINK_MSG_ID_SYS_STATUS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
2014-02-26 21:28:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_status_sub;
|
2016-05-04 08:22:00 +02:00
|
|
|
MavlinkOrbSubscription *_cpuload_sub;
|
2016-02-24 18:08:56 +00:00
|
|
|
MavlinkOrbSubscription *_battery_status_sub;
|
2014-02-26 21:28:35 +04:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _status_timestamp{0};
|
|
|
|
|
uint64_t _cpuload_timestamp{0};
|
|
|
|
|
uint64_t _battery_status_timestamp{0};
|
|
|
|
|
|
2014-07-16 23:41:13 -04:00
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamSysStatus(MavlinkStreamSysStatus &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamSysStatus &operator = (const MavlinkStreamSysStatus &);
|
2014-07-16 23:41:13 -04:00
|
|
|
|
2014-02-26 21:28:35 +04:00
|
|
|
protected:
|
2014-07-23 11:11:49 +02:00
|
|
|
explicit MavlinkStreamSysStatus(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2016-02-24 18:08:56 +00:00
|
|
|
_status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))),
|
2016-02-26 18:14:24 -08:00
|
|
|
_cpuload_sub(_mavlink->add_orb_subscription(ORB_ID(cpuload))),
|
2016-02-24 18:08:56 +00:00
|
|
|
_battery_status_sub(_mavlink->add_orb_subscription(ORB_ID(battery_status)))
|
2014-07-16 23:41:13 -04:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-03-01 00:16:51 +04:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_status_s status = {};
|
|
|
|
|
cpuload_s cpuload = {};
|
|
|
|
|
battery_status_s battery_status = {};
|
2016-02-24 18:08:56 +00:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
const bool updated_status = _status_sub->update(&_status_timestamp, &status);
|
|
|
|
|
const bool updated_cpuload = _cpuload_sub->update(&_cpuload_timestamp, &cpuload);
|
|
|
|
|
const bool updated_battery = _battery_status_sub->update(&_battery_status_timestamp, &battery_status);
|
2014-06-11 14:00:44 +02:00
|
|
|
|
2016-02-26 18:14:24 -08:00
|
|
|
if (updated_status || updated_battery || updated_cpuload) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_sys_status_t msg = {};
|
2014-07-23 11:11:49 +02:00
|
|
|
|
|
|
|
|
msg.onboard_control_sensors_present = status.onboard_control_sensors_present;
|
|
|
|
|
msg.onboard_control_sensors_enabled = status.onboard_control_sensors_enabled;
|
|
|
|
|
msg.onboard_control_sensors_health = status.onboard_control_sensors_health;
|
2016-02-26 18:14:24 -08:00
|
|
|
msg.load = cpuload.load * 1000.0f;
|
2016-05-15 15:38:01 +02:00
|
|
|
msg.voltage_battery = (battery_status.connected) ? battery_status.voltage_filtered_v * 1000.0f : UINT16_MAX;
|
|
|
|
|
msg.current_battery = (battery_status.connected) ? battery_status.current_filtered_a * 100.0f : -1;
|
2018-03-01 09:07:55 +01:00
|
|
|
msg.battery_remaining = (battery_status.connected) ? ceilf(battery_status.remaining * 100.0f) : -1;
|
2016-02-24 10:10:50 +00:00
|
|
|
// TODO: fill in something useful in the fields below
|
|
|
|
|
msg.drop_rate_comm = 0;
|
|
|
|
|
msg.errors_comm = 0;
|
|
|
|
|
msg.errors_count1 = 0;
|
|
|
|
|
msg.errors_count2 = 0;
|
|
|
|
|
msg.errors_count3 = 0;
|
|
|
|
|
msg.errors_count4 = 0;
|
2014-07-23 11:11:49 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_sys_status_send_struct(_mavlink->get_channel(), &msg);
|
2015-05-17 17:44:32 +02:00
|
|
|
|
|
|
|
|
/* battery status message with higher resolution */
|
2016-04-23 14:24:36 +02:00
|
|
|
mavlink_battery_status_t bat_msg = {};
|
2015-05-17 17:44:32 +02:00
|
|
|
bat_msg.id = 0;
|
|
|
|
|
bat_msg.battery_function = MAV_BATTERY_FUNCTION_ALL;
|
|
|
|
|
bat_msg.type = MAV_BATTERY_TYPE_LIPO;
|
2016-05-15 15:38:01 +02:00
|
|
|
bat_msg.current_consumed = (battery_status.connected) ? battery_status.discharged_mah : -1;
|
2016-04-23 14:24:36 +02:00
|
|
|
bat_msg.energy_consumed = -1;
|
2016-05-15 15:38:01 +02:00
|
|
|
bat_msg.current_battery = (battery_status.connected) ? battery_status.current_filtered_a * 100 : -1;
|
2018-03-01 09:07:55 +01:00
|
|
|
bat_msg.battery_remaining = (battery_status.connected) ? ceilf(battery_status.remaining * 100.0f) : -1;
|
2018-03-06 02:42:20 -07:00
|
|
|
bat_msg.temperature = (battery_status.connected) ? (int16_t)battery_status.temperature : INT16_MAX;
|
|
|
|
|
//bat_msg.average_current_battery = (battery_status.connected) ? battery_status.average_current_a * 100.0f : -1;
|
|
|
|
|
//bat_msg.serial_number = (battery_status.connected) ? battery_status.serial_number : 0;
|
|
|
|
|
//bat_msg.capacity = (battery_status.connected) ? battery_status.capacity : 0;
|
|
|
|
|
//bat_msg.cycle_count = (battery_status.connected) ? battery_status.cycle_count : UINT16_MAX;
|
|
|
|
|
//bat_msg.run_time_to_empty = (battery_status.connected) ? battery_status.run_time_to_empty * 60 : 0;
|
|
|
|
|
//bat_msg.average_time_to_empty = (battery_status.connected) ? battery_status.average_time_to_empty * 60 : 0;
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2016-02-27 21:09:46 -05:00
|
|
|
for (unsigned int i = 0; i < (sizeof(bat_msg.voltages) / sizeof(bat_msg.voltages[0])); i++) {
|
2016-05-15 15:38:01 +02:00
|
|
|
if ((int)i < battery_status.cell_count && battery_status.connected) {
|
2016-02-24 18:08:56 +00:00
|
|
|
bat_msg.voltages[i] = (battery_status.voltage_v / battery_status.cell_count) * 1000.0f;
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2015-05-17 17:44:32 +02:00
|
|
|
} else {
|
2015-10-11 11:35:46 +02:00
|
|
|
bat_msg.voltages[i] = UINT16_MAX;
|
2015-05-17 17:44:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-11 11:35:46 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_battery_status_send_struct(_mavlink->get_channel(), &bat_msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-03-16 13:48:33 +01:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-02-26 22:47:19 +04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-07-23 22:40:55 +02:00
|
|
|
class MavlinkStreamHighresIMU : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamHighresIMU::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "HIGHRES_IMU";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-23 22:40:55 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HIGHRES_IMU;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-23 22:40:55 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamHighresIMU(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HIGHRES_IMU_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_sensor_sub;
|
|
|
|
|
uint64_t _sensor_time;
|
2014-07-23 22:40:55 +02:00
|
|
|
|
2017-09-21 16:24:53 -04:00
|
|
|
MavlinkOrbSubscription *_bias_sub;
|
2016-06-21 14:12:13 +02:00
|
|
|
MavlinkOrbSubscription *_differential_pressure_sub;
|
2018-02-18 11:44:21 -05:00
|
|
|
MavlinkOrbSubscription *_magnetometer_sub;
|
|
|
|
|
MavlinkOrbSubscription *_air_data_sub;
|
2016-06-21 14:12:13 +02:00
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
uint64_t _accel_timestamp;
|
|
|
|
|
uint64_t _gyro_timestamp;
|
|
|
|
|
uint64_t _mag_timestamp;
|
|
|
|
|
uint64_t _baro_timestamp;
|
2018-04-16 17:43:52 +02:00
|
|
|
uint64_t _dpres_timestamp;
|
2014-07-23 22:40:55 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamHighresIMU(MavlinkStreamHighresIMU &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamHighresIMU &operator = (const MavlinkStreamHighresIMU &);
|
2014-07-23 22:40:55 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamHighresIMU(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-23 23:10:10 +02:00
|
|
|
_sensor_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_combined))),
|
|
|
|
|
_sensor_time(0),
|
2017-09-21 16:24:53 -04:00
|
|
|
_bias_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_bias))),
|
2016-06-21 14:12:13 +02:00
|
|
|
_differential_pressure_sub(_mavlink->add_orb_subscription(ORB_ID(differential_pressure))),
|
2018-02-18 11:44:21 -05:00
|
|
|
_magnetometer_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_magnetometer))),
|
|
|
|
|
_air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data))),
|
2014-07-23 23:10:10 +02:00
|
|
|
_accel_timestamp(0),
|
|
|
|
|
_gyro_timestamp(0),
|
|
|
|
|
_mag_timestamp(0),
|
2018-04-16 17:43:52 +02:00
|
|
|
_baro_timestamp(0),
|
|
|
|
|
_dpres_timestamp(0)
|
2014-07-23 22:40:55 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-23 22:40:55 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
sensor_combined_s sensor;
|
2014-07-23 22:40:55 +02:00
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
if (_sensor_sub->update(&_sensor_time, &sensor)) {
|
2014-07-23 22:40:55 +02:00
|
|
|
uint16_t fields_updated = 0;
|
|
|
|
|
|
2016-06-25 15:57:03 +02:00
|
|
|
if (_accel_timestamp != sensor.timestamp + sensor.accelerometer_timestamp_relative) {
|
2014-07-23 22:40:55 +02:00
|
|
|
/* mark first three dimensions as changed */
|
|
|
|
|
fields_updated |= (1 << 0) | (1 << 1) | (1 << 2);
|
2016-06-25 15:57:03 +02:00
|
|
|
_accel_timestamp = sensor.timestamp + sensor.accelerometer_timestamp_relative;
|
2014-07-23 22:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-25 12:28:02 +02:00
|
|
|
if (_gyro_timestamp != sensor.timestamp) {
|
2014-07-23 22:40:55 +02:00
|
|
|
/* mark second group dimensions as changed */
|
|
|
|
|
fields_updated |= (1 << 3) | (1 << 4) | (1 << 5);
|
2016-06-25 12:28:02 +02:00
|
|
|
_gyro_timestamp = sensor.timestamp;
|
2014-07-23 22:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
vehicle_magnetometer_s magnetometer = {};
|
|
|
|
|
_magnetometer_sub->update(&magnetometer);
|
|
|
|
|
|
|
|
|
|
if (_mag_timestamp != magnetometer.timestamp) {
|
2014-07-23 22:40:55 +02:00
|
|
|
/* mark third group dimensions as changed */
|
|
|
|
|
fields_updated |= (1 << 6) | (1 << 7) | (1 << 8);
|
2018-02-18 11:44:21 -05:00
|
|
|
_mag_timestamp = magnetometer.timestamp;
|
2014-07-23 22:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
vehicle_air_data_s air_data = {};
|
|
|
|
|
_air_data_sub->update(&air_data);
|
|
|
|
|
|
|
|
|
|
if (_baro_timestamp != air_data.timestamp) {
|
2018-04-16 17:43:52 +02:00
|
|
|
/* mark fourth group (baro fields) dimensions as changed */
|
2014-07-23 22:40:55 +02:00
|
|
|
fields_updated |= (1 << 9) | (1 << 11) | (1 << 12);
|
2018-02-18 11:44:21 -05:00
|
|
|
_baro_timestamp = air_data.timestamp;
|
2014-07-23 22:40:55 +02:00
|
|
|
}
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
sensor_bias_s bias = {};
|
|
|
|
|
_bias_sub->update(&bias);
|
2018-02-18 11:44:21 -05:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
differential_pressure_s differential_pressure = {};
|
|
|
|
|
_differential_pressure_sub->update(&differential_pressure);
|
2014-07-23 22:40:55 +02:00
|
|
|
|
2018-04-16 17:43:52 +02:00
|
|
|
if (_dpres_timestamp != differential_pressure.timestamp) {
|
|
|
|
|
/* mark fourth group (dpres field) dimensions as changed */
|
|
|
|
|
fields_updated |= (1 << 10);
|
|
|
|
|
_dpres_timestamp = differential_pressure.timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_highres_imu_t msg = {};
|
2014-07-23 22:40:55 +02:00
|
|
|
|
|
|
|
|
msg.time_usec = sensor.timestamp;
|
2017-09-21 16:24:53 -04:00
|
|
|
msg.xacc = sensor.accelerometer_m_s2[0] - bias.accel_x_bias;
|
|
|
|
|
msg.yacc = sensor.accelerometer_m_s2[1] - bias.accel_y_bias;
|
|
|
|
|
msg.zacc = sensor.accelerometer_m_s2[2] - bias.accel_z_bias;
|
|
|
|
|
msg.xgyro = sensor.gyro_rad[0] - bias.gyro_x_bias;
|
|
|
|
|
msg.ygyro = sensor.gyro_rad[1] - bias.gyro_y_bias;
|
|
|
|
|
msg.zgyro = sensor.gyro_rad[2] - bias.gyro_z_bias;
|
2018-02-18 11:44:21 -05:00
|
|
|
msg.xmag = magnetometer.magnetometer_ga[0] - bias.mag_x_bias;
|
|
|
|
|
msg.ymag = magnetometer.magnetometer_ga[1] - bias.mag_y_bias;
|
|
|
|
|
msg.zmag = magnetometer.magnetometer_ga[2] - bias.mag_z_bias;
|
|
|
|
|
msg.abs_pressure = air_data.baro_pressure_pa;
|
2016-06-21 14:12:13 +02:00
|
|
|
msg.diff_pressure = differential_pressure.differential_pressure_raw_pa;
|
2018-02-18 11:44:21 -05:00
|
|
|
msg.pressure_alt = air_data.baro_alt_meter;
|
|
|
|
|
msg.temperature = air_data.baro_temp_celcius;
|
2014-07-23 22:40:55 +02:00
|
|
|
msg.fields_updated = fields_updated;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_highres_imu_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-23 22:40:55 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-23 22:40:55 +02:00
|
|
|
}
|
|
|
|
|
};
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
|
2018-01-05 11:41:26 +01:00
|
|
|
// TEMP This is temporary for the Snapdragon Flight and VISLAM to get unfiltered IMU data
|
|
|
|
|
class MavlinkStreamScaledIMU : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamScaledIMU::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "SCALED_IMU";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_SCALED_IMU;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamScaledIMU(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return _raw_accel_sub->is_published() ? (MAVLINK_MSG_ID_SCALED_IMU_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_raw_accel_sub;
|
|
|
|
|
MavlinkOrbSubscription *_raw_gyro_sub;
|
|
|
|
|
uint64_t _raw_accel_time;
|
|
|
|
|
uint64_t _raw_gyro_time;
|
|
|
|
|
|
|
|
|
|
// do not allow top copy this class
|
|
|
|
|
MavlinkStreamScaledIMU(MavlinkStreamScaledIMU &);
|
|
|
|
|
MavlinkStreamScaledIMU &operator = (const MavlinkStreamScaledIMU &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamScaledIMU(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_raw_accel_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel))),
|
|
|
|
|
_raw_gyro_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_gyro))),
|
|
|
|
|
_raw_accel_time(0),
|
2018-03-25 14:21:09 -04:00
|
|
|
_raw_gyro_time(0)
|
2018-01-05 11:41:26 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool send(const hrt_abstime t)
|
|
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
sensor_accel_s sensor_accel = {};
|
|
|
|
|
sensor_accel_s sensor_gyro = {};
|
2018-01-05 11:41:26 +01:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
bool updated = false;
|
|
|
|
|
updated |= _raw_accel_sub->update(&_raw_accel_time, &sensor_accel);
|
|
|
|
|
updated |= _raw_gyro_sub->update(&_raw_gyro_time, &sensor_gyro);
|
2018-01-05 11:41:26 +01:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
if (updated) {
|
2018-01-05 11:41:26 +01:00
|
|
|
|
|
|
|
|
mavlink_scaled_imu_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.time_boot_ms = sensor_accel.timestamp / 1000;
|
|
|
|
|
msg.xacc = (int16_t)(sensor_accel.x_raw / CONSTANTS_ONE_G); // [milli g]
|
|
|
|
|
msg.yacc = (int16_t)(sensor_accel.y_raw / CONSTANTS_ONE_G); // [milli g]
|
|
|
|
|
msg.zacc = (int16_t)(sensor_accel.z_raw / CONSTANTS_ONE_G); // [milli g]
|
2018-03-25 14:21:09 -04:00
|
|
|
msg.xgyro = sensor_gyro.x_raw; // [milli rad/s]
|
|
|
|
|
msg.ygyro = sensor_gyro.y_raw; // [milli rad/s]
|
|
|
|
|
msg.zgyro = sensor_gyro.z_raw; // [milli rad/s]
|
2018-01-05 11:41:26 +01:00
|
|
|
msg.xmag = 0;
|
|
|
|
|
msg.ymag = 0;
|
|
|
|
|
msg.zmag = 0;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_scaled_imu_send_struct(_mavlink->get_channel(), &msg);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-07-23 22:54:48 +02:00
|
|
|
class MavlinkStreamAttitude : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamAttitude::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "ATTITUDE";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-23 22:54:48 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ATTITUDE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-23 22:54:48 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamAttitude(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ATTITUDE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_att_sub;
|
|
|
|
|
uint64_t _att_time;
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamAttitude(MavlinkStreamAttitude &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamAttitude &operator = (const MavlinkStreamAttitude &);
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamAttitude(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-23 23:10:10 +02:00
|
|
|
_att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude))),
|
|
|
|
|
_att_time(0)
|
2014-07-23 22:54:48 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-23 22:54:48 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_attitude_s att;
|
2014-07-23 22:54:48 +02:00
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
if (_att_sub->update(&_att_time, &att)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_attitude_t msg = {};
|
2016-09-27 22:18:18 +02:00
|
|
|
matrix::Eulerf euler = matrix::Quatf(att.q);
|
2014-07-23 22:54:48 +02:00
|
|
|
msg.time_boot_ms = att.timestamp / 1000;
|
2016-09-27 22:18:18 +02:00
|
|
|
msg.roll = euler.phi();
|
|
|
|
|
msg.pitch = euler.theta();
|
|
|
|
|
msg.yaw = euler.psi();
|
2014-07-23 22:54:48 +02:00
|
|
|
msg.rollspeed = att.rollspeed;
|
|
|
|
|
msg.pitchspeed = att.pitchspeed;
|
|
|
|
|
msg.yawspeed = att.yawspeed;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_attitude_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-23 22:54:48 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-23 22:54:48 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamAttitudeQuaternion : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamAttitudeQuaternion::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "ATTITUDE_QUATERNION";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-23 22:54:48 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ATTITUDE_QUATERNION;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-23 22:54:48 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamAttitudeQuaternion(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ATTITUDE_QUATERNION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_att_sub;
|
|
|
|
|
uint64_t _att_time;
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamAttitudeQuaternion(MavlinkStreamAttitudeQuaternion &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamAttitudeQuaternion &operator = (const MavlinkStreamAttitudeQuaternion &);
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamAttitudeQuaternion(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-23 23:10:10 +02:00
|
|
|
_att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude))),
|
|
|
|
|
_att_time(0)
|
2014-07-23 22:54:48 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-23 22:54:48 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_attitude_s att;
|
2014-07-23 22:54:48 +02:00
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
if (_att_sub->update(&_att_time, &att)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_attitude_quaternion_t msg = {};
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
msg.time_boot_ms = att.timestamp / 1000;
|
|
|
|
|
msg.q1 = att.q[0];
|
|
|
|
|
msg.q2 = att.q[1];
|
|
|
|
|
msg.q3 = att.q[2];
|
|
|
|
|
msg.q4 = att.q[3];
|
|
|
|
|
msg.rollspeed = att.rollspeed;
|
|
|
|
|
msg.pitchspeed = att.pitchspeed;
|
|
|
|
|
msg.yawspeed = att.yawspeed;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_attitude_quaternion_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-23 22:54:48 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-23 22:54:48 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamVFRHUD : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamVFRHUD::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "VFR_HUD";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-23 22:54:48 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_VFR_HUD;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-23 22:54:48 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamVFRHUD(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_VFR_HUD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_att_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _att_time;
|
|
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_pos_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _pos_time;
|
|
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_armed_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _armed_time;
|
|
|
|
|
|
2017-04-22 16:08:27 -04:00
|
|
|
MavlinkOrbSubscription *_act0_sub;
|
|
|
|
|
MavlinkOrbSubscription *_act1_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
|
2014-07-23 23:10:10 +02:00
|
|
|
MavlinkOrbSubscription *_airspeed_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _airspeed_time;
|
|
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
MavlinkOrbSubscription *_air_data_sub;
|
2016-01-17 16:30:02 +01:00
|
|
|
|
2014-07-23 22:54:48 +02:00
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamVFRHUD(MavlinkStreamVFRHUD &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamVFRHUD &operator = (const MavlinkStreamVFRHUD &);
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamVFRHUD(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-23 23:10:10 +02:00
|
|
|
_att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_att_time(0),
|
2018-03-25 13:01:34 -04:00
|
|
|
_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_pos_time(0),
|
2014-07-23 23:10:10 +02:00
|
|
|
_armed_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_armed))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_armed_time(0),
|
2017-04-22 16:08:27 -04:00
|
|
|
_act0_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_controls_0))),
|
|
|
|
|
_act1_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_controls_1))),
|
2014-07-23 23:10:10 +02:00
|
|
|
_airspeed_sub(_mavlink->add_orb_subscription(ORB_ID(airspeed))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_airspeed_time(0),
|
2018-02-18 11:44:21 -05:00
|
|
|
_air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data)))
|
2014-07-23 22:54:48 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-23 22:54:48 +02:00
|
|
|
{
|
2018-03-25 13:01:34 -04:00
|
|
|
vehicle_attitude_s att = {};
|
|
|
|
|
vehicle_local_position_s pos = {};
|
|
|
|
|
actuator_armed_s armed = {};
|
|
|
|
|
airspeed_s airspeed = {};
|
2014-07-23 22:54:48 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
|
|
|
|
|
bool updated = false;
|
|
|
|
|
updated |= _att_sub->update(&_att_time, &att);
|
|
|
|
|
updated |= _pos_sub->update(&_pos_time, &pos);
|
|
|
|
|
updated |= _armed_sub->update(&_armed_time, &armed);
|
|
|
|
|
updated |= _airspeed_sub->update(&_airspeed_time, &airspeed);
|
2014-07-23 22:54:48 +02:00
|
|
|
|
|
|
|
|
if (updated) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_vfr_hud_t msg = {};
|
2016-09-27 22:18:18 +02:00
|
|
|
matrix::Eulerf euler = matrix::Quatf(att.q);
|
2015-12-10 10:27:46 -05:00
|
|
|
msg.airspeed = airspeed.indicated_airspeed_m_s;
|
2018-03-25 13:01:34 -04:00
|
|
|
msg.groundspeed = sqrtf(pos.vx * pos.vx + pos.vy * pos.vy);
|
2016-09-27 22:18:18 +02:00
|
|
|
msg.heading = _wrap_2pi(euler.psi()) * M_RAD_TO_DEG_F;
|
2017-04-22 16:08:27 -04:00
|
|
|
|
|
|
|
|
if (armed.armed) {
|
2018-03-25 13:01:34 -04:00
|
|
|
actuator_controls_s act0 = {};
|
|
|
|
|
actuator_controls_s act1 = {};
|
|
|
|
|
_act0_sub->update(&act0);
|
|
|
|
|
_act1_sub->update(&act1);
|
|
|
|
|
|
2017-04-22 16:08:27 -04:00
|
|
|
// VFR_HUD throttle should only be used for operator feedback.
|
|
|
|
|
// VTOLs switch between actuator_controls_0 and actuator_controls_1. During transition there isn't a
|
|
|
|
|
// a single throttle value, but this should still be a useful heuristic for operator awareness.
|
|
|
|
|
//
|
|
|
|
|
// Use ACTUATOR_CONTROL_TARGET if accurate states are needed.
|
2018-03-25 13:01:34 -04:00
|
|
|
msg.throttle = 100 * math::max(
|
|
|
|
|
act0.control[actuator_controls_s::INDEX_THROTTLE],
|
|
|
|
|
act1.control[actuator_controls_s::INDEX_THROTTLE]);
|
2017-04-22 16:08:27 -04:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
msg.throttle = 0.0f;
|
|
|
|
|
}
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2018-03-25 13:01:34 -04:00
|
|
|
if (pos.z_valid && pos.z_global) {
|
|
|
|
|
/* use local position estimate */
|
|
|
|
|
msg.alt = -pos.z + pos.ref_alt;
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2016-01-17 16:30:02 +01:00
|
|
|
} else {
|
2018-02-18 11:44:21 -05:00
|
|
|
vehicle_air_data_s air_data = {};
|
|
|
|
|
_air_data_sub->update(&air_data);
|
2018-03-25 14:21:09 -04:00
|
|
|
|
2016-01-17 16:30:02 +01:00
|
|
|
/* fall back to baro altitude */
|
2018-02-18 11:44:21 -05:00
|
|
|
if (air_data.timestamp > 0) {
|
|
|
|
|
msg.alt = air_data.baro_alt_meter;
|
2018-03-25 13:01:34 -04:00
|
|
|
}
|
2016-01-17 16:30:02 +01:00
|
|
|
}
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2018-03-25 13:01:34 -04:00
|
|
|
if (pos.v_z_valid) {
|
|
|
|
|
msg.climb = -pos.vz;
|
|
|
|
|
}
|
2014-07-23 22:54:48 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_vfr_hud_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-23 22:54:48 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-23 22:54:48 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-07-28 00:07:01 +02:00
|
|
|
class MavlinkStreamGPSRawInt : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamGPSRawInt::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "GPS_RAW_INT";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 00:07:01 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_GPS_RAW_INT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 00:07:01 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamGPSRawInt(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_GPS_RAW_INT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_gps_sub;
|
|
|
|
|
uint64_t _gps_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamGPSRawInt(MavlinkStreamGPSRawInt &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamGPSRawInt &operator = (const MavlinkStreamGPSRawInt &);
|
2014-07-28 00:07:01 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamGPSRawInt(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-28 11:02:56 +02:00
|
|
|
_gps_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_gps_position))),
|
2014-07-28 00:07:01 +02:00
|
|
|
_gps_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 00:07:01 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_gps_position_s gps;
|
2014-07-28 00:07:01 +02:00
|
|
|
|
|
|
|
|
if (_gps_sub->update(&_gps_time, &gps)) {
|
2015-10-24 20:27:14 +02:00
|
|
|
mavlink_gps_raw_int_t msg = {};
|
2014-07-28 00:07:01 +02:00
|
|
|
|
2016-06-15 12:59:39 +02:00
|
|
|
msg.time_usec = gps.timestamp;
|
2014-07-28 00:07:01 +02:00
|
|
|
msg.fix_type = gps.fix_type;
|
|
|
|
|
msg.lat = gps.lat;
|
|
|
|
|
msg.lon = gps.lon;
|
|
|
|
|
msg.alt = gps.alt;
|
2017-07-22 23:27:48 +02:00
|
|
|
msg.alt_ellipsoid = gps.alt_ellipsoid;
|
|
|
|
|
msg.eph = gps.hdop * 100;
|
|
|
|
|
msg.epv = gps.vdop * 100;
|
|
|
|
|
msg.h_acc = gps.eph * 1e3f;
|
|
|
|
|
msg.v_acc = gps.epv * 1e3f;
|
|
|
|
|
msg.vel_acc = gps.s_variance_m_s * 1e3f;
|
|
|
|
|
msg.hdg_acc = gps.c_variance_rad * 1e5f / M_DEG_TO_RAD_F;
|
2018-03-25 14:21:09 -04:00
|
|
|
msg.vel = cm_uint16_from_m_float(gps.vel_m_s);
|
|
|
|
|
msg.cog = _wrap_2pi(gps.cog_rad) * M_RAD_TO_DEG_F * 1e2f;
|
|
|
|
|
msg.satellites_visible = gps.satellites_used;
|
2014-07-28 00:07:01 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_gps_raw_int_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 00:07:01 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 00:07:01 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-15 14:23:27 +05:30
|
|
|
class MavlinkStreamSystemTime : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-08-26 23:43:33 +02:00
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return MavlinkStreamSystemTime::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return "SYSTEM_TIME";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return MAVLINK_MSG_ID_SYSTEM_TIME;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return new MavlinkStreamSystemTime(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return MAVLINK_MSG_ID_SYSTEM_TIME_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamSystemTime(MavlinkStreamSystemTime &);
|
|
|
|
|
MavlinkStreamSystemTime &operator = (const MavlinkStreamSystemTime &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamSystemTime(Mavlink *mavlink) : MavlinkStream(mavlink)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_system_time_t msg = {};
|
2014-12-15 14:23:27 +05:30
|
|
|
timespec tv;
|
|
|
|
|
|
2015-04-24 01:39:25 -07:00
|
|
|
px4_clock_gettime(CLOCK_REALTIME, &tv);
|
2014-12-15 14:23:27 +05:30
|
|
|
|
|
|
|
|
msg.time_boot_ms = hrt_absolute_time() / 1000;
|
|
|
|
|
msg.time_unix_usec = (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000;
|
|
|
|
|
|
2018-02-23 15:07:58 +01:00
|
|
|
// If the time is before 2001-01-01, it's probably the default 2000
|
|
|
|
|
// and we don't need to bother sending it because it's definitely wrong.
|
|
|
|
|
if (msg.time_unix_usec > 978307200000000) {
|
|
|
|
|
mavlink_msg_system_time_send_struct(_mavlink->get_channel(), &msg);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
2018-02-23 15:07:58 +01:00
|
|
|
return false;
|
2014-12-15 14:23:27 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamTimesync : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-08-26 23:43:33 +02:00
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return MavlinkStreamTimesync::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return "TIMESYNC";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return MAVLINK_MSG_ID_TIMESYNC;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return new MavlinkStreamTimesync(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-12-15 14:23:27 +05:30
|
|
|
return MAVLINK_MSG_ID_TIMESYNC_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamTimesync(MavlinkStreamTimesync &);
|
|
|
|
|
MavlinkStreamTimesync &operator = (const MavlinkStreamTimesync &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamTimesync(Mavlink *mavlink) : MavlinkStream(mavlink)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_timesync_t msg = {};
|
2014-12-15 14:23:27 +05:30
|
|
|
|
2014-12-16 13:43:48 +05:30
|
|
|
msg.tc1 = 0;
|
2014-12-15 14:23:27 +05:30
|
|
|
msg.ts1 = hrt_absolute_time() * 1000; // boot time in nanoseconds
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_timesync_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-12-15 14:23:27 +05:30
|
|
|
}
|
|
|
|
|
};
|
2014-07-28 00:07:01 +02:00
|
|
|
|
2016-04-17 18:19:32 +02:00
|
|
|
class MavlinkStreamADSBVehicle : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamADSBVehicle::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "ADSB_VEHICLE";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-04-17 18:19:32 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ADSB_VEHICLE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2016-04-17 18:19:32 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamADSBVehicle(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool const_rate()
|
2017-07-20 08:31:08 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 18:19:32 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return (_pos_time > 0) ? MAVLINK_MSG_ID_ADSB_VEHICLE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2016-04-17 18:19:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_pos_sub;
|
|
|
|
|
uint64_t _pos_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamADSBVehicle(MavlinkStreamADSBVehicle &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamADSBVehicle &operator = (const MavlinkStreamADSBVehicle &);
|
2016-04-17 18:19:32 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamADSBVehicle(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_pos_sub(_mavlink->add_orb_subscription(ORB_ID(transponder_report))),
|
|
|
|
|
_pos_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-04-17 18:19:32 +02:00
|
|
|
{
|
|
|
|
|
struct transponder_report_s pos;
|
2017-07-23 18:28:02 +02:00
|
|
|
bool sent = false;
|
2016-04-17 18:19:32 +02:00
|
|
|
|
2017-07-20 08:31:08 +02:00
|
|
|
while (_pos_sub->update(&_pos_time, &pos)) {
|
2016-04-17 18:19:32 +02:00
|
|
|
mavlink_adsb_vehicle_t msg = {};
|
|
|
|
|
|
2018-02-18 13:08:40 +03:00
|
|
|
if (!(pos.flags & transponder_report_s::PX4_ADSB_FLAGS_RETRANSLATE)) { continue; }
|
|
|
|
|
|
2016-04-17 18:19:32 +02:00
|
|
|
msg.ICAO_address = pos.ICAO_address;
|
|
|
|
|
msg.lat = pos.lat * 1e7;
|
|
|
|
|
msg.lon = pos.lon * 1e7;
|
|
|
|
|
msg.altitude_type = pos.altitude_type;
|
|
|
|
|
msg.altitude = pos.altitude * 1e3f;
|
|
|
|
|
msg.heading = (pos.heading + M_PI_F) / M_PI_F * 180.0f * 100.0f;
|
|
|
|
|
msg.hor_velocity = pos.hor_velocity * 100.0f;
|
|
|
|
|
msg.ver_velocity = pos.ver_velocity * 100.0f;
|
|
|
|
|
memcpy(&msg.callsign[0], &pos.callsign[0], sizeof(msg.callsign));
|
|
|
|
|
msg.emitter_type = pos.emitter_type;
|
|
|
|
|
msg.tslc = pos.tslc;
|
|
|
|
|
msg.squawk = pos.squawk;
|
|
|
|
|
|
2018-02-18 13:08:40 +03:00
|
|
|
msg.flags = 0;
|
|
|
|
|
|
|
|
|
|
if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_COORDS) { msg.flags |= ADSB_FLAGS_VALID_COORDS; }
|
|
|
|
|
|
|
|
|
|
if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_ALTITUDE) { msg.flags |= ADSB_FLAGS_VALID_ALTITUDE; }
|
|
|
|
|
|
|
|
|
|
if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_HEADING) { msg.flags |= ADSB_FLAGS_VALID_HEADING; }
|
|
|
|
|
|
|
|
|
|
if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_VELOCITY) { msg.flags |= ADSB_FLAGS_VALID_VELOCITY; }
|
|
|
|
|
|
|
|
|
|
if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_CALLSIGN) { msg.flags |= ADSB_FLAGS_VALID_CALLSIGN; }
|
|
|
|
|
|
|
|
|
|
if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_SQUAWK) { msg.flags |= ADSB_FLAGS_VALID_SQUAWK; }
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_adsb_vehicle_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
sent = true;
|
2016-04-17 18:19:32 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return sent;
|
2016-04-17 18:19:32 +02:00
|
|
|
}
|
|
|
|
|
};
|
2015-05-21 17:41:52 +05:30
|
|
|
|
2016-11-16 18:45:07 +01:00
|
|
|
class MavlinkStreamCollision : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamCollision::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "COLLISION";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_COLLISION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamCollision(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return (_collision_time > 0) ? MAVLINK_MSG_ID_COLLISION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_collision_sub;
|
|
|
|
|
uint64_t _collision_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamCollision(MavlinkStreamCollision &);
|
|
|
|
|
MavlinkStreamCollision &operator = (const MavlinkStreamCollision &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamCollision(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_collision_sub(_mavlink->add_orb_subscription(ORB_ID(collision_report))),
|
|
|
|
|
_collision_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-11-16 18:45:07 +01:00
|
|
|
{
|
|
|
|
|
struct collision_report_s report;
|
2017-07-23 18:28:02 +02:00
|
|
|
bool sent = false;
|
2016-11-16 18:45:07 +01:00
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
while (_collision_sub->update(&_collision_time, &report)) {
|
2016-11-16 18:45:07 +01:00
|
|
|
mavlink_collision_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.src = report.src;
|
|
|
|
|
msg.id = report.id;
|
|
|
|
|
msg.action = report.action;
|
|
|
|
|
msg.threat_level = report.threat_level;
|
|
|
|
|
msg.time_to_minimum_delta = report.time_to_minimum_delta;
|
|
|
|
|
msg.altitude_minimum_delta = report.altitude_minimum_delta;
|
|
|
|
|
msg.horizontal_minimum_delta = report.horizontal_minimum_delta;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_collision_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
sent = true;
|
2016-11-16 18:45:07 +01:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return sent;
|
2016-11-16 18:45:07 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-21 17:41:52 +05:30
|
|
|
class MavlinkStreamCameraTrigger : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-08-08 11:44:04 +02:00
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2015-05-21 17:41:52 +05:30
|
|
|
return MavlinkStreamCameraTrigger::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 11:44:04 +02:00
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2015-05-21 17:41:52 +05:30
|
|
|
return "CAMERA_TRIGGER";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2015-08-08 11:44:04 +02:00
|
|
|
{
|
2015-05-21 17:41:52 +05:30
|
|
|
return MAVLINK_MSG_ID_CAMERA_TRIGGER;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2015-08-08 11:44:04 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2015-05-21 17:41:52 +05:30
|
|
|
return new MavlinkStreamCameraTrigger(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool const_rate()
|
2017-05-18 10:19:12 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 11:44:04 +02:00
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return (_trigger_time > 0) ? MAVLINK_MSG_ID_CAMERA_TRIGGER_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2015-05-21 17:41:52 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2015-08-08 11:44:04 +02:00
|
|
|
MavlinkOrbSubscription *_trigger_sub;
|
2015-08-08 14:14:14 +02:00
|
|
|
uint64_t _trigger_time;
|
2015-05-21 17:41:52 +05:30
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamCameraTrigger(MavlinkStreamCameraTrigger &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamCameraTrigger &operator = (const MavlinkStreamCameraTrigger &);
|
2015-05-21 17:41:52 +05:30
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamCameraTrigger(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2015-08-08 14:14:14 +02:00
|
|
|
_trigger_sub(_mavlink->add_orb_subscription(ORB_ID(camera_trigger))),
|
|
|
|
|
_trigger_time(0)
|
2015-05-21 17:41:52 +05:30
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2015-08-08 11:44:04 +02:00
|
|
|
{
|
2015-05-21 17:41:52 +05:30
|
|
|
struct camera_trigger_s trigger;
|
|
|
|
|
|
2015-08-08 14:14:14 +02:00
|
|
|
if (_trigger_sub->update(&_trigger_time, &trigger)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_camera_trigger_t msg = {};
|
2015-05-21 17:41:52 +05:30
|
|
|
|
|
|
|
|
msg.time_usec = trigger.timestamp;
|
2015-08-08 14:14:14 +02:00
|
|
|
msg.seq = trigger.seq;
|
2015-08-08 11:44:04 +02:00
|
|
|
|
2015-08-08 14:14:14 +02:00
|
|
|
/* ensure that only active trigger events are sent */
|
|
|
|
|
if (trigger.timestamp > 0) {
|
2017-07-16 22:24:26 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_camera_trigger_send_struct(_mavlink->get_channel(), &msg);
|
2017-02-06 14:52:23 +01:00
|
|
|
|
2017-07-27 17:08:22 -07:00
|
|
|
struct vehicle_command_s cmd = {
|
|
|
|
|
.timestamp = 0,
|
|
|
|
|
.param5 = NAN,
|
|
|
|
|
.param6 = NAN,
|
|
|
|
|
.param1 = 0.0f, // all cameras
|
|
|
|
|
.param2 = 0.0f, // duration 0 because only taking one picture
|
|
|
|
|
.param3 = 1.0f, // only take one
|
|
|
|
|
.param4 = NAN,
|
|
|
|
|
.param7 = NAN,
|
|
|
|
|
.command = MAV_CMD_IMAGE_START_CAPTURE,
|
|
|
|
|
.target_system = mavlink_system.sysid,
|
|
|
|
|
.target_component = MAV_COMP_ID_CAMERA
|
|
|
|
|
};
|
2017-07-16 22:24:26 +02:00
|
|
|
|
|
|
|
|
MavlinkCommandSender::instance().handle_vehicle_command(cmd, _mavlink->get_channel());
|
2017-07-18 21:14:36 -04:00
|
|
|
|
|
|
|
|
// TODO: move this camera_trigger and publish as a vehicle_command
|
|
|
|
|
/* send MAV_CMD_DO_DIGICAM_CONTROL*/
|
|
|
|
|
mavlink_command_long_t digicam_ctrl_cmd;
|
|
|
|
|
|
|
|
|
|
digicam_ctrl_cmd.target_system = 0; // 0 for broadcast
|
|
|
|
|
digicam_ctrl_cmd.target_component = MAV_COMP_ID_CAMERA;
|
|
|
|
|
digicam_ctrl_cmd.command = MAV_CMD_DO_DIGICAM_CONTROL;
|
|
|
|
|
digicam_ctrl_cmd.confirmation = 0;
|
|
|
|
|
digicam_ctrl_cmd.param1 = NAN;
|
|
|
|
|
digicam_ctrl_cmd.param2 = NAN;
|
|
|
|
|
digicam_ctrl_cmd.param3 = NAN;
|
|
|
|
|
digicam_ctrl_cmd.param4 = NAN;
|
|
|
|
|
digicam_ctrl_cmd.param5 = 1; // take 1 picture
|
|
|
|
|
digicam_ctrl_cmd.param6 = NAN;
|
|
|
|
|
digicam_ctrl_cmd.param7 = NAN;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_command_long_send_struct(_mavlink->get_channel(), &digicam_ctrl_cmd);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2015-08-08 14:14:14 +02:00
|
|
|
}
|
2015-05-21 17:41:52 +05:30
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2015-05-21 17:41:52 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-01 11:23:02 +02:00
|
|
|
class MavlinkStreamCameraImageCaptured : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamCameraImageCaptured::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "CAMERA_IMAGE_CAPTURED";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_CAMERA_IMAGE_CAPTURED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool const_rate()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamCameraImageCaptured(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return (_capture_time > 0) ? MAVLINK_MSG_ID_CAMERA_IMAGE_CAPTURED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_capture_sub;
|
|
|
|
|
uint64_t _capture_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamCameraImageCaptured(MavlinkStreamCameraImageCaptured &);
|
|
|
|
|
MavlinkStreamCameraImageCaptured &operator = (const MavlinkStreamCameraImageCaptured &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamCameraImageCaptured(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_capture_sub(_mavlink->add_orb_subscription(ORB_ID(camera_capture))),
|
|
|
|
|
_capture_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2017-05-01 11:23:02 +02:00
|
|
|
{
|
|
|
|
|
struct camera_capture_s capture;
|
|
|
|
|
|
|
|
|
|
if (_capture_sub->update(&_capture_time, &capture)) {
|
|
|
|
|
|
|
|
|
|
mavlink_camera_image_captured_t msg;
|
|
|
|
|
|
|
|
|
|
msg.time_boot_ms = capture.timestamp / 1000;
|
|
|
|
|
msg.time_utc = capture.timestamp_utc;
|
|
|
|
|
msg.camera_id = 1; // FIXME : get this from uORB
|
|
|
|
|
msg.lat = capture.lat * 1e7;
|
|
|
|
|
msg.lon = capture.lon * 1e7;
|
|
|
|
|
msg.alt = capture.alt * 1e3f;
|
2017-05-04 11:16:53 +02:00
|
|
|
msg.relative_alt = capture.ground_distance * 1e3f;
|
2017-05-01 11:23:02 +02:00
|
|
|
msg.q[0] = capture.q[0];
|
|
|
|
|
msg.q[1] = capture.q[1];
|
|
|
|
|
msg.q[2] = capture.q[2];
|
|
|
|
|
msg.q[3] = capture.q[3];
|
|
|
|
|
msg.image_index = capture.seq;
|
|
|
|
|
msg.capture_result = capture.result;
|
|
|
|
|
msg.file_url[0] = '\0';
|
|
|
|
|
|
|
|
|
|
mavlink_msg_camera_image_captured_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2017-05-01 11:23:02 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2017-05-01 11:23:02 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
class MavlinkStreamGlobalPositionInt : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamGlobalPositionInt::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "GLOBAL_POSITION_INT";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_GLOBAL_POSITION_INT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamGlobalPositionInt(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_GLOBAL_POSITION_INT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2018-03-25 13:21:08 -04:00
|
|
|
MavlinkOrbSubscription *_gpos_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _gpos_time;
|
|
|
|
|
|
2018-03-25 13:21:08 -04:00
|
|
|
MavlinkOrbSubscription *_lpos_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _lpos_time;
|
|
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
MavlinkOrbSubscription *_home_sub;
|
2018-02-18 11:44:21 -05:00
|
|
|
MavlinkOrbSubscription *_air_data_sub;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamGlobalPositionInt(MavlinkStreamGlobalPositionInt &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamGlobalPositionInt &operator = (const MavlinkStreamGlobalPositionInt &);
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamGlobalPositionInt(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2018-03-25 13:21:08 -04:00
|
|
|
_gpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_global_position))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_gpos_time(0),
|
2018-03-25 13:21:08 -04:00
|
|
|
_lpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_lpos_time(0),
|
2014-07-28 11:02:56 +02:00
|
|
|
_home_sub(_mavlink->add_orb_subscription(ORB_ID(home_position))),
|
2018-02-18 11:44:21 -05:00
|
|
|
_air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data)))
|
2014-07-28 11:02:56 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
2018-03-25 13:21:08 -04:00
|
|
|
vehicle_global_position_s gpos = {};
|
|
|
|
|
vehicle_local_position_s lpos = {};
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
bool gpos_updated = _gpos_sub->update(&_gpos_time, &gpos);
|
|
|
|
|
bool lpos_updated = _lpos_sub->update(&_lpos_time, &lpos);
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
if (gpos_updated && lpos_updated) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_global_position_int_t msg = {};
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2018-03-25 13:21:08 -04:00
|
|
|
if (lpos.z_valid && lpos.z_global) {
|
|
|
|
|
msg.alt = (-lpos.z + lpos.ref_alt) * 1000.0f;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// fall back to baro altitude
|
2018-02-18 11:44:21 -05:00
|
|
|
vehicle_air_data_s air_data = {};
|
|
|
|
|
_air_data_sub->update(&air_data);
|
2018-03-25 14:21:09 -04:00
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
if (air_data.timestamp > 0) {
|
|
|
|
|
msg.alt = air_data.baro_alt_meter * 1000.0f;
|
2018-03-25 13:21:08 -04:00
|
|
|
}
|
2018-01-02 15:12:30 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
home_position_s home = {};
|
|
|
|
|
_home_sub->update(&home);
|
|
|
|
|
|
|
|
|
|
if ((home.timestamp > 0) && home.valid_alt) {
|
2018-03-25 13:21:08 -04:00
|
|
|
if (lpos.z_valid) {
|
|
|
|
|
msg.relative_alt = -(lpos.z - home.z) * 1000.0f;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
msg.relative_alt = msg.alt - (home.alt * 1000.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if (lpos.z_valid) {
|
|
|
|
|
msg.relative_alt = -lpos.z * 1000.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg.time_boot_ms = gpos.timestamp / 1000;
|
|
|
|
|
msg.lat = gpos.lat * 1e7;
|
|
|
|
|
msg.lon = gpos.lon * 1e7;
|
|
|
|
|
|
|
|
|
|
msg.vx = lpos.vx * 100.0f;
|
|
|
|
|
msg.vy = lpos.vy * 100.0f;
|
|
|
|
|
msg.vz = lpos.vz * 100.0f;
|
|
|
|
|
|
|
|
|
|
msg.hdg = _wrap_2pi(lpos.yaw) * M_RAD_TO_DEG_F * 100.0f;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_global_position_int_send_struct(_mavlink->get_channel(), &msg);
|
2018-03-25 14:21:09 -04:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
return false;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-16 21:50:35 +05:30
|
|
|
class MavlinkStreamVisionPositionEstimate : public MavlinkStream
|
2015-12-07 13:30:38 -08:00
|
|
|
{
|
|
|
|
|
public:
|
2016-08-26 23:43:33 +02:00
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2016-12-16 21:50:35 +05:30
|
|
|
return MavlinkStreamVisionPositionEstimate::get_name_static();
|
2016-08-26 23:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2016-12-16 21:50:35 +05:30
|
|
|
return "VISION_POSITION_ESTIMATE";
|
2016-08-26 23:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2016-12-16 21:50:35 +05:30
|
|
|
return new MavlinkStreamVisionPositionEstimate(mavlink);
|
2016-08-26 23:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return (_pos_time > 0) ? MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
|
|
|
|
}
|
2015-12-07 13:30:38 -08:00
|
|
|
private:
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkOrbSubscription *_pos_sub;
|
|
|
|
|
uint64_t _pos_time;
|
2015-12-07 13:30:38 -08:00
|
|
|
|
2016-12-16 21:50:35 +05:30
|
|
|
MavlinkOrbSubscription *_att_sub;
|
|
|
|
|
uint64_t _att_time;
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
/* do not allow top copying this class */
|
2016-12-16 21:50:35 +05:30
|
|
|
MavlinkStreamVisionPositionEstimate(MavlinkStreamVisionPositionEstimate &);
|
|
|
|
|
MavlinkStreamVisionPositionEstimate &operator = (const MavlinkStreamVisionPositionEstimate &);
|
2015-12-07 13:30:38 -08:00
|
|
|
|
|
|
|
|
protected:
|
2016-12-16 21:50:35 +05:30
|
|
|
explicit MavlinkStreamVisionPositionEstimate(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_vision_position))),
|
|
|
|
|
_pos_time(0),
|
|
|
|
|
_att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_vision_attitude))),
|
|
|
|
|
_att_time(0)
|
2016-08-26 23:43:33 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_local_position_s vpos = {};
|
|
|
|
|
vehicle_attitude_s vatt = {};
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2017-02-16 14:08:55 +05:30
|
|
|
bool att_updated = _att_sub->update(&_att_time, &vatt);
|
|
|
|
|
bool pos_updated = _pos_sub->update(&_pos_time, &vpos);
|
|
|
|
|
|
|
|
|
|
if (pos_updated || att_updated) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_vision_position_estimate_t vmsg = {};
|
2016-08-26 23:43:33 +02:00
|
|
|
vmsg.usec = vpos.timestamp;
|
|
|
|
|
vmsg.x = vpos.x;
|
|
|
|
|
vmsg.y = vpos.y;
|
|
|
|
|
vmsg.z = vpos.z;
|
2018-03-21 16:04:51 -04:00
|
|
|
|
|
|
|
|
matrix::Eulerf euler = matrix::Quatf(vatt.q);
|
|
|
|
|
vmsg.roll = euler.phi();
|
|
|
|
|
vmsg.pitch = euler.theta();
|
|
|
|
|
vmsg.yaw = euler.psi();
|
2016-08-26 23:43:33 +02:00
|
|
|
|
|
|
|
|
mavlink_msg_vision_position_estimate_send_struct(_mavlink->get_channel(), &vmsg);
|
|
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return (pos_updated || att_updated);
|
2016-08-26 23:43:33 +02:00
|
|
|
}
|
2015-12-07 13:30:38 -08:00
|
|
|
};
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
class MavlinkStreamLocalPositionNED : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamLocalPositionNED::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "LOCAL_POSITION_NED";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_LOCAL_POSITION_NED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamLocalPositionNED(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_LOCAL_POSITION_NED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_pos_sub;
|
|
|
|
|
uint64_t _pos_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamLocalPositionNED(MavlinkStreamLocalPositionNED &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamLocalPositionNED &operator = (const MavlinkStreamLocalPositionNED &);
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamLocalPositionNED(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))),
|
|
|
|
|
_pos_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_local_position_s pos;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
if (_pos_sub->update(&_pos_time, &pos)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_local_position_ned_t msg = {};
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
msg.time_boot_ms = pos.timestamp / 1000;
|
|
|
|
|
msg.x = pos.x;
|
|
|
|
|
msg.y = pos.y;
|
|
|
|
|
msg.z = pos.z;
|
2014-08-27 07:58:36 +02:00
|
|
|
msg.vx = pos.vx;
|
|
|
|
|
msg.vy = pos.vy;
|
|
|
|
|
msg.vz = pos.vz;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_local_position_ned_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-10-24 10:57:46 -04:00
|
|
|
class MavlinkStreamLocalPositionNEDCOV : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamLocalPositionNEDCOV::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "LOCAL_POSITION_NED_COV";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2015-10-24 10:57:46 -04:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_LOCAL_POSITION_NED_COV;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2015-10-24 10:57:46 -04:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamLocalPositionNEDCOV(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_LOCAL_POSITION_NED_COV_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_est_sub;
|
|
|
|
|
uint64_t _est_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamLocalPositionNEDCOV(MavlinkStreamLocalPositionNEDCOV &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamLocalPositionNEDCOV &operator = (const MavlinkStreamLocalPositionNEDCOV &);
|
2015-10-24 10:57:46 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamLocalPositionNEDCOV(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_est_sub(_mavlink->add_orb_subscription(ORB_ID(estimator_status))),
|
|
|
|
|
_est_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2015-10-24 10:57:46 -04:00
|
|
|
{
|
2016-08-15 13:07:29 +02:00
|
|
|
struct estimator_status_s est = {};
|
2015-10-24 10:57:46 -04:00
|
|
|
|
|
|
|
|
if (_est_sub->update(&_est_time, &est)) {
|
2016-08-15 13:07:29 +02:00
|
|
|
mavlink_local_position_ned_cov_t msg = {};
|
2015-10-24 10:57:46 -04:00
|
|
|
|
2016-11-17 08:46:06 +01:00
|
|
|
msg.time_usec = est.timestamp;
|
2015-10-24 10:57:46 -04:00
|
|
|
msg.x = est.states[0];
|
|
|
|
|
msg.y = est.states[1];
|
|
|
|
|
msg.z = est.states[2];
|
|
|
|
|
msg.vx = est.states[3];
|
|
|
|
|
msg.vy = est.states[4];
|
|
|
|
|
msg.vz = est.states[5];
|
|
|
|
|
msg.ax = est.states[6];
|
|
|
|
|
msg.ay = est.states[7];
|
|
|
|
|
msg.az = est.states[8];
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2016-08-15 13:07:29 +02:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2015-10-24 10:57:46 -04:00
|
|
|
msg.covariance[i] = est.covariances[i];
|
|
|
|
|
}
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2015-10-24 10:57:46 -04:00
|
|
|
msg.covariance[9] = est.nan_flags;
|
|
|
|
|
msg.covariance[10] = est.health_flags;
|
|
|
|
|
msg.covariance[11] = est.timeout_flags;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_local_position_ned_cov_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2015-10-24 10:57:46 -04:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2015-10-24 10:57:46 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-25 15:57:53 +01:00
|
|
|
class MavlinkStreamEstimatorStatus : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamEstimatorStatus::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "ESTIMATOR_STATUS";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-02-25 15:57:53 +01:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_VIBRATION;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2016-02-25 15:57:53 +01:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamEstimatorStatus(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_VIBRATION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_est_sub;
|
|
|
|
|
uint64_t _est_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamEstimatorStatus(MavlinkStreamEstimatorStatus &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamEstimatorStatus &operator = (const MavlinkStreamEstimatorStatus &);
|
2016-02-25 15:57:53 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamEstimatorStatus(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_est_sub(_mavlink->add_orb_subscription(ORB_ID(estimator_status))),
|
|
|
|
|
_est_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-02-25 15:57:53 +01:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
estimator_status_s est;
|
2016-02-25 15:57:53 +01:00
|
|
|
|
|
|
|
|
if (_est_sub->update(&_est_time, &est)) {
|
2018-03-25 14:21:09 -04:00
|
|
|
// ESTIMATOR_STATUS
|
|
|
|
|
mavlink_estimator_status_t est_msg = {};
|
|
|
|
|
est_msg.time_usec = est.timestamp;
|
|
|
|
|
est_msg.vel_ratio = est.vel_test_ratio;
|
|
|
|
|
est_msg.pos_horiz_ratio = est.pos_test_ratio;
|
|
|
|
|
est_msg.pos_vert_ratio = est.hgt_test_ratio;
|
|
|
|
|
est_msg.mag_ratio = est.mag_test_ratio;
|
|
|
|
|
est_msg.hagl_ratio = est.hagl_test_ratio;
|
|
|
|
|
est_msg.tas_ratio = est.tas_test_ratio;
|
|
|
|
|
est_msg.pos_horiz_accuracy = est.pos_horiz_accuracy;
|
|
|
|
|
est_msg.pos_vert_accuracy = est.pos_vert_accuracy;
|
|
|
|
|
est_msg.flags = est.solution_status_flags;
|
2016-09-03 16:00:51 -04:00
|
|
|
mavlink_msg_estimator_status_send_struct(_mavlink->get_channel(), &est_msg);
|
2016-02-25 15:57:53 +01:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
// VIBRATION
|
|
|
|
|
mavlink_vibration_t msg = {};
|
|
|
|
|
msg.time_usec = est.timestamp;
|
|
|
|
|
msg.vibration_x = est.vibe[0];
|
|
|
|
|
msg.vibration_y = est.vibe[1];
|
|
|
|
|
msg.vibration_z = est.vibe[2];
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_vibration_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2016-02-25 15:57:53 +01:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2016-02-25 15:57:53 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-13 17:03:31 +01:00
|
|
|
class MavlinkStreamAttPosMocap : public MavlinkStream
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2015-06-13 17:03:31 +01:00
|
|
|
return MavlinkStreamAttPosMocap::get_name_static();
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2015-06-13 17:03:31 +01:00
|
|
|
return "ATT_POS_MOCAP";
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
2015-06-13 17:03:31 +01:00
|
|
|
return MAVLINK_MSG_ID_ATT_POS_MOCAP;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2015-06-13 17:03:31 +01:00
|
|
|
return new MavlinkStreamAttPosMocap(mavlink);
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2015-06-13 17:03:31 +01:00
|
|
|
return MAVLINK_MSG_ID_ATT_POS_MOCAP_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2015-06-13 17:03:31 +01:00
|
|
|
MavlinkOrbSubscription *_mocap_sub;
|
|
|
|
|
uint64_t _mocap_time;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2015-06-13 17:03:31 +01:00
|
|
|
MavlinkStreamAttPosMocap(MavlinkStreamAttPosMocap &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamAttPosMocap &operator = (const MavlinkStreamAttPosMocap &);
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
2015-06-13 17:03:31 +01:00
|
|
|
explicit MavlinkStreamAttPosMocap(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_mocap_sub(_mavlink->add_orb_subscription(ORB_ID(att_pos_mocap))),
|
|
|
|
|
_mocap_time(0)
|
2014-07-28 11:02:56 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
att_pos_mocap_s mocap;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2015-06-13 17:03:31 +01:00
|
|
|
if (_mocap_sub->update(&_mocap_time, &mocap)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_att_pos_mocap_t msg = {};
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2016-07-11 04:46:29 -06:00
|
|
|
msg.time_usec = mocap.timestamp;
|
2015-06-13 17:03:31 +01:00
|
|
|
msg.q[0] = mocap.q[0];
|
|
|
|
|
msg.q[1] = mocap.q[1];
|
|
|
|
|
msg.q[2] = mocap.q[2];
|
|
|
|
|
msg.q[3] = mocap.q[3];
|
|
|
|
|
msg.x = mocap.x;
|
|
|
|
|
msg.y = mocap.y;
|
|
|
|
|
msg.z = mocap.z;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_att_pos_mocap_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-09-27 18:06:53 +02:00
|
|
|
class MavlinkStreamHomePosition : public MavlinkStream
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2015-09-27 18:06:53 +02:00
|
|
|
return MavlinkStreamHomePosition::get_name_static();
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2015-09-27 18:06:53 +02:00
|
|
|
return "HOME_POSITION";
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
2015-09-27 18:06:53 +02:00
|
|
|
return MAVLINK_MSG_ID_HOME_POSITION;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2015-09-27 18:06:53 +02:00
|
|
|
return new MavlinkStreamHomePosition(mavlink);
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2015-09-27 18:06:53 +02:00
|
|
|
return _home_sub->is_published() ? (MAVLINK_MSG_ID_HOME_POSITION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_home_sub;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2015-09-27 18:06:53 +02:00
|
|
|
MavlinkStreamHomePosition(MavlinkStreamHomePosition &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamHomePosition &operator = (const MavlinkStreamHomePosition &);
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
2015-09-27 18:06:53 +02:00
|
|
|
explicit MavlinkStreamHomePosition(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-28 11:02:56 +02:00
|
|
|
_home_sub(_mavlink->add_orb_subscription(ORB_ID(home_position)))
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
|
|
|
|
/* we're sending the GPS home periodically to ensure the
|
|
|
|
|
* the GCS does pick it up at one point */
|
|
|
|
|
if (_home_sub->is_published()) {
|
2018-03-25 14:21:09 -04:00
|
|
|
home_position_s home;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
if (_home_sub->update(&home)) {
|
2017-12-10 02:31:42 -05:00
|
|
|
if (home.valid_hpos) {
|
|
|
|
|
mavlink_home_position_t msg;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2017-12-10 02:31:42 -05:00
|
|
|
msg.latitude = home.lat * 1e7;
|
|
|
|
|
msg.longitude = home.lon * 1e7;
|
|
|
|
|
msg.altitude = home.alt * 1e3f;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2017-12-10 02:31:42 -05:00
|
|
|
msg.x = home.x;
|
|
|
|
|
msg.y = home.y;
|
|
|
|
|
msg.z = home.z;
|
2015-09-27 18:06:53 +02:00
|
|
|
|
2017-12-10 02:31:42 -05:00
|
|
|
matrix::Quatf q(matrix::Eulerf(0.0f, 0.0f, home.yaw));
|
|
|
|
|
msg.q[0] = q(0);
|
|
|
|
|
msg.q[1] = q(1);
|
|
|
|
|
msg.q[2] = q(2);
|
|
|
|
|
msg.q[3] = q(3);
|
2016-12-25 21:13:00 +01:00
|
|
|
|
2017-12-10 02:31:42 -05:00
|
|
|
msg.approach_x = 0.0f;
|
|
|
|
|
msg.approach_y = 0.0f;
|
|
|
|
|
msg.approach_z = 0.0f;
|
2015-09-27 18:06:53 +02:00
|
|
|
|
2017-12-10 02:31:42 -05:00
|
|
|
mavlink_msg_home_position_send_struct(_mavlink->get_channel(), &msg);
|
2015-09-27 18:06:53 +02:00
|
|
|
|
2017-12-10 02:31:42 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <int N>
|
|
|
|
|
class MavlinkStreamServoOutputRaw : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamServoOutputRaw<N>::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_SERVO_OUTPUT_RAW;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 11:02:56 +02:00
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
switch (N) {
|
2016-08-26 23:43:33 +02:00
|
|
|
case 0:
|
2014-07-28 11:02:56 +02:00
|
|
|
return "SERVO_OUTPUT_RAW_0";
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 1:
|
2014-07-28 11:02:56 +02:00
|
|
|
return "SERVO_OUTPUT_RAW_1";
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 2:
|
2014-07-28 11:02:56 +02:00
|
|
|
return "SERVO_OUTPUT_RAW_2";
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 3:
|
2014-07-28 11:02:56 +02:00
|
|
|
return "SERVO_OUTPUT_RAW_3";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamServoOutputRaw<N>(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_SERVO_OUTPUT_RAW_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_act_sub;
|
|
|
|
|
uint64_t _act_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamServoOutputRaw(MavlinkStreamServoOutputRaw &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamServoOutputRaw &operator = (const MavlinkStreamServoOutputRaw &);
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamServoOutputRaw(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2018-03-25 14:21:09 -04:00
|
|
|
_act_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_outputs), N)),
|
2014-07-28 11:02:56 +02:00
|
|
|
_act_time(0)
|
2018-03-25 14:21:09 -04:00
|
|
|
{}
|
2014-07-28 11:02:56 +02:00
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 11:02:56 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
actuator_outputs_s act;
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
if (_act_sub->update(&_act_time, &act)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_servo_output_raw_t msg = {};
|
2014-07-28 11:02:56 +02:00
|
|
|
|
|
|
|
|
msg.time_usec = act.timestamp;
|
|
|
|
|
msg.port = N;
|
|
|
|
|
msg.servo1_raw = act.output[0];
|
|
|
|
|
msg.servo2_raw = act.output[1];
|
|
|
|
|
msg.servo3_raw = act.output[2];
|
|
|
|
|
msg.servo4_raw = act.output[3];
|
|
|
|
|
msg.servo5_raw = act.output[4];
|
|
|
|
|
msg.servo6_raw = act.output[5];
|
|
|
|
|
msg.servo7_raw = act.output[6];
|
|
|
|
|
msg.servo8_raw = act.output[7];
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_servo_output_raw_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 11:02:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-12 09:26:55 +01:00
|
|
|
template <int N>
|
|
|
|
|
class MavlinkStreamActuatorControlTarget : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamActuatorControlTarget<N>::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
switch (N) {
|
2016-08-26 23:43:33 +02:00
|
|
|
case 0:
|
2015-02-12 09:26:55 +01:00
|
|
|
return "ACTUATOR_CONTROL_TARGET0";
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 1:
|
2015-02-12 09:26:55 +01:00
|
|
|
return "ACTUATOR_CONTROL_TARGET1";
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 2:
|
2015-02-12 09:26:55 +01:00
|
|
|
return "ACTUATOR_CONTROL_TARGET2";
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 3:
|
2015-02-12 09:26:55 +01:00
|
|
|
return "ACTUATOR_CONTROL_TARGET3";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2015-02-12 09:26:55 +01:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ACTUATOR_CONTROL_TARGET;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2015-02-12 09:26:55 +01:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamActuatorControlTarget<N>(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return _att_ctrl_sub->is_published() ? (MAVLINK_MSG_ID_ACTUATOR_CONTROL_TARGET_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_att_ctrl_sub;
|
|
|
|
|
uint64_t _att_ctrl_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamActuatorControlTarget(MavlinkStreamActuatorControlTarget &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamActuatorControlTarget &operator = (const MavlinkStreamActuatorControlTarget &);
|
2015-02-12 09:26:55 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamActuatorControlTarget(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_att_ctrl_sub(nullptr),
|
|
|
|
|
_att_ctrl_time(0)
|
|
|
|
|
{
|
|
|
|
|
// XXX this can be removed once the multiplatform system remaps topics
|
|
|
|
|
switch (N) {
|
2016-08-26 23:43:33 +02:00
|
|
|
case 0:
|
2015-02-12 09:26:55 +01:00
|
|
|
_att_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_0));
|
|
|
|
|
break;
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 1:
|
2015-02-12 09:26:55 +01:00
|
|
|
_att_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_1));
|
|
|
|
|
break;
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 2:
|
2015-02-12 09:26:55 +01:00
|
|
|
_att_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_2));
|
|
|
|
|
break;
|
|
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
case 3:
|
2015-02-12 09:26:55 +01:00
|
|
|
_att_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_3));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2015-02-12 09:26:55 +01:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
actuator_controls_s att_ctrl;
|
2015-02-12 09:26:55 +01:00
|
|
|
|
|
|
|
|
if (_att_ctrl_sub->update(&_att_ctrl_time, &att_ctrl)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_actuator_control_target_t msg = {};
|
2015-02-12 09:26:55 +01:00
|
|
|
|
|
|
|
|
msg.time_usec = att_ctrl.timestamp;
|
|
|
|
|
msg.group_mlx = N;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < sizeof(msg.controls) / sizeof(msg.controls[0]); i++) {
|
|
|
|
|
msg.controls[i] = att_ctrl.control[i];
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_actuator_control_target_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2015-02-12 09:26:55 +01:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2015-02-12 09:26:55 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-01 16:34:46 +02:00
|
|
|
class MavlinkStreamHILActuatorControls : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamHILActuatorControls::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "HIL_ACTUATOR_CONTROLS";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-09-01 16:34:46 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HIL_ACTUATOR_CONTROLS;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-09-01 16:34:46 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamHILActuatorControls(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HIL_ACTUATOR_CONTROLS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_status_sub;
|
|
|
|
|
|
|
|
|
|
MavlinkOrbSubscription *_act_sub;
|
|
|
|
|
uint64_t _act_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamHILActuatorControls(MavlinkStreamHILActuatorControls &);
|
|
|
|
|
MavlinkStreamHILActuatorControls &operator = (const MavlinkStreamHILActuatorControls &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamHILActuatorControls(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))),
|
|
|
|
|
_act_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_outputs))),
|
|
|
|
|
_act_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-09-01 16:34:46 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
actuator_outputs_s act;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
if (_act_sub->update(&_act_time, &act)) {
|
|
|
|
|
vehicle_status_s status = {};
|
|
|
|
|
_status_sub->update(&status);
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
if ((status.timestamp > 0) && (status.arming_state == vehicle_status_s::ARMING_STATE_ARMED)) {
|
|
|
|
|
/* translate the current system state to mavlink state and mode */
|
|
|
|
|
uint8_t mavlink_state;
|
|
|
|
|
uint8_t mavlink_base_mode;
|
|
|
|
|
uint32_t mavlink_custom_mode;
|
|
|
|
|
mavlink_hil_actuator_controls_t msg = {};
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
get_mavlink_mode_state(&status, &mavlink_state, &mavlink_base_mode, &mavlink_custom_mode);
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
const float pwm_center = (PWM_DEFAULT_MAX + PWM_DEFAULT_MIN) / 2;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
unsigned system_type = _mavlink->get_system_type();
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
/* scale outputs depending on system type */
|
|
|
|
|
if (system_type == MAV_TYPE_QUADROTOR ||
|
|
|
|
|
system_type == MAV_TYPE_HEXAROTOR ||
|
|
|
|
|
system_type == MAV_TYPE_OCTOROTOR ||
|
|
|
|
|
system_type == MAV_TYPE_VTOL_DUOROTOR ||
|
|
|
|
|
system_type == MAV_TYPE_VTOL_QUADROTOR ||
|
|
|
|
|
system_type == MAV_TYPE_VTOL_RESERVED2) {
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
/* multirotors: set number of rotor outputs depending on type */
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
unsigned n;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
switch (system_type) {
|
|
|
|
|
case MAV_TYPE_QUADROTOR:
|
|
|
|
|
n = 4;
|
|
|
|
|
break;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
case MAV_TYPE_HEXAROTOR:
|
|
|
|
|
n = 6;
|
|
|
|
|
break;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
case MAV_TYPE_VTOL_DUOROTOR:
|
|
|
|
|
n = 2;
|
|
|
|
|
break;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
case MAV_TYPE_VTOL_QUADROTOR:
|
|
|
|
|
n = 4;
|
|
|
|
|
break;
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
case MAV_TYPE_VTOL_RESERVED2:
|
|
|
|
|
n = 8;
|
|
|
|
|
break;
|
2016-09-07 12:09:22 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
default:
|
|
|
|
|
n = 8;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
for (unsigned i = 0; i < 16; i++) {
|
|
|
|
|
if (act.output[i] > PWM_DEFAULT_MIN / 2) {
|
|
|
|
|
if (i < n) {
|
|
|
|
|
/* scale PWM out 900..2100 us to 0..1 for rotors */
|
|
|
|
|
msg.controls[i] = (act.output[i] - PWM_DEFAULT_MIN) / (PWM_DEFAULT_MAX - PWM_DEFAULT_MIN);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
/* scale PWM out 900..2100 us to -1..1 for other channels */
|
|
|
|
|
msg.controls[i] = (act.output[i] - pwm_center) / ((PWM_DEFAULT_MAX - PWM_DEFAULT_MIN) / 2);
|
|
|
|
|
}
|
2016-09-01 16:34:46 +02:00
|
|
|
|
|
|
|
|
} else {
|
2018-03-25 14:21:09 -04:00
|
|
|
/* send 0 when disarmed and for disabled channels */
|
|
|
|
|
msg.controls[i] = 0.0f;
|
2016-09-01 16:34:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
} else {
|
|
|
|
|
/* fixed wing: scale throttle to 0..1 and other channels to -1..1 */
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
for (unsigned i = 0; i < 16; i++) {
|
|
|
|
|
if (act.output[i] > PWM_DEFAULT_MIN / 2) {
|
|
|
|
|
if (i != 3) {
|
|
|
|
|
/* scale PWM out 900..2100 us to -1..1 for normal channels */
|
|
|
|
|
msg.controls[i] = (act.output[i] - pwm_center) / ((PWM_DEFAULT_MAX - PWM_DEFAULT_MIN) / 2);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
/* scale PWM out 900..2100 us to 0..1 for throttle */
|
|
|
|
|
msg.controls[i] = (act.output[i] - PWM_DEFAULT_MIN) / (PWM_DEFAULT_MAX - PWM_DEFAULT_MIN);
|
|
|
|
|
}
|
2016-09-01 16:34:46 +02:00
|
|
|
|
|
|
|
|
} else {
|
2018-03-25 14:21:09 -04:00
|
|
|
/* set 0 for disabled channels */
|
|
|
|
|
msg.controls[i] = 0.0f;
|
2016-09-01 16:34:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
msg.time_usec = hrt_absolute_time();
|
|
|
|
|
msg.mode = mavlink_base_mode;
|
|
|
|
|
msg.flags = 0;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_hil_actuator_controls_send_struct(_mavlink->get_channel(), &msg);
|
2016-09-01 16:34:46 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
2016-09-01 16:34:46 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
return false;
|
2016-09-01 16:34:46 +02:00
|
|
|
}
|
|
|
|
|
};
|
2014-07-28 13:53:45 +02:00
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
class MavlinkStreamPositionTargetGlobalInt : public MavlinkStream
|
2014-07-28 13:53:45 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MavlinkStreamPositionTargetGlobalInt::get_name_static();
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return "POSITION_TARGET_GLOBAL_INT";
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 13:53:45 +02:00
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MAVLINK_MSG_ID_POSITION_TARGET_GLOBAL_INT;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 13:53:45 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return new MavlinkStreamPositionTargetGlobalInt(mavlink);
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MAVLINK_MSG_ID_POSITION_TARGET_GLOBAL_INT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_pos_sp_triplet_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _pos_sp_triplet_timestamp{0};
|
2014-07-28 13:53:45 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2014-08-10 01:24:04 +02:00
|
|
|
MavlinkStreamPositionTargetGlobalInt(MavlinkStreamPositionTargetGlobalInt &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamPositionTargetGlobalInt &operator = (const MavlinkStreamPositionTargetGlobalInt &);
|
2014-07-28 13:53:45 +02:00
|
|
|
|
|
|
|
|
protected:
|
2014-08-10 01:24:04 +02:00
|
|
|
explicit MavlinkStreamPositionTargetGlobalInt(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-28 13:53:45 +02:00
|
|
|
_pos_sp_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet)))
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 13:53:45 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
position_setpoint_triplet_s pos_sp_triplet;
|
2014-07-28 13:53:45 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
if (_pos_sp_triplet_sub->update(&_pos_sp_triplet_timestamp, &pos_sp_triplet)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_position_target_global_int_t msg = {};
|
2014-07-28 13:53:45 +02:00
|
|
|
|
2016-08-26 23:43:33 +02:00
|
|
|
msg.time_boot_ms = hrt_absolute_time() / 1000;
|
2014-07-28 13:53:45 +02:00
|
|
|
msg.coordinate_frame = MAV_FRAME_GLOBAL;
|
2014-08-10 01:24:04 +02:00
|
|
|
msg.lat_int = pos_sp_triplet.current.lat * 1e7;
|
|
|
|
|
msg.lon_int = pos_sp_triplet.current.lon * 1e7;
|
|
|
|
|
msg.alt = pos_sp_triplet.current.alt;
|
2014-07-28 13:53:45 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_position_target_global_int_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamLocalPositionSetpoint : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamLocalPositionSetpoint::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return "POSITION_TARGET_LOCAL_NED";
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 13:53:45 +02:00
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 13:53:45 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamLocalPositionSetpoint(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_pos_sp_sub;
|
|
|
|
|
uint64_t _pos_sp_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamLocalPositionSetpoint(MavlinkStreamLocalPositionSetpoint &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamLocalPositionSetpoint &operator = (const MavlinkStreamLocalPositionSetpoint &);
|
2014-07-28 13:53:45 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamLocalPositionSetpoint(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_pos_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position_setpoint))),
|
|
|
|
|
_pos_sp_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 13:53:45 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_local_position_setpoint_s pos_sp;
|
2014-07-28 13:53:45 +02:00
|
|
|
|
|
|
|
|
if (_pos_sp_sub->update(&_pos_sp_time, &pos_sp)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_position_target_local_ned_t msg = {};
|
2014-07-28 13:53:45 +02:00
|
|
|
|
2014-08-10 01:30:25 +02:00
|
|
|
msg.time_boot_ms = pos_sp.timestamp / 1000;
|
2014-07-28 13:53:45 +02:00
|
|
|
msg.coordinate_frame = MAV_FRAME_LOCAL_NED;
|
|
|
|
|
msg.x = pos_sp.x;
|
|
|
|
|
msg.y = pos_sp.y;
|
|
|
|
|
msg.z = pos_sp.z;
|
2015-06-26 00:41:07 +02:00
|
|
|
msg.yaw = pos_sp.yaw;
|
|
|
|
|
msg.vx = pos_sp.vx;
|
|
|
|
|
msg.vy = pos_sp.vy;
|
|
|
|
|
msg.vz = pos_sp.vz;
|
2015-12-10 19:21:38 +01:00
|
|
|
msg.afx = pos_sp.acc_x;
|
|
|
|
|
msg.afy = pos_sp.acc_y;
|
|
|
|
|
msg.afz = pos_sp.acc_z;
|
2014-07-28 13:53:45 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_position_target_local_ned_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 13:53:45 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
class MavlinkStreamAttitudeTarget : public MavlinkStream
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MavlinkStreamAttitudeTarget::get_name_static();
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return "ATTITUDE_TARGET";
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MAVLINK_MSG_ID_ATTITUDE_TARGET;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 17:40:53 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return new MavlinkStreamAttitudeTarget(mavlink);
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-08-10 01:24:04 +02:00
|
|
|
return MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-08-10 01:24:04 +02:00
|
|
|
MavlinkOrbSubscription *_att_sp_sub;
|
|
|
|
|
MavlinkOrbSubscription *_att_rates_sp_sub;
|
2018-03-25 14:21:09 -04:00
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
uint64_t _att_sp_time;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2014-08-10 01:24:04 +02:00
|
|
|
MavlinkStreamAttitudeTarget(MavlinkStreamAttitudeTarget &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamAttitudeTarget &operator = (const MavlinkStreamAttitudeTarget &);
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
protected:
|
2014-08-10 01:24:04 +02:00
|
|
|
explicit MavlinkStreamAttitudeTarget(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_att_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude_setpoint))),
|
|
|
|
|
_att_rates_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_rates_setpoint))),
|
2018-03-25 14:21:09 -04:00
|
|
|
_att_sp_time(0)
|
2014-07-28 17:40:53 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_attitude_setpoint_s att_sp;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
if (_att_sp_sub->update(&_att_sp_time, &att_sp)) {
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_rates_setpoint_s att_rates_sp = {};
|
|
|
|
|
_att_rates_sp_sub->update(&att_rates_sp);
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_attitude_target_t msg = {};
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
msg.time_boot_ms = att_sp.timestamp / 1000;
|
2017-01-04 17:45:32 -05:00
|
|
|
|
2016-10-18 09:46:12 +02:00
|
|
|
if (att_sp.q_d_valid) {
|
|
|
|
|
memcpy(&msg.q[0], &att_sp.q_d[0], sizeof(msg.q));
|
2017-01-04 17:45:32 -05:00
|
|
|
|
2016-10-18 09:46:12 +02:00
|
|
|
} else {
|
|
|
|
|
mavlink_euler_to_quaternion(att_sp.roll_body, att_sp.pitch_body, att_sp.yaw_body, msg.q);
|
|
|
|
|
}
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
msg.body_roll_rate = att_rates_sp.roll;
|
|
|
|
|
msg.body_pitch_rate = att_rates_sp.pitch;
|
|
|
|
|
msg.body_yaw_rate = att_rates_sp.yaw;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2014-08-10 01:24:04 +02:00
|
|
|
msg.thrust = att_sp.thrust;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_attitude_target_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-07-17 09:12:11 +02:00
|
|
|
class MavlinkStreamRCChannels : public MavlinkStream
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2015-07-17 09:12:11 +02:00
|
|
|
return MavlinkStreamRCChannels::get_name_static();
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2015-07-17 09:12:11 +02:00
|
|
|
return "RC_CHANNELS";
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
2015-07-17 09:12:11 +02:00
|
|
|
return MAVLINK_MSG_ID_RC_CHANNELS;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 17:40:53 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2015-07-17 09:12:11 +02:00
|
|
|
return new MavlinkStreamRCChannels(mavlink);
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2015-07-17 09:12:11 +02:00
|
|
|
return _rc_sub->is_published() ? (MAVLINK_MSG_ID_RC_CHANNELS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_rc_sub;
|
|
|
|
|
uint64_t _rc_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2015-07-17 09:12:11 +02:00
|
|
|
MavlinkStreamRCChannels(MavlinkStreamRCChannels &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamRCChannels &operator = (const MavlinkStreamRCChannels &);
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
protected:
|
2015-07-17 09:12:11 +02:00
|
|
|
explicit MavlinkStreamRCChannels(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-28 17:40:53 +02:00
|
|
|
_rc_sub(_mavlink->add_orb_subscription(ORB_ID(input_rc))),
|
|
|
|
|
_rc_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
rc_input_values rc;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
if (_rc_sub->update(&_rc_time, &rc)) {
|
|
|
|
|
|
2015-04-21 06:58:03 +02:00
|
|
|
/* send RC channel data and RSSI */
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_rc_channels_t msg = {};
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2016-08-15 09:03:27 +02:00
|
|
|
msg.time_boot_ms = rc.timestamp / 1000;
|
2014-07-28 17:40:53 +02:00
|
|
|
msg.chancount = rc.channel_count;
|
|
|
|
|
msg.chan1_raw = (rc.channel_count > 0) ? rc.values[0] : UINT16_MAX;
|
|
|
|
|
msg.chan2_raw = (rc.channel_count > 1) ? rc.values[1] : UINT16_MAX;
|
|
|
|
|
msg.chan3_raw = (rc.channel_count > 2) ? rc.values[2] : UINT16_MAX;
|
|
|
|
|
msg.chan4_raw = (rc.channel_count > 3) ? rc.values[3] : UINT16_MAX;
|
|
|
|
|
msg.chan5_raw = (rc.channel_count > 4) ? rc.values[4] : UINT16_MAX;
|
|
|
|
|
msg.chan6_raw = (rc.channel_count > 5) ? rc.values[5] : UINT16_MAX;
|
|
|
|
|
msg.chan7_raw = (rc.channel_count > 6) ? rc.values[6] : UINT16_MAX;
|
|
|
|
|
msg.chan8_raw = (rc.channel_count > 7) ? rc.values[7] : UINT16_MAX;
|
|
|
|
|
msg.chan9_raw = (rc.channel_count > 8) ? rc.values[8] : UINT16_MAX;
|
|
|
|
|
msg.chan10_raw = (rc.channel_count > 9) ? rc.values[9] : UINT16_MAX;
|
|
|
|
|
msg.chan11_raw = (rc.channel_count > 10) ? rc.values[10] : UINT16_MAX;
|
|
|
|
|
msg.chan12_raw = (rc.channel_count > 11) ? rc.values[11] : UINT16_MAX;
|
|
|
|
|
msg.chan13_raw = (rc.channel_count > 12) ? rc.values[12] : UINT16_MAX;
|
|
|
|
|
msg.chan14_raw = (rc.channel_count > 13) ? rc.values[13] : UINT16_MAX;
|
|
|
|
|
msg.chan15_raw = (rc.channel_count > 14) ? rc.values[14] : UINT16_MAX;
|
|
|
|
|
msg.chan16_raw = (rc.channel_count > 15) ? rc.values[15] : UINT16_MAX;
|
|
|
|
|
msg.chan17_raw = (rc.channel_count > 16) ? rc.values[16] : UINT16_MAX;
|
|
|
|
|
msg.chan18_raw = (rc.channel_count > 17) ? rc.values[17] : UINT16_MAX;
|
2014-11-01 16:54:11 +01:00
|
|
|
|
2016-04-23 16:33:25 +02:00
|
|
|
msg.rssi = (rc.channel_count > 0) ? rc.rssi : 0;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_rc_channels_send_struct(_mavlink->get_channel(), &msg);
|
2016-01-04 12:35:23 +01:00
|
|
|
|
|
|
|
|
/* send override message - harmless if connected to GCS, allows to connect a board to a Linux system */
|
|
|
|
|
/* http://mavlink.org/messages/common#RC_CHANNELS_OVERRIDE */
|
|
|
|
|
mavlink_rc_channels_override_t over;
|
|
|
|
|
over.target_system = mavlink_system.sysid;
|
|
|
|
|
over.target_component = 0;
|
|
|
|
|
over.chan1_raw = msg.chan1_raw;
|
|
|
|
|
over.chan2_raw = msg.chan2_raw;
|
|
|
|
|
over.chan3_raw = msg.chan3_raw;
|
|
|
|
|
over.chan4_raw = msg.chan4_raw;
|
|
|
|
|
over.chan5_raw = msg.chan5_raw;
|
|
|
|
|
over.chan6_raw = msg.chan6_raw;
|
|
|
|
|
over.chan7_raw = msg.chan7_raw;
|
|
|
|
|
over.chan8_raw = msg.chan8_raw;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_rc_channels_override_send_struct(_mavlink->get_channel(), &over);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamManualControl : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamManualControl::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "MANUAL_CONTROL";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_MANUAL_CONTROL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 17:40:53 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamManualControl(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-07-28 20:30:58 +02:00
|
|
|
return _manual_sub->is_published() ? (MAVLINK_MSG_ID_MANUAL_CONTROL_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_manual_sub;
|
|
|
|
|
uint64_t _manual_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamManualControl(MavlinkStreamManualControl &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamManualControl &operator = (const MavlinkStreamManualControl &);
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamManualControl(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_manual_sub(_mavlink->add_orb_subscription(ORB_ID(manual_control_setpoint))),
|
|
|
|
|
_manual_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 17:40:53 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
manual_control_setpoint_s manual;
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
if (_manual_sub->update(&_manual_time, &manual)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_manual_control_t msg = {};
|
2014-07-28 17:40:53 +02:00
|
|
|
|
|
|
|
|
msg.target = mavlink_system.sysid;
|
|
|
|
|
msg.x = manual.x * 1000;
|
|
|
|
|
msg.y = manual.y * 1000;
|
|
|
|
|
msg.z = manual.z * 1000;
|
|
|
|
|
msg.r = manual.r * 1000;
|
2015-09-04 14:56:42 +02:00
|
|
|
unsigned shift = 2;
|
2014-07-28 17:40:53 +02:00
|
|
|
msg.buttons = 0;
|
2015-09-04 14:56:42 +02:00
|
|
|
msg.buttons |= (manual.mode_switch << (shift * 0));
|
|
|
|
|
msg.buttons |= (manual.return_switch << (shift * 1));
|
|
|
|
|
msg.buttons |= (manual.posctl_switch << (shift * 2));
|
|
|
|
|
msg.buttons |= (manual.loiter_switch << (shift * 3));
|
|
|
|
|
msg.buttons |= (manual.acro_switch << (shift * 4));
|
|
|
|
|
msg.buttons |= (manual.offboard_switch << (shift * 5));
|
2014-07-28 17:40:53 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_manual_control_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 17:40:53 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-30 16:39:02 +01:00
|
|
|
class MavlinkStreamOpticalFlowRad : public MavlinkStream
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2014-10-30 16:39:02 +01:00
|
|
|
return MavlinkStreamOpticalFlowRad::get_name_static();
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2014-10-30 16:39:02 +01:00
|
|
|
return "OPTICAL_FLOW_RAD";
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
2014-10-30 16:39:02 +01:00
|
|
|
return MAVLINK_MSG_ID_OPTICAL_FLOW_RAD;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 20:30:58 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2014-10-30 16:39:02 +01:00
|
|
|
return new MavlinkStreamOpticalFlowRad(mavlink);
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2014-10-30 16:39:02 +01:00
|
|
|
return _flow_sub->is_published() ? (MAVLINK_MSG_ID_OPTICAL_FLOW_RAD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_flow_sub;
|
|
|
|
|
uint64_t _flow_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2014-10-30 16:39:02 +01:00
|
|
|
MavlinkStreamOpticalFlowRad(MavlinkStreamOpticalFlowRad &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamOpticalFlowRad &operator = (const MavlinkStreamOpticalFlowRad &);
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
protected:
|
2014-10-30 16:39:02 +01:00
|
|
|
explicit MavlinkStreamOpticalFlowRad(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2014-07-28 20:30:58 +02:00
|
|
|
_flow_sub(_mavlink->add_orb_subscription(ORB_ID(optical_flow))),
|
|
|
|
|
_flow_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
optical_flow_s flow;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
if (_flow_sub->update(&_flow_time, &flow)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_optical_flow_rad_t msg = {};
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
msg.time_usec = flow.timestamp;
|
|
|
|
|
msg.sensor_id = flow.sensor_id;
|
2014-10-30 16:39:02 +01:00
|
|
|
msg.integrated_x = flow.pixel_flow_x_integral;
|
|
|
|
|
msg.integrated_y = flow.pixel_flow_y_integral;
|
|
|
|
|
msg.integrated_xgyro = flow.gyro_x_rate_integral;
|
|
|
|
|
msg.integrated_ygyro = flow.gyro_y_rate_integral;
|
|
|
|
|
msg.integrated_zgyro = flow.gyro_z_rate_integral;
|
|
|
|
|
msg.distance = flow.ground_distance_m;
|
2014-07-28 20:30:58 +02:00
|
|
|
msg.quality = flow.quality;
|
2014-10-30 16:39:02 +01:00
|
|
|
msg.integration_time_us = flow.integration_timespan;
|
|
|
|
|
msg.sensor_id = flow.sensor_id;
|
|
|
|
|
msg.time_delta_distance_us = flow.time_since_last_sonar_update;
|
|
|
|
|
msg.temperature = flow.gyro_temperature;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_optical_flow_rad_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamNamedValueFloat : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamNamedValueFloat::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "NAMED_VALUE_FLOAT";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_NAMED_VALUE_FLOAT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 20:30:58 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamNamedValueFloat(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return (_debug_time > 0) ? MAVLINK_MSG_ID_NAMED_VALUE_FLOAT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_debug_sub;
|
|
|
|
|
uint64_t _debug_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamNamedValueFloat(MavlinkStreamNamedValueFloat &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamNamedValueFloat &operator = (const MavlinkStreamNamedValueFloat &);
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamNamedValueFloat(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_debug_sub(_mavlink->add_orb_subscription(ORB_ID(debug_key_value))),
|
|
|
|
|
_debug_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
2017-07-29 11:39:51 +02:00
|
|
|
struct debug_key_value_s debug;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
if (_debug_sub->update(&_debug_time, &debug)) {
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_named_value_float_t msg = {};
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
msg.time_boot_ms = debug.timestamp_ms;
|
|
|
|
|
memcpy(msg.name, debug.key, sizeof(msg.name));
|
|
|
|
|
/* enforce null termination */
|
|
|
|
|
msg.name[sizeof(msg.name) - 1] = '\0';
|
|
|
|
|
msg.value = debug.value;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_named_value_float_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-07 15:37:25 +02:00
|
|
|
class MavlinkStreamDebug : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamDebug::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "DEBUG";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_DEBUG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamDebug(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return (_debug_time > 0) ? MAVLINK_MSG_ID_DEBUG_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_debug_sub;
|
|
|
|
|
uint64_t _debug_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamDebug(MavlinkStreamDebug &);
|
|
|
|
|
MavlinkStreamDebug &operator = (const MavlinkStreamDebug &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamDebug(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_debug_sub(_mavlink->add_orb_subscription(ORB_ID(debug_value))),
|
|
|
|
|
_debug_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-08-16 10:32:32 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2017-06-07 15:37:25 +02:00
|
|
|
{
|
|
|
|
|
struct debug_value_s debug = {};
|
|
|
|
|
|
|
|
|
|
if (_debug_sub->update(&_debug_time, &debug)) {
|
|
|
|
|
mavlink_debug_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.time_boot_ms = debug.timestamp_ms;
|
|
|
|
|
msg.ind = debug.ind;
|
|
|
|
|
msg.value = debug.value;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_debug_send_struct(_mavlink->get_channel(), &msg);
|
2017-08-16 10:32:32 +02:00
|
|
|
|
|
|
|
|
return true;
|
2017-06-07 15:37:25 +02:00
|
|
|
}
|
2017-08-16 10:32:32 +02:00
|
|
|
|
|
|
|
|
return false;
|
2017-06-07 15:37:25 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-07 15:45:55 +02:00
|
|
|
class MavlinkStreamDebugVect : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamDebugVect::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "DEBUG_VECT";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_DEBUG_VECT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamDebugVect(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return (_debug_time > 0) ? MAVLINK_MSG_ID_DEBUG_VECT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_debug_sub;
|
|
|
|
|
uint64_t _debug_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamDebugVect(MavlinkStreamDebugVect &);
|
|
|
|
|
MavlinkStreamDebugVect &operator = (const MavlinkStreamDebugVect &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamDebugVect(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_debug_sub(_mavlink->add_orb_subscription(ORB_ID(debug_vect))),
|
|
|
|
|
_debug_time(0)
|
|
|
|
|
{}
|
|
|
|
|
|
2017-08-16 10:32:32 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2017-06-07 15:45:55 +02:00
|
|
|
{
|
|
|
|
|
struct debug_vect_s debug = {};
|
|
|
|
|
|
|
|
|
|
if (_debug_sub->update(&_debug_time, &debug)) {
|
|
|
|
|
mavlink_debug_vect_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.time_usec = debug.timestamp_us;
|
|
|
|
|
memcpy(msg.name, debug.name, sizeof(msg.name));
|
|
|
|
|
/* enforce null termination */
|
|
|
|
|
msg.name[sizeof(msg.name) - 1] = '\0';
|
|
|
|
|
msg.x = debug.x;
|
|
|
|
|
msg.y = debug.y;
|
|
|
|
|
msg.z = debug.z;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_debug_vect_send_struct(_mavlink->get_channel(), &msg);
|
2017-08-16 10:32:32 +02:00
|
|
|
|
|
|
|
|
return true;
|
2017-06-07 15:45:55 +02:00
|
|
|
}
|
2017-08-16 10:32:32 +02:00
|
|
|
|
|
|
|
|
return false;
|
2017-06-07 15:45:55 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-22 21:45:34 -04:00
|
|
|
class MavlinkStreamNavControllerOutput : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamNavControllerOutput::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "NAV_CONTROLLER_OUTPUT";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-04-22 21:45:34 -04:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2016-04-22 21:45:34 -04:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamNavControllerOutput(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return (_fw_pos_ctrl_status_sub->is_published()) ?
|
2018-01-05 10:16:35 -08:00
|
|
|
MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2016-04-22 21:45:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_fw_pos_ctrl_status_sub;
|
|
|
|
|
MavlinkOrbSubscription *_tecs_status_sub;
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
uint64_t _fw_pos_ctrl_status_timestamp{0};
|
|
|
|
|
uint64_t _tecs_status_timestamp{0};
|
|
|
|
|
|
2016-04-22 21:45:34 -04:00
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamNavControllerOutput(MavlinkStreamNavControllerOutput &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamNavControllerOutput &operator = (const MavlinkStreamNavControllerOutput &);
|
2016-04-22 21:45:34 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamNavControllerOutput(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_fw_pos_ctrl_status_sub(_mavlink->add_orb_subscription(ORB_ID(fw_pos_ctrl_status))),
|
|
|
|
|
_tecs_status_sub(_mavlink->add_orb_subscription(ORB_ID(tecs_status)))
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-04-22 21:45:34 -04:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
fw_pos_ctrl_status_s _fw_pos_ctrl_status = {};
|
|
|
|
|
tecs_status_s _tecs_status = {};
|
2016-04-22 21:45:34 -04:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
bool updated = false;
|
|
|
|
|
updated |= _fw_pos_ctrl_status_sub->update(&_fw_pos_ctrl_status_timestamp, &_fw_pos_ctrl_status);
|
|
|
|
|
updated |= _tecs_status_sub->update(&_tecs_status_timestamp, &_tecs_status);
|
2016-04-22 21:45:34 -04:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
if (updated) {
|
2016-04-22 21:45:34 -04:00
|
|
|
mavlink_nav_controller_output_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.nav_roll = math::degrees(_fw_pos_ctrl_status.nav_roll);
|
|
|
|
|
msg.nav_pitch = math::degrees(_fw_pos_ctrl_status.nav_pitch);
|
|
|
|
|
msg.nav_bearing = (int16_t)math::degrees(_fw_pos_ctrl_status.nav_bearing);
|
|
|
|
|
msg.target_bearing = (int16_t)math::degrees(_fw_pos_ctrl_status.target_bearing);
|
|
|
|
|
msg.wp_dist = (uint16_t)_fw_pos_ctrl_status.wp_dist;
|
|
|
|
|
msg.xtrack_error = _fw_pos_ctrl_status.xtrack_error;
|
|
|
|
|
msg.alt_error = _tecs_status.altitude_filtered - _tecs_status.altitudeSp;
|
|
|
|
|
msg.aspd_error = _tecs_status.airspeed_filtered - _tecs_status.airspeedSp;
|
|
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_nav_controller_output_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2016-04-22 21:45:34 -04:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2016-04-22 21:45:34 -04:00
|
|
|
}
|
|
|
|
|
};
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
class MavlinkStreamCameraCapture : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamCameraCapture::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "CAMERA_CAPTURE";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 20:30:58 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamCameraCapture(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_COMMAND_LONG_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_status_sub;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamCameraCapture(MavlinkStreamCameraCapture &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamCameraCapture &operator = (const MavlinkStreamCameraCapture &);
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamCameraCapture(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status)))
|
|
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_status_s status;
|
2017-07-29 11:39:51 +02:00
|
|
|
|
|
|
|
|
if (_status_sub->update(&status)) {
|
|
|
|
|
|
|
|
|
|
mavlink_command_long_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.target_system = 0;
|
|
|
|
|
msg.target_component = MAV_COMP_ID_ALL;
|
|
|
|
|
msg.command = MAV_CMD_DO_CONTROL_VIDEO;
|
|
|
|
|
msg.confirmation = 0;
|
|
|
|
|
msg.param1 = 0;
|
|
|
|
|
msg.param2 = 0;
|
|
|
|
|
msg.param3 = 0;
|
|
|
|
|
/* set camera capture ON/OFF depending on arming state */
|
2018-03-27 16:04:17 -04:00
|
|
|
msg.param4 = (status.arming_state == vehicle_status_s::ARMING_STATE_ARMED) ? 1 : 0;
|
2017-07-29 11:39:51 +02:00
|
|
|
msg.param5 = 0;
|
|
|
|
|
msg.param6 = 0;
|
|
|
|
|
msg.param7 = 0;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_command_long_send_struct(_mavlink->get_channel(), &msg);
|
|
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MavlinkStreamDistanceSensor : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamDistanceSensor::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "DISTANCE_SENSOR";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_DISTANCE_SENSOR;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2014-07-28 20:30:58 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamDistanceSensor(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2015-05-20 00:54:36 +01:00
|
|
|
return _distance_sensor_sub->is_published() ? (MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2015-05-20 00:54:36 +01:00
|
|
|
MavlinkOrbSubscription *_distance_sensor_sub;
|
|
|
|
|
uint64_t _dist_sensor_time;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamDistanceSensor(MavlinkStreamDistanceSensor &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamDistanceSensor &operator = (const MavlinkStreamDistanceSensor &);
|
2014-07-28 20:30:58 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamDistanceSensor(Mavlink *mavlink) : MavlinkStream(mavlink),
|
2015-05-20 00:54:36 +01:00
|
|
|
_distance_sensor_sub(_mavlink->add_orb_subscription(ORB_ID(distance_sensor))),
|
|
|
|
|
_dist_sensor_time(0)
|
2014-07-28 20:30:58 +02:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2014-07-28 20:30:58 +02:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
distance_sensor_s dist_sensor;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
2015-05-20 00:54:36 +01:00
|
|
|
if (_distance_sensor_sub->update(&_dist_sensor_time, &dist_sensor)) {
|
2014-07-28 20:30:58 +02:00
|
|
|
|
2017-02-17 12:36:52 -05:00
|
|
|
mavlink_distance_sensor_t msg = {};
|
2014-07-28 20:30:58 +02:00
|
|
|
|
2015-05-24 15:58:44 +01:00
|
|
|
msg.time_boot_ms = dist_sensor.timestamp / 1000; /* us to ms */
|
|
|
|
|
|
|
|
|
|
/* TODO: use correct ID here */
|
|
|
|
|
msg.id = 0;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
2015-05-20 00:54:36 +01:00
|
|
|
switch (dist_sensor.type) {
|
|
|
|
|
case MAV_DISTANCE_SENSOR_ULTRASOUND:
|
2015-05-20 12:51:20 +01:00
|
|
|
msg.type = MAV_DISTANCE_SENSOR_ULTRASOUND;
|
2014-07-28 20:30:58 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-05-20 00:54:36 +01:00
|
|
|
case MAV_DISTANCE_SENSOR_LASER:
|
|
|
|
|
msg.type = MAV_DISTANCE_SENSOR_LASER;
|
|
|
|
|
break;
|
|
|
|
|
|
2015-05-21 12:41:41 +01:00
|
|
|
case MAV_DISTANCE_SENSOR_INFRARED:
|
2015-05-20 00:54:36 +01:00
|
|
|
msg.type = MAV_DISTANCE_SENSOR_INFRARED;
|
2015-05-21 12:41:41 +01:00
|
|
|
break;
|
2015-05-20 00:54:36 +01:00
|
|
|
|
2014-07-28 20:30:58 +02:00
|
|
|
default:
|
|
|
|
|
msg.type = MAV_DISTANCE_SENSOR_LASER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-20 00:54:36 +01:00
|
|
|
msg.orientation = dist_sensor.orientation;
|
2015-05-24 15:58:44 +01:00
|
|
|
msg.min_distance = dist_sensor.min_distance * 100.0f; /* m to cm */
|
|
|
|
|
msg.max_distance = dist_sensor.max_distance * 100.0f; /* m to cm */
|
|
|
|
|
msg.current_distance = dist_sensor.current_distance * 100.0f; /* m to cm */
|
2015-05-20 00:54:36 +01:00
|
|
|
msg.covariance = dist_sensor.covariance;
|
2014-07-28 20:30:58 +02:00
|
|
|
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_distance_sensor_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2014-07-28 20:30:58 +02:00
|
|
|
}
|
|
|
|
|
};
|
2014-04-13 23:30:09 +02:00
|
|
|
|
2015-10-06 18:50:21 +02:00
|
|
|
class MavlinkStreamExtendedSysState : public MavlinkStream
|
2015-08-11 20:25:04 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2015-10-06 18:50:21 +02:00
|
|
|
return MavlinkStreamExtendedSysState::get_name_static();
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2015-10-06 18:50:21 +02:00
|
|
|
return "EXTENDED_SYS_STATE";
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2015-08-11 20:25:04 +02:00
|
|
|
{
|
2015-10-06 18:50:21 +02:00
|
|
|
return MAVLINK_MSG_ID_EXTENDED_SYS_STATE;
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2015-08-11 20:25:04 +02:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2015-10-06 18:50:21 +02:00
|
|
|
return new MavlinkStreamExtendedSysState(mavlink);
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2015-10-06 18:50:21 +02:00
|
|
|
return MAVLINK_MSG_ID_EXTENDED_SYS_STATE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_status_sub;
|
2015-10-06 18:50:21 +02:00
|
|
|
MavlinkOrbSubscription *_landed_sub;
|
2017-04-17 09:31:49 -04:00
|
|
|
MavlinkOrbSubscription *_pos_sp_triplet_sub;
|
|
|
|
|
MavlinkOrbSubscription *_control_mode_sub;
|
2015-10-06 18:50:21 +02:00
|
|
|
mavlink_extended_sys_state_t _msg;
|
2015-08-11 20:25:04 +02:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2015-10-06 18:50:21 +02:00
|
|
|
MavlinkStreamExtendedSysState(MavlinkStreamExtendedSysState &);
|
|
|
|
|
MavlinkStreamExtendedSysState &operator = (const MavlinkStreamExtendedSysState &);
|
2015-08-11 20:25:04 +02:00
|
|
|
|
|
|
|
|
protected:
|
2015-10-06 18:50:21 +02:00
|
|
|
explicit MavlinkStreamExtendedSysState(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))),
|
|
|
|
|
_landed_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_land_detected))),
|
2017-04-17 09:31:49 -04:00
|
|
|
_pos_sp_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet))),
|
|
|
|
|
_control_mode_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_control_mode))),
|
2017-02-17 12:36:52 -05:00
|
|
|
_msg()
|
2015-10-06 18:50:21 +02:00
|
|
|
{
|
|
|
|
|
_msg.vtol_state = MAV_VTOL_STATE_UNDEFINED;
|
2018-02-18 18:09:16 -05:00
|
|
|
_msg.landed_state = MAV_LANDED_STATE_ON_GROUND;
|
2015-10-06 18:50:21 +02:00
|
|
|
}
|
2015-08-11 20:25:04 +02:00
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2015-08-11 20:25:04 +02:00
|
|
|
{
|
2015-10-06 18:50:21 +02:00
|
|
|
bool updated = false;
|
2015-08-11 20:25:04 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_status_s status;
|
|
|
|
|
|
2015-08-11 20:25:04 +02:00
|
|
|
if (_status_sub->update(&status)) {
|
2015-10-06 18:50:21 +02:00
|
|
|
updated = true;
|
2015-08-11 20:25:04 +02:00
|
|
|
|
2015-08-18 11:02:52 +02:00
|
|
|
if (status.is_vtol) {
|
2016-05-26 07:06:06 +02:00
|
|
|
if (!status.in_transition_mode && status.is_rotary_wing) {
|
|
|
|
|
_msg.vtol_state = MAV_VTOL_STATE_MC;
|
2015-08-18 11:02:52 +02:00
|
|
|
|
2017-01-04 17:45:32 -05:00
|
|
|
} else if (!status.in_transition_mode) {
|
2016-05-26 07:06:06 +02:00
|
|
|
_msg.vtol_state = MAV_VTOL_STATE_FW;
|
2015-08-18 11:02:52 +02:00
|
|
|
|
2016-05-26 07:06:06 +02:00
|
|
|
} else if (status.in_transition_mode && status.in_transition_to_fw) {
|
|
|
|
|
_msg.vtol_state = MAV_VTOL_STATE_TRANSITION_TO_FW;
|
2015-08-18 11:02:52 +02:00
|
|
|
|
2016-05-26 07:06:06 +02:00
|
|
|
} else if (status.in_transition_mode) {
|
|
|
|
|
_msg.vtol_state = MAV_VTOL_STATE_TRANSITION_TO_MC;
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
2015-10-06 18:50:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_land_detected_s land_detected;
|
|
|
|
|
|
2015-10-06 18:50:21 +02:00
|
|
|
if (_landed_sub->update(&land_detected)) {
|
|
|
|
|
updated = true;
|
2015-08-18 11:02:52 +02:00
|
|
|
|
2015-10-06 18:50:21 +02:00
|
|
|
if (land_detected.landed) {
|
|
|
|
|
_msg.landed_state = MAV_LANDED_STATE_ON_GROUND;
|
2016-03-15 18:21:52 +00:00
|
|
|
|
2017-04-17 09:31:49 -04:00
|
|
|
} else if (!land_detected.landed) {
|
2015-10-06 18:50:21 +02:00
|
|
|
_msg.landed_state = MAV_LANDED_STATE_IN_AIR;
|
2017-04-17 09:31:49 -04:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_control_mode_s control_mode;
|
|
|
|
|
position_setpoint_triplet_s pos_sp_triplet;
|
2017-04-17 09:31:49 -04:00
|
|
|
|
|
|
|
|
if (_control_mode_sub->update(&control_mode) && _pos_sp_triplet_sub->update(&pos_sp_triplet)) {
|
|
|
|
|
if (control_mode.flag_control_auto_enabled && pos_sp_triplet.current.valid) {
|
|
|
|
|
if (pos_sp_triplet.current.type == position_setpoint_s::SETPOINT_TYPE_TAKEOFF) {
|
|
|
|
|
_msg.landed_state = MAV_LANDED_STATE_TAKEOFF;
|
|
|
|
|
|
|
|
|
|
} else if (pos_sp_triplet.current.type == position_setpoint_s::SETPOINT_TYPE_LAND) {
|
|
|
|
|
_msg.landed_state = MAV_LANDED_STATE_LANDING;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
2015-10-06 18:50:21 +02:00
|
|
|
}
|
2015-08-11 20:25:04 +02:00
|
|
|
|
2015-10-06 18:50:21 +02:00
|
|
|
if (updated) {
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_extended_sys_state_send_struct(_mavlink->get_channel(), &_msg);
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return updated;
|
2015-08-11 20:25:04 +02:00
|
|
|
}
|
|
|
|
|
};
|
2014-05-13 16:04:02 +02:00
|
|
|
|
2015-11-18 23:55:37 +01:00
|
|
|
class MavlinkStreamAltitude : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamAltitude::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "ALTITUDE";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2015-11-18 23:55:37 +01:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_ALTITUDE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-07-12 13:56:38 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-15 18:41:39 -07:00
|
|
|
|
2015-11-18 23:55:37 +01:00
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamAltitude(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return (_local_pos_time > 0) ? MAVLINK_MSG_ID_ALTITUDE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2015-11-18 23:55:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_local_pos_sub;
|
|
|
|
|
MavlinkOrbSubscription *_home_sub;
|
2018-02-18 11:44:21 -05:00
|
|
|
MavlinkOrbSubscription *_air_data_sub;
|
2018-03-25 12:52:57 -04:00
|
|
|
|
|
|
|
|
uint64_t _local_pos_time{0};
|
2016-01-17 16:30:02 +01:00
|
|
|
|
2015-11-18 23:55:37 +01:00
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamAltitude(MavlinkStreamAltitude &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamAltitude &operator = (const MavlinkStreamAltitude &);
|
2015-11-18 23:55:37 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamAltitude(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_local_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))),
|
|
|
|
|
_home_sub(_mavlink->add_orb_subscription(ORB_ID(home_position))),
|
2018-02-18 11:44:21 -05:00
|
|
|
_air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data)))
|
2015-11-18 23:55:37 +01:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2015-11-18 23:55:37 +01:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
mavlink_altitude_t msg = {};
|
2015-11-23 21:19:24 +01:00
|
|
|
|
2018-03-25 12:52:57 -04:00
|
|
|
msg.altitude_monotonic = NAN;
|
|
|
|
|
msg.altitude_amsl = NAN;
|
|
|
|
|
msg.altitude_local = NAN;
|
|
|
|
|
msg.altitude_relative = NAN;
|
|
|
|
|
msg.altitude_terrain = NAN;
|
|
|
|
|
msg.bottom_clearance = NAN;
|
2017-01-04 17:45:32 -05:00
|
|
|
|
2018-03-25 12:52:57 -04:00
|
|
|
// always update monotonic altitude
|
2018-02-18 11:44:21 -05:00
|
|
|
bool air_data_updated = false;
|
|
|
|
|
vehicle_air_data_s air_data = {};
|
|
|
|
|
_air_data_sub->update(&air_data);
|
2015-11-18 23:55:37 +01:00
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
if (air_data.timestamp > 0) {
|
|
|
|
|
msg.altitude_monotonic = air_data.baro_alt_meter;
|
2016-08-26 23:43:33 +02:00
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
air_data_updated = true;
|
2016-08-15 13:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
bool lpos_updated = false;
|
|
|
|
|
|
|
|
|
|
vehicle_local_position_s local_pos;
|
2016-08-27 23:50:24 -04:00
|
|
|
|
2018-03-25 12:52:57 -04:00
|
|
|
if (_local_pos_sub->update(&_local_pos_time, &local_pos)) {
|
|
|
|
|
|
|
|
|
|
if (local_pos.z_valid) {
|
|
|
|
|
if (local_pos.z_global) {
|
|
|
|
|
msg.altitude_amsl = -local_pos.z + local_pos.ref_alt;
|
2016-08-27 23:50:24 -04:00
|
|
|
|
|
|
|
|
} else {
|
2018-03-25 12:52:57 -04:00
|
|
|
msg.altitude_amsl = msg.altitude_monotonic;
|
2016-08-27 23:50:24 -04:00
|
|
|
}
|
2016-08-15 13:07:29 +02:00
|
|
|
|
2018-03-25 12:52:57 -04:00
|
|
|
msg.altitude_local = -local_pos.z;
|
2016-08-27 23:50:24 -04:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
home_position_s home = {};
|
2018-03-25 12:52:57 -04:00
|
|
|
_home_sub->update(&home);
|
2016-08-27 23:50:24 -04:00
|
|
|
|
2018-03-25 12:52:57 -04:00
|
|
|
if (home.valid_alt) {
|
|
|
|
|
msg.altitude_relative = -(local_pos.z - home.z);
|
2016-08-27 23:50:24 -04:00
|
|
|
|
2018-03-25 12:52:57 -04:00
|
|
|
} else {
|
|
|
|
|
msg.altitude_relative = -local_pos.z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (local_pos.dist_bottom_valid) {
|
|
|
|
|
msg.altitude_terrain = -local_pos.z - local_pos.dist_bottom;
|
|
|
|
|
msg.bottom_clearance = local_pos.dist_bottom;
|
|
|
|
|
}
|
2016-08-27 23:50:24 -04:00
|
|
|
}
|
2018-03-25 12:52:57 -04:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
lpos_updated = true;
|
2016-08-15 13:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
// local position timeout after 10 ms
|
|
|
|
|
// avoid publishing only baro altitude_monotonic if possible
|
|
|
|
|
bool lpos_timeout = (hrt_elapsed_time(&_local_pos_time) > 10000);
|
|
|
|
|
|
2018-02-18 11:44:21 -05:00
|
|
|
if (lpos_updated || (air_data_updated && lpos_timeout)) {
|
2016-08-15 13:07:29 +02:00
|
|
|
msg.time_usec = hrt_absolute_time();
|
2016-05-14 14:17:30 +02:00
|
|
|
mavlink_msg_altitude_send_struct(_mavlink->get_channel(), &msg);
|
2018-03-25 14:21:09 -04:00
|
|
|
|
|
|
|
|
return true;
|
2015-11-18 23:55:37 +01:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
return false;
|
2015-11-18 23:55:37 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-27 10:16:24 -04:00
|
|
|
class MavlinkStreamWind : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamWind::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return "WIND_COV";
|
2016-06-27 10:16:24 -04:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
static uint16_t get_id_static()
|
2016-06-27 10:16:24 -04:00
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_WIND_COV;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 11:24:21 +01:00
|
|
|
uint16_t get_id()
|
2016-08-26 23:43:33 +02:00
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
2016-06-27 10:16:24 -04:00
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamWind(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-07-10 17:05:33 +02:00
|
|
|
return (_wind_estimate_time > 0) ? MAVLINK_MSG_ID_WIND_COV_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2016-06-27 10:16:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_wind_estimate_sub;
|
|
|
|
|
uint64_t _wind_estimate_time;
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
MavlinkOrbSubscription *_local_pos_sub;
|
2016-06-27 10:16:24 -04:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamWind(MavlinkStreamWind &);
|
2016-08-26 23:43:33 +02:00
|
|
|
MavlinkStreamWind &operator = (const MavlinkStreamWind &);
|
2016-06-27 10:16:24 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamWind(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_wind_estimate_sub(_mavlink->add_orb_subscription(ORB_ID(wind_estimate))),
|
|
|
|
|
_wind_estimate_time(0),
|
2018-03-25 14:21:09 -04:00
|
|
|
_local_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position)))
|
2016-06-27 10:16:24 -04:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-06-27 10:16:24 -04:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
wind_estimate_s wind_estimate;
|
2016-06-27 10:16:24 -04:00
|
|
|
|
2017-07-29 11:39:51 +02:00
|
|
|
if (_wind_estimate_sub->update(&_wind_estimate_time, &wind_estimate)) {
|
2016-06-27 10:16:24 -04:00
|
|
|
|
2016-08-15 13:07:29 +02:00
|
|
|
mavlink_wind_cov_t msg = {};
|
2016-06-27 10:16:24 -04:00
|
|
|
|
|
|
|
|
msg.time_usec = wind_estimate.timestamp;
|
|
|
|
|
|
|
|
|
|
msg.wind_x = wind_estimate.windspeed_north;
|
|
|
|
|
msg.wind_y = wind_estimate.windspeed_east;
|
|
|
|
|
msg.wind_z = 0.0f;
|
|
|
|
|
|
2017-09-21 16:24:53 -04:00
|
|
|
msg.var_horiz = wind_estimate.variance_north + wind_estimate.variance_east;
|
2016-06-27 10:16:24 -04:00
|
|
|
msg.var_vert = 0.0f;
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
vehicle_local_position_s lpos = {};
|
|
|
|
|
_local_pos_sub->update(&lpos);
|
|
|
|
|
msg.wind_alt = (lpos.z_valid && lpos.z_global) ? (-lpos.z + lpos.ref_alt) : NAN;
|
2016-06-27 10:16:24 -04:00
|
|
|
|
|
|
|
|
msg.horiz_accuracy = 0.0f;
|
|
|
|
|
msg.vert_accuracy = 0.0f;
|
|
|
|
|
|
|
|
|
|
mavlink_msg_wind_cov_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2016-06-27 10:16:24 -04:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2016-06-27 10:16:24 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-28 18:48:09 +01:00
|
|
|
class MavlinkStreamMountOrientation : public MavlinkStream
|
2016-11-08 11:27:18 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
2016-11-28 18:48:09 +01:00
|
|
|
return MavlinkStreamMountOrientation::get_name_static();
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
2016-11-28 18:48:09 +01:00
|
|
|
return "MOUNT_ORIENTATION";
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
2016-11-28 18:48:09 +01:00
|
|
|
return MAVLINK_MSG_ID_MOUNT_ORIENTATION;
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
2016-11-28 18:48:09 +01:00
|
|
|
return new MavlinkStreamMountOrientation(mavlink);
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
2016-11-28 18:48:09 +01:00
|
|
|
return (_mount_orientation_time > 0) ? MAVLINK_MSG_ID_MOUNT_ORIENTATION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2016-11-28 18:48:09 +01:00
|
|
|
MavlinkOrbSubscription *_mount_orientation_sub;
|
|
|
|
|
uint64_t _mount_orientation_time;
|
2016-11-08 11:27:18 +01:00
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
2016-11-28 18:48:09 +01:00
|
|
|
MavlinkStreamMountOrientation(MavlinkStreamMountOrientation &);
|
|
|
|
|
MavlinkStreamMountOrientation &operator = (const MavlinkStreamMountOrientation &);
|
2016-11-08 11:27:18 +01:00
|
|
|
|
|
|
|
|
protected:
|
2016-11-28 18:48:09 +01:00
|
|
|
explicit MavlinkStreamMountOrientation(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_mount_orientation_sub(_mavlink->add_orb_subscription(ORB_ID(mount_orientation))),
|
|
|
|
|
_mount_orientation_time(0)
|
2016-11-08 11:27:18 +01:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-11-08 11:27:18 +01:00
|
|
|
{
|
2017-07-29 11:39:51 +02:00
|
|
|
struct mount_orientation_s mount_orientation;
|
2016-11-08 11:27:18 +01:00
|
|
|
|
2017-07-29 11:39:51 +02:00
|
|
|
if (_mount_orientation_sub->update(&_mount_orientation_time, &mount_orientation)) {
|
2016-11-08 11:27:18 +01:00
|
|
|
|
2016-11-28 18:48:09 +01:00
|
|
|
mavlink_mount_orientation_t msg = {};
|
2016-11-08 11:27:18 +01:00
|
|
|
|
2016-11-28 18:48:09 +01:00
|
|
|
msg.roll = 180.0f / M_PI_F * mount_orientation.attitude_euler_angle[0];
|
|
|
|
|
msg.pitch = 180.0f / M_PI_F * mount_orientation.attitude_euler_angle[1];
|
|
|
|
|
msg.yaw = 180.0f / M_PI_F * mount_orientation.attitude_euler_angle[2];
|
2016-11-08 11:27:18 +01:00
|
|
|
|
2016-11-28 18:48:09 +01:00
|
|
|
mavlink_msg_mount_orientation_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2016-11-08 11:27:18 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-03 13:42:10 -05:00
|
|
|
class MavlinkStreamGroundTruth : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamGroundTruth::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "GROUND_TRUTH";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_HIL_STATE_QUATERNION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamGroundTruth(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return (_att_time > 0 || _gpos_time > 0) ? MAVLINK_MSG_ID_HIL_STATE_QUATERNION_LEN +
|
2017-01-04 17:45:32 -05:00
|
|
|
MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
|
2016-12-03 13:42:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MavlinkOrbSubscription *_att_sub;
|
|
|
|
|
MavlinkOrbSubscription *_gpos_sub;
|
|
|
|
|
uint64_t _att_time;
|
|
|
|
|
uint64_t _gpos_time;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamGroundTruth(MavlinkStreamGroundTruth &);
|
|
|
|
|
MavlinkStreamGroundTruth &operator = (const MavlinkStreamGroundTruth &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamGroundTruth(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude_groundtruth))),
|
|
|
|
|
_gpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_global_position_groundtruth))),
|
|
|
|
|
_att_time(0),
|
2018-03-25 14:21:09 -04:00
|
|
|
_gpos_time(0)
|
2016-12-03 13:42:10 -05:00
|
|
|
{}
|
|
|
|
|
|
2017-07-23 18:28:02 +02:00
|
|
|
bool send(const hrt_abstime t)
|
2016-12-03 13:42:10 -05:00
|
|
|
{
|
2018-03-25 14:21:09 -04:00
|
|
|
|
|
|
|
|
vehicle_attitude_s att = {};
|
|
|
|
|
vehicle_global_position_s gpos = {};
|
|
|
|
|
bool att_updated = _att_sub->update(&_att_time, &att);
|
|
|
|
|
bool gpos_updated = _gpos_sub->update(&_gpos_time, &gpos);
|
2016-12-03 13:42:10 -05:00
|
|
|
|
|
|
|
|
if (att_updated || gpos_updated) {
|
|
|
|
|
|
|
|
|
|
mavlink_hil_state_quaternion_t msg = {};
|
|
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
// vehicle_attitude -> hil_state_quaternion
|
|
|
|
|
msg.attitude_quaternion[0] = att.q[0];
|
|
|
|
|
msg.attitude_quaternion[1] = att.q[1];
|
|
|
|
|
msg.attitude_quaternion[2] = att.q[2];
|
|
|
|
|
msg.attitude_quaternion[3] = att.q[3];
|
|
|
|
|
msg.rollspeed = att.rollspeed;
|
|
|
|
|
msg.pitchspeed = att.pitchspeed;
|
|
|
|
|
msg.yawspeed = att.yawspeed;
|
2016-12-03 13:42:10 -05:00
|
|
|
|
2018-03-25 14:21:09 -04:00
|
|
|
// vehicle_global_position -> hil_state_quaternion
|
|
|
|
|
msg.lat = gpos.lat;
|
|
|
|
|
msg.lon = gpos.lon;
|
|
|
|
|
msg.alt = gpos.alt;
|
|
|
|
|
msg.vx = gpos.vel_n;
|
|
|
|
|
msg.vy = gpos.vel_e;
|
|
|
|
|
msg.vz = gpos.vel_d;
|
|
|
|
|
msg.ind_airspeed = 0;
|
|
|
|
|
msg.true_airspeed = 0;
|
|
|
|
|
msg.xacc = 0;
|
|
|
|
|
msg.yacc = 0;
|
|
|
|
|
msg.zacc = 0;
|
2017-01-04 17:45:32 -05:00
|
|
|
|
2016-12-03 13:42:10 -05:00
|
|
|
mavlink_msg_hil_state_quaternion_send_struct(_mavlink->get_channel(), &msg);
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return true;
|
2016-12-03 13:42:10 -05:00
|
|
|
}
|
2017-07-23 18:28:02 +02:00
|
|
|
|
|
|
|
|
return false;
|
2016-12-03 13:42:10 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-07 00:54:05 -04:00
|
|
|
class MavlinkStreamPing : public MavlinkStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const char *get_name() const
|
|
|
|
|
{
|
|
|
|
|
return MavlinkStreamPing::get_name_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *get_name_static()
|
|
|
|
|
{
|
|
|
|
|
return "PING";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint16_t get_id_static()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_PING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_id()
|
|
|
|
|
{
|
|
|
|
|
return get_id_static();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
return new MavlinkStreamPing(mavlink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned get_size()
|
|
|
|
|
{
|
|
|
|
|
return MAVLINK_MSG_ID_PING_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool const_rate()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uint32_t _sequence;
|
|
|
|
|
|
|
|
|
|
/* do not allow top copying this class */
|
|
|
|
|
MavlinkStreamPing(MavlinkStreamPing &);
|
|
|
|
|
MavlinkStreamPing &operator = (const MavlinkStreamPing &);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MavlinkStreamPing(Mavlink *mavlink) : MavlinkStream(mavlink),
|
|
|
|
|
_sequence(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool send(const hrt_abstime t)
|
|
|
|
|
{
|
|
|
|
|
mavlink_ping_t msg = {};
|
|
|
|
|
|
|
|
|
|
msg.time_usec = hrt_absolute_time();
|
|
|
|
|
msg.seq = _sequence++;
|
|
|
|
|
msg.target_system = 0; // All systems
|
|
|
|
|
msg.target_component = 0; // All components
|
|
|
|
|
|
|
|
|
|
mavlink_msg_ping_send_struct(_mavlink->get_channel(), &msg);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-03 13:24:04 -04:00
|
|
|
static const StreamListItem streams_list[] = {
|
|
|
|
|
StreamListItem(&MavlinkStreamHeartbeat::new_instance, &MavlinkStreamHeartbeat::get_name_static, &MavlinkStreamHeartbeat::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamStatustext::new_instance, &MavlinkStreamStatustext::get_name_static, &MavlinkStreamStatustext::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamCommandLong::new_instance, &MavlinkStreamCommandLong::get_name_static, &MavlinkStreamCommandLong::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamSysStatus::new_instance, &MavlinkStreamSysStatus::get_name_static, &MavlinkStreamSysStatus::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamHighresIMU::new_instance, &MavlinkStreamHighresIMU::get_name_static, &MavlinkStreamHighresIMU::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamScaledIMU::new_instance, &MavlinkStreamScaledIMU::get_name_static, &MavlinkStreamScaledIMU::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamAttitude::new_instance, &MavlinkStreamAttitude::get_name_static, &MavlinkStreamAttitude::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamAttitudeQuaternion::new_instance, &MavlinkStreamAttitudeQuaternion::get_name_static, &MavlinkStreamAttitudeQuaternion::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamVFRHUD::new_instance, &MavlinkStreamVFRHUD::get_name_static, &MavlinkStreamVFRHUD::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamGPSRawInt::new_instance, &MavlinkStreamGPSRawInt::get_name_static, &MavlinkStreamGPSRawInt::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamSystemTime::new_instance, &MavlinkStreamSystemTime::get_name_static, &MavlinkStreamSystemTime::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamTimesync::new_instance, &MavlinkStreamTimesync::get_name_static, &MavlinkStreamTimesync::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamGlobalPositionInt::new_instance, &MavlinkStreamGlobalPositionInt::get_name_static, &MavlinkStreamGlobalPositionInt::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamLocalPositionNED::new_instance, &MavlinkStreamLocalPositionNED::get_name_static, &MavlinkStreamLocalPositionNED::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamVisionPositionEstimate::new_instance, &MavlinkStreamVisionPositionEstimate::get_name_static, &MavlinkStreamVisionPositionEstimate::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamLocalPositionNEDCOV::new_instance, &MavlinkStreamLocalPositionNEDCOV::get_name_static, &MavlinkStreamLocalPositionNEDCOV::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamEstimatorStatus::new_instance, &MavlinkStreamEstimatorStatus::get_name_static, &MavlinkStreamEstimatorStatus::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamAttPosMocap::new_instance, &MavlinkStreamAttPosMocap::get_name_static, &MavlinkStreamAttPosMocap::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamHomePosition::new_instance, &MavlinkStreamHomePosition::get_name_static, &MavlinkStreamHomePosition::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamServoOutputRaw<0>::new_instance, &MavlinkStreamServoOutputRaw<0>::get_name_static, &MavlinkStreamServoOutputRaw<0>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamServoOutputRaw<1>::new_instance, &MavlinkStreamServoOutputRaw<1>::get_name_static, &MavlinkStreamServoOutputRaw<1>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamServoOutputRaw<2>::new_instance, &MavlinkStreamServoOutputRaw<2>::get_name_static, &MavlinkStreamServoOutputRaw<2>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamServoOutputRaw<3>::new_instance, &MavlinkStreamServoOutputRaw<3>::get_name_static, &MavlinkStreamServoOutputRaw<3>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamHILActuatorControls::new_instance, &MavlinkStreamHILActuatorControls::get_name_static, &MavlinkStreamHILActuatorControls::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamPositionTargetGlobalInt::new_instance, &MavlinkStreamPositionTargetGlobalInt::get_name_static, &MavlinkStreamPositionTargetGlobalInt::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamLocalPositionSetpoint::new_instance, &MavlinkStreamLocalPositionSetpoint::get_name_static, &MavlinkStreamLocalPositionSetpoint::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamAttitudeTarget::new_instance, &MavlinkStreamAttitudeTarget::get_name_static, &MavlinkStreamAttitudeTarget::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamRCChannels::new_instance, &MavlinkStreamRCChannels::get_name_static, &MavlinkStreamRCChannels::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamManualControl::new_instance, &MavlinkStreamManualControl::get_name_static, &MavlinkStreamManualControl::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamOpticalFlowRad::new_instance, &MavlinkStreamOpticalFlowRad::get_name_static, &MavlinkStreamOpticalFlowRad::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamActuatorControlTarget<0>::new_instance, &MavlinkStreamActuatorControlTarget<0>::get_name_static, &MavlinkStreamActuatorControlTarget<0>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamActuatorControlTarget<1>::new_instance, &MavlinkStreamActuatorControlTarget<1>::get_name_static, &MavlinkStreamActuatorControlTarget<1>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamActuatorControlTarget<2>::new_instance, &MavlinkStreamActuatorControlTarget<2>::get_name_static, &MavlinkStreamActuatorControlTarget<2>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamActuatorControlTarget<3>::new_instance, &MavlinkStreamActuatorControlTarget<3>::get_name_static, &MavlinkStreamActuatorControlTarget<3>::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamNamedValueFloat::new_instance, &MavlinkStreamNamedValueFloat::get_name_static, &MavlinkStreamNamedValueFloat::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamDebug::new_instance, &MavlinkStreamDebug::get_name_static, &MavlinkStreamDebug::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamDebugVect::new_instance, &MavlinkStreamDebugVect::get_name_static, &MavlinkStreamDebugVect::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamNavControllerOutput::new_instance, &MavlinkStreamNavControllerOutput::get_name_static, &MavlinkStreamNavControllerOutput::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamCameraCapture::new_instance, &MavlinkStreamCameraCapture::get_name_static, &MavlinkStreamCameraCapture::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamCameraTrigger::new_instance, &MavlinkStreamCameraTrigger::get_name_static, &MavlinkStreamCameraTrigger::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamCameraImageCaptured::new_instance, &MavlinkStreamCameraImageCaptured::get_name_static, &MavlinkStreamCameraImageCaptured::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamDistanceSensor::new_instance, &MavlinkStreamDistanceSensor::get_name_static, &MavlinkStreamDistanceSensor::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamExtendedSysState::new_instance, &MavlinkStreamExtendedSysState::get_name_static, &MavlinkStreamExtendedSysState::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamAltitude::new_instance, &MavlinkStreamAltitude::get_name_static, &MavlinkStreamAltitude::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamADSBVehicle::new_instance, &MavlinkStreamADSBVehicle::get_name_static, &MavlinkStreamADSBVehicle::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamCollision::new_instance, &MavlinkStreamCollision::get_name_static, &MavlinkStreamCollision::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamWind::new_instance, &MavlinkStreamWind::get_name_static, &MavlinkStreamWind::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamMountOrientation::new_instance, &MavlinkStreamMountOrientation::get_name_static, &MavlinkStreamMountOrientation::get_id_static),
|
2018-01-30 18:04:37 +01:00
|
|
|
StreamListItem(&MavlinkStreamHighLatency2::new_instance, &MavlinkStreamHighLatency2::get_name_static, &MavlinkStreamHighLatency2::get_id_static),
|
2018-04-07 00:54:05 -04:00
|
|
|
StreamListItem(&MavlinkStreamGroundTruth::new_instance, &MavlinkStreamGroundTruth::get_name_static, &MavlinkStreamGroundTruth::get_id_static),
|
|
|
|
|
StreamListItem(&MavlinkStreamPing::new_instance, &MavlinkStreamPing::get_name_static, &MavlinkStreamPing::get_id_static)
|
2014-02-26 21:28:35 +04:00
|
|
|
};
|
2018-04-03 13:24:04 -04:00
|
|
|
|
|
|
|
|
const char *get_stream_name(const uint16_t msg_id)
|
|
|
|
|
{
|
|
|
|
|
// search for stream with specified msg id in supported streams list
|
|
|
|
|
for (const auto &stream : streams_list) {
|
|
|
|
|
if (msg_id == stream.get_id()) {
|
|
|
|
|
return stream.get_name();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MavlinkStream *create_mavlink_stream(const char *stream_name, Mavlink *mavlink)
|
|
|
|
|
{
|
|
|
|
|
// search for stream with specified name in supported streams list
|
|
|
|
|
if (stream_name != nullptr) {
|
|
|
|
|
for (const auto &stream : streams_list) {
|
|
|
|
|
if (strcmp(stream_name, stream.get_name()) == 0) {
|
|
|
|
|
return stream.new_instance(mavlink);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|