2015-12-30 22:19:52 -04:00
|
|
|
#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
|
|
|
|
2022-08-30 08:15:10 -03:00
|
|
|
AP_Mount_SoloGimbal::AP_Mount_SoloGimbal(AP_Mount &frontend, AP_Mount_Params ¶ms, uint8_t instance) :
|
|
|
|
AP_Mount_Backend(frontend, params, 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;
|
2022-08-30 08:15:10 -03:00
|
|
|
set_mode((enum MAV_MOUNT_MODE)_params.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);
|
2022-06-23 00:39:24 -03:00
|
|
|
// initialise _angle_rad to smooth transition if user changes to RC_TARGETTINg
|
|
|
|
_angle_rad = {0, 0, 0, false};
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// move mount to a neutral position, typically pointing forward
|
2022-06-23 00:39:24 -03:00
|
|
|
case MAV_MOUNT_MODE_NEUTRAL: {
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2022-08-30 08:15:10 -03:00
|
|
|
const Vector3f &target = _params.neutral_angles.get();
|
2022-06-23 00:39:24 -03:00
|
|
|
_angle_rad.roll = radians(target.x);
|
|
|
|
_angle_rad.pitch = radians(target.y);
|
|
|
|
_angle_rad.yaw = radians(target.z);
|
|
|
|
_angle_rad.yaw_is_ef = false;
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
2022-06-23 00:39:24 -03:00
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
|
|
|
|
// 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);
|
2022-06-23 00:39:24 -03:00
|
|
|
switch (mavt_target.target_type) {
|
|
|
|
case MountTargetType::ANGLE:
|
|
|
|
_angle_rad = mavt_target.angle_rad;
|
|
|
|
break;
|
|
|
|
case MountTargetType::RATE:
|
|
|
|
update_angle_target_from_rate(mavt_target.rate_rads, _angle_rad);
|
|
|
|
break;
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// RC radio manual angle control, but with stabilization from the AHRS
|
2022-06-23 00:39:24 -03:00
|
|
|
case MAV_MOUNT_MODE_RC_TARGETING: {
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2022-06-23 00:39:24 -03:00
|
|
|
// update targets using pilot's RC inputs
|
|
|
|
MountTarget rc_target {};
|
|
|
|
if (get_rc_rate_target(rc_target)) {
|
|
|
|
update_angle_target_from_rate(rc_target, _angle_rad);
|
|
|
|
} else if (get_rc_angle_target(rc_target)) {
|
|
|
|
_angle_rad = rc_target;
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
2022-06-23 00:39:24 -03:00
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
|
|
|
|
// 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-23 00:39:24 -03:00
|
|
|
IGNORE_RETURN(get_angle_target_to_roi(_angle_rad));
|
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);
|
2022-06-23 00:39:24 -03:00
|
|
|
IGNORE_RETURN(get_angle_target_to_home(_angle_rad));
|
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-23 00:39:24 -03:00
|
|
|
IGNORE_RETURN(get_angle_target_to_sysid(_angle_rad));
|
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
|
|
|
}
|
|
|
|
|
2022-07-11 05:07:22 -03:00
|
|
|
// get attitude as a quaternion. returns true on success
|
|
|
|
bool AP_Mount_SoloGimbal::get_attitude_quaternion(Quaternion& att_quat)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2022-07-11 05:07:22 -03:00
|
|
|
if (!_gimbal.aligned()) {
|
|
|
|
return false;
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
2022-07-11 05:07:22 -03:00
|
|
|
att_quat.from_euler(_angle_rad.roll, _angle_rad.pitch, get_bf_yaw_angle(_angle_rad));
|
|
|
|
return true;
|
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
|
|
|
{
|
2022-06-23 00:39:24 -03:00
|
|
|
_gimbal.update_target(Vector3f{_angle_rad.roll, _angle_rad.pitch, get_bf_yaw_angle(_angle_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
|