2015-12-30 22:19:52 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
|
|
|
#include "AP_Mount_SoloGimbal.h"
|
2020-07-24 14:01:21 -03:00
|
|
|
#if HAL_SOLO_GIMBAL_ENABLED
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
#include "SoloGimbal.h"
|
2019-01-18 00:23:42 -04:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2016-05-11 23:39:57 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2015-01-08 16:11:26 -04:00
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
AP_Mount_SoloGimbal::AP_Mount_SoloGimbal(AP_Mount &frontend, AP_Mount::mount_state &state, uint8_t instance) :
|
2015-01-30 02:39:31 -04:00
|
|
|
AP_Mount_Backend(frontend, state, instance),
|
2018-10-11 06:30:03 -03:00
|
|
|
_gimbal()
|
2015-01-30 02:39:31 -04:00
|
|
|
{}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// init - performs any required initialisation for this instance
|
2019-08-27 03:23:30 -03:00
|
|
|
void AP_Mount_SoloGimbal::init()
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-02-01 05:34:12 -04:00
|
|
|
_initialised = true;
|
|
|
|
set_mode((enum MAV_MOUNT_MODE)_state._default_mode.get());
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::update_fast()
|
|
|
|
{
|
|
|
|
_gimbal.update_fast();
|
|
|
|
}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// update mount position - should be called periodically
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::update()
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-01-19 09:39:13 -04:00
|
|
|
// exit immediately if not initialised
|
|
|
|
if (!_initialised) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
|
|
|
|
// update based on mount mode
|
2015-01-29 02:23:16 -04:00
|
|
|
switch(get_mode()) {
|
2015-01-15 01:13:59 -04:00
|
|
|
// move mount to a "retracted" position. we do not implement a separate servo based retract mechanism
|
|
|
|
case MAV_MOUNT_MODE_RETRACT:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(true);
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// move mount to a neutral position, typically pointing forward
|
|
|
|
case MAV_MOUNT_MODE_NEUTRAL:
|
2015-12-30 22:19:52 -04:00
|
|
|
{
|
|
|
|
_gimbal.set_lockedToBody(false);
|
|
|
|
const Vector3f &target = _state._neutral_angles.get();
|
|
|
|
_angle_ef_target_rad.x = ToRad(target.x);
|
|
|
|
_angle_ef_target_rad.y = ToRad(target.y);
|
|
|
|
_angle_ef_target_rad.z = ToRad(target.z);
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// point to the angles given by a mavlink message
|
|
|
|
case MAV_MOUNT_MODE_MAVLINK_TARGETING:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2015-01-15 01:13:59 -04:00
|
|
|
// do nothing because earth-frame angle targets (i.e. _angle_ef_target_rad) should have already been set by a MOUNT_CONTROL message from GCS
|
|
|
|
break;
|
|
|
|
|
|
|
|
// RC radio manual angle control, but with stabilization from the AHRS
|
|
|
|
case MAV_MOUNT_MODE_RC_TARGETING:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2015-01-15 01:13:59 -04:00
|
|
|
// update targets using pilot's rc inputs
|
|
|
|
update_targets_from_rc();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// point mount to a GPS point given by the mission planner
|
|
|
|
case MAV_MOUNT_MODE_GPS_POINT:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2022-06-17 03:56:53 -03:00
|
|
|
UNUSED_RESULT(calc_angle_to_roi_target(_angle_ef_target_rad, true, true, true));
|
2020-12-21 05:07:43 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_MOUNT_MODE_HOME_LOCATION:
|
2022-06-17 04:14:11 -03:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2020-12-21 05:07:43 -04:00
|
|
|
// constantly update the home location:
|
|
|
|
if (!AP::ahrs().home_is_set()) {
|
|
|
|
break;
|
2015-01-15 01:13:59 -04:00
|
|
|
}
|
2020-12-21 05:07:43 -04:00
|
|
|
_state._roi_target = AP::ahrs().get_home();
|
|
|
|
_state._roi_target_set = true;
|
2022-06-17 03:56:53 -03:00
|
|
|
UNUSED_RESULT(calc_angle_to_roi_target(_angle_ef_target_rad, true, true, true));
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
2019-03-16 04:06:02 -03:00
|
|
|
case MAV_MOUNT_MODE_SYSID_TARGET:
|
2022-06-17 04:14:11 -03:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2022-06-17 03:56:53 -03:00
|
|
|
UNUSED_RESULT(calc_angle_to_sysid_target(_angle_ef_target_rad, true, true, true));
|
2019-03-16 04:06:02 -03:00
|
|
|
break;
|
|
|
|
|
2015-01-15 01:13:59 -04:00
|
|
|
default:
|
|
|
|
// we do not know this mode so do nothing
|
|
|
|
break;
|
|
|
|
}
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// has_pan_control - returns true if this mount can control it's pan (required for multicopters)
|
2015-12-30 22:19:52 -04:00
|
|
|
bool AP_Mount_SoloGimbal::has_pan_control() const
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
|
|
|
// we do not have yaw control
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set_mode - sets mount's mode
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::set_mode(enum MAV_MOUNT_MODE mode)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-01-19 09:39:13 -04:00
|
|
|
// exit immediately if not initialised
|
|
|
|
if (!_initialised) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// record the mode change
|
2015-01-18 21:40:40 -04:00
|
|
|
_state._mode = mode;
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2018-10-11 06:30:03 -03:00
|
|
|
// send_mount_status - called to allow mounts to send their status to GCS using the MOUNT_STATUS message
|
|
|
|
void AP_Mount_SoloGimbal::send_mount_status(mavlink_channel_t chan)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-12-30 22:19:52 -04:00
|
|
|
if (_gimbal.aligned()) {
|
2022-01-05 17:50:53 -04:00
|
|
|
mavlink_msg_mount_status_send(chan, 0, 0, degrees(_angle_ef_target_rad.y)*100, degrees(_angle_ef_target_rad.x)*100, degrees(_angle_ef_target_rad.z)*100, _state._mode);
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
2016-05-11 23:39:57 -03:00
|
|
|
|
|
|
|
// block heartbeat from transmitting to the GCS
|
|
|
|
GCS_MAVLINK::disable_channel_routing(chan);
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2015-01-29 05:01:55 -04:00
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_Mount_SoloGimbal::handle_gimbal_report(mavlink_channel_t chan, const mavlink_message_t &msg)
|
2015-01-29 05:01:55 -04:00
|
|
|
{
|
2015-03-20 17:43:51 -03:00
|
|
|
_gimbal.update_target(_angle_ef_target_rad);
|
2015-03-20 17:19:34 -03:00
|
|
|
_gimbal.receive_feedback(chan,msg);
|
2015-12-30 22:19:52 -04:00
|
|
|
|
2019-02-11 04:33:19 -04:00
|
|
|
AP_Logger *logger = AP_Logger::get_singleton();
|
|
|
|
if (logger == nullptr) {
|
2018-03-13 21:23:01 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-11 04:33:19 -04:00
|
|
|
if(!_params_saved && logger->logging_started()) {
|
|
|
|
_gimbal.fetch_params(); //last parameter save might not be stored in logger so retry
|
2015-12-30 22:19:52 -04:00
|
|
|
_params_saved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_gimbal.get_log_dt() > 1.0f/25.0f) {
|
2018-03-13 21:23:01 -03:00
|
|
|
_gimbal.write_logs();
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_Mount_SoloGimbal::handle_param_value(const mavlink_message_t &msg)
|
2015-12-30 22:19:52 -04:00
|
|
|
{
|
2018-03-13 21:23:01 -03:00
|
|
|
_gimbal.handle_param_value(msg);
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_Mount_SoloGimbal::handle_gimbal_torque_report(mavlink_channel_t chan, const mavlink_message_t &msg)
|
2015-12-30 22:19:52 -04:00
|
|
|
{
|
|
|
|
_gimbal.disable_torque_report();
|
2015-02-16 01:48:55 -04:00
|
|
|
}
|
|
|
|
|
2020-07-24 14:01:21 -03:00
|
|
|
#endif // HAL_SOLO_GIMBAL_ENABLED
|