123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709 |
- #include <AP_Common/AP_Common.h>
- #include <AP_Param/AP_Param.h>
- #include "AP_Mount.h"
- #include "AP_Mount_Backend.h"
- #include "AP_Mount_Servo.h"
- #include "AP_Mount_SoloGimbal.h"
- #include "AP_Mount_Alexmos.h"
- #include "AP_Mount_SToRM32.h"
- #include "AP_Mount_SToRM32_serial.h"
- const AP_Param::GroupInfo AP_Mount::var_info[] = {
-
-
-
-
-
- AP_GROUPINFO("_DEFLT_MODE", 0, AP_Mount, state[0]._default_mode, MAV_MOUNT_MODE_RC_TARGETING),
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AP_GROUPINFO("_RETRACT", 1, AP_Mount, state[0]._retract_angles, 0),
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AP_GROUPINFO("_NEUTRAL", 2, AP_Mount, state[0]._neutral_angles, 0),
-
-
-
-
-
-
- AP_GROUPINFO("_STAB_ROLL", 4, AP_Mount, state[0]._stab_roll, 0),
-
-
-
-
-
- AP_GROUPINFO("_STAB_TILT", 5, AP_Mount, state[0]._stab_tilt, 0),
-
-
-
-
-
- AP_GROUPINFO("_STAB_PAN", 6, AP_Mount, state[0]._stab_pan, 0),
-
-
-
-
-
- AP_GROUPINFO("_RC_IN_ROLL", 7, AP_Mount, state[0]._roll_rc_in, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("_ANGMIN_ROL", 8, AP_Mount, state[0]._roll_angle_min, -4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("_ANGMAX_ROL", 9, AP_Mount, state[0]._roll_angle_max, 4500),
-
-
-
-
-
- AP_GROUPINFO("_RC_IN_TILT", 10, AP_Mount, state[0]._tilt_rc_in, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("_ANGMIN_TIL", 11, AP_Mount, state[0]._tilt_angle_min, -4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("_ANGMAX_TIL", 12, AP_Mount, state[0]._tilt_angle_max, 4500),
-
-
-
-
-
- AP_GROUPINFO("_RC_IN_PAN", 13, AP_Mount, state[0]._pan_rc_in, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("_ANGMIN_PAN", 14, AP_Mount, state[0]._pan_angle_min, -4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("_ANGMAX_PAN", 15, AP_Mount, state[0]._pan_angle_max, 4500),
-
-
-
-
-
-
- AP_GROUPINFO("_JSTICK_SPD", 16, AP_Mount, _joystick_speed, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("_LEAD_RLL", 17, AP_Mount, state[0]._roll_stb_lead, 0.0f),
-
-
-
-
-
-
-
- AP_GROUPINFO("_LEAD_PTCH", 18, AP_Mount, state[0]._pitch_stb_lead, 0.0f),
-
-
-
-
-
-
- AP_GROUPINFO("_TYPE", 19, AP_Mount, state[0]._type, 0),
-
-
-
-
-
- #if AP_MOUNT_MAX_INSTANCES > 1
-
-
-
-
-
- AP_GROUPINFO("2_DEFLT_MODE", 25, AP_Mount, state[1]._default_mode, MAV_MOUNT_MODE_RC_TARGETING),
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AP_GROUPINFO("2_RETRACT", 26, AP_Mount, state[1]._retract_angles, 0),
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AP_GROUPINFO("2_NEUTRAL", 27, AP_Mount, state[1]._neutral_angles, 0),
-
-
-
-
-
-
- AP_GROUPINFO("2_STAB_ROLL", 28, AP_Mount, state[1]._stab_roll, 0),
-
-
-
-
-
- AP_GROUPINFO("2_STAB_TILT", 29, AP_Mount, state[1]._stab_tilt, 0),
-
-
-
-
-
- AP_GROUPINFO("2_STAB_PAN", 30, AP_Mount, state[1]._stab_pan, 0),
-
-
-
-
-
- AP_GROUPINFO("2_RC_IN_ROLL", 31, AP_Mount, state[1]._roll_rc_in, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_ANGMIN_ROL", 32, AP_Mount, state[1]._roll_angle_min, -4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_ANGMAX_ROL", 33, AP_Mount, state[1]._roll_angle_max, 4500),
-
-
-
-
-
- AP_GROUPINFO("2_RC_IN_TILT", 34, AP_Mount, state[1]._tilt_rc_in, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_ANGMIN_TIL", 35, AP_Mount, state[1]._tilt_angle_min, -4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_ANGMAX_TIL", 36, AP_Mount, state[1]._tilt_angle_max, 4500),
-
-
-
-
-
- AP_GROUPINFO("2_RC_IN_PAN", 37, AP_Mount, state[1]._pan_rc_in, 0),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_ANGMIN_PAN", 38, AP_Mount, state[1]._pan_angle_min, -4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_ANGMAX_PAN", 39, AP_Mount, state[1]._pan_angle_max, 4500),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_LEAD_RLL", 40, AP_Mount, state[1]._roll_stb_lead, 0.0f),
-
-
-
-
-
-
-
- AP_GROUPINFO("2_LEAD_PTCH", 41, AP_Mount, state[1]._pitch_stb_lead, 0.0f),
-
-
-
-
-
- AP_GROUPINFO("2_TYPE", 42, AP_Mount, state[1]._type, 0),
- #endif
- AP_GROUPEND
- };
- AP_Mount::AP_Mount(const struct Location ¤t_loc) :
- _current_loc(current_loc)
- {
- if (_singleton != nullptr) {
- #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
- AP_HAL::panic("Mount must be singleton");
- #endif
- return;
- }
- _singleton = this;
- AP_Param::setup_object_defaults(this, var_info);
- }
- void AP_Mount::init()
- {
-
- if (_num_instances != 0) {
- return;
- }
-
- if (!state[0]._type.configured()) {
- if (SRV_Channels::function_assigned(SRV_Channel::Aux_servo_function_t::k_mount_pan) ||
- SRV_Channels::function_assigned(SRV_Channel::Aux_servo_function_t::k_mount_tilt) ||
- SRV_Channels::function_assigned(SRV_Channel::Aux_servo_function_t::k_mount_roll)) {
- state[0]._type.set_and_save(Mount_Type_Servo);
- }
- }
-
- bool primary_set = false;
-
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
-
- state[instance]._mode = (enum MAV_MOUNT_MODE)state[instance]._default_mode.get();
- MountType mount_type = get_mount_type(instance);
-
- if (mount_type == Mount_Type_Servo) {
- _backends[instance] = new AP_Mount_Servo(*this, state[instance], instance);
- _num_instances++;
- #if AP_AHRS_NAVEKF_AVAILABLE
- #if !HAL_MINIMIZE_FEATURES
-
- } else if (mount_type == Mount_Type_SoloGimbal) {
- _backends[instance] = new AP_Mount_SoloGimbal(*this, state[instance], instance);
- _num_instances++;
- #endif
- #endif
-
- } else if (mount_type == Mount_Type_Alexmos) {
- _backends[instance] = new AP_Mount_Alexmos(*this, state[instance], instance);
- _num_instances++;
-
- } else if (mount_type == Mount_Type_SToRM32) {
- _backends[instance] = new AP_Mount_SToRM32(*this, state[instance], instance);
- _num_instances++;
-
- } else if (mount_type == Mount_Type_SToRM32_serial) {
- _backends[instance] = new AP_Mount_SToRM32_serial(*this, state[instance], instance);
- _num_instances++;
- }
-
- if (_backends[instance] != nullptr) {
- _backends[instance]->init();
- if (!primary_set) {
- _primary = instance;
- primary_set = true;
- }
- }
- }
- }
- void AP_Mount::update()
- {
-
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
- if (_backends[instance] != nullptr) {
- _backends[instance]->update();
- }
- }
- }
- void AP_Mount::update_fast()
- {
-
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
- if (_backends[instance] != nullptr) {
- _backends[instance]->update_fast();
- }
- }
- }
- AP_Mount::MountType AP_Mount::get_mount_type(uint8_t instance) const
- {
- if (instance >= AP_MOUNT_MAX_INSTANCES) {
- return Mount_Type_None;
- }
- return (MountType)state[instance]._type.get();
- }
- bool AP_Mount::has_pan_control(uint8_t instance) const
- {
- if (instance >= AP_MOUNT_MAX_INSTANCES || _backends[instance] == nullptr) {
- return false;
- }
-
- return _backends[instance]->has_pan_control();
- }
- MAV_MOUNT_MODE AP_Mount::get_mode(uint8_t instance) const
- {
-
- if (instance >= AP_MOUNT_MAX_INSTANCES) {
- return MAV_MOUNT_MODE_RETRACT;
- }
- return state[instance]._mode;
- }
- void AP_Mount::set_mode_to_default(uint8_t instance)
- {
- set_mode(instance, (enum MAV_MOUNT_MODE)state[instance]._default_mode.get());
- }
- void AP_Mount::set_mode(uint8_t instance, enum MAV_MOUNT_MODE mode)
- {
-
- if (instance >= AP_MOUNT_MAX_INSTANCES || _backends[instance] == nullptr) {
- return;
- }
-
- _backends[instance]->set_mode(mode);
- }
- void AP_Mount::set_angle_targets(uint8_t instance, float roll, float tilt, float pan)
- {
- if (instance >= AP_MOUNT_MAX_INSTANCES || _backends[instance] == nullptr) {
- return;
- }
-
- _backends[instance]->set_angle_targets(roll, tilt, pan);
- }
- MAV_RESULT AP_Mount::handle_command_do_mount_configure(const mavlink_command_long_t &packet)
- {
- if (_primary >= AP_MOUNT_MAX_INSTANCES || _backends[_primary] == nullptr) {
- return MAV_RESULT_FAILED;
- }
- _backends[_primary]->set_mode((MAV_MOUNT_MODE)packet.param1);
- state[0]._stab_roll = packet.param2;
- state[0]._stab_tilt = packet.param3;
- state[0]._stab_pan = packet.param4;
- return MAV_RESULT_ACCEPTED;
- }
- MAV_RESULT AP_Mount::handle_command_do_mount_control(const mavlink_command_long_t &packet)
- {
- if (_primary >= AP_MOUNT_MAX_INSTANCES || _backends[_primary] == nullptr) {
- return MAV_RESULT_FAILED;
- }
-
- _backends[_primary]->control(packet.param1, packet.param2, packet.param3, (MAV_MOUNT_MODE) packet.param7);
- return MAV_RESULT_ACCEPTED;
- }
- MAV_RESULT AP_Mount::handle_command_long(const mavlink_command_long_t &packet)
- {
- switch (packet.command) {
- case MAV_CMD_DO_MOUNT_CONFIGURE:
- return handle_command_do_mount_configure(packet);
- case MAV_CMD_DO_MOUNT_CONTROL:
- return handle_command_do_mount_control(packet);
- default:
- return MAV_RESULT_UNSUPPORTED;
- }
- }
- void AP_Mount::handle_mount_configure(const mavlink_message_t &msg)
- {
- if (_primary >= AP_MOUNT_MAX_INSTANCES || _backends[_primary] == nullptr) {
- return;
- }
- mavlink_mount_configure_t packet;
- mavlink_msg_mount_configure_decode(&msg, &packet);
-
- _backends[_primary]->handle_mount_configure(packet);
- }
- void AP_Mount::handle_mount_control(const mavlink_message_t &msg)
- {
- if (_primary >= AP_MOUNT_MAX_INSTANCES || _backends[_primary] == nullptr) {
- return;
- }
- mavlink_mount_control_t packet;
- mavlink_msg_mount_control_decode(&msg, &packet);
-
- _backends[_primary]->handle_mount_control(packet);
- }
- void AP_Mount::send_mount_status(mavlink_channel_t chan)
- {
-
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
- if (_backends[instance] != nullptr) {
- _backends[instance]->send_mount_status(chan);
- }
- }
- }
- void AP_Mount::set_roi_target(uint8_t instance, const struct Location &target_loc)
- {
-
- if (instance < AP_MOUNT_MAX_INSTANCES && _backends[instance] != nullptr) {
- _backends[instance]->set_roi_target(target_loc);
- }
- }
- void AP_Mount::handle_gimbal_report(mavlink_channel_t chan, const mavlink_message_t &msg)
- {
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
- if (_backends[instance] != nullptr) {
- _backends[instance]->handle_gimbal_report(chan, msg);
- }
- }
- }
- void AP_Mount::handle_message(mavlink_channel_t chan, const mavlink_message_t &msg)
- {
- switch (msg.msgid) {
- case MAVLINK_MSG_ID_GIMBAL_REPORT:
- handle_gimbal_report(chan, msg);
- break;
- case MAVLINK_MSG_ID_MOUNT_CONFIGURE:
- handle_mount_configure(msg);
- break;
- case MAVLINK_MSG_ID_MOUNT_CONTROL:
- handle_mount_control(msg);
- break;
- default:
- #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
- AP_HAL::panic("Unhandled mount case");
- #endif
- break;
- }
- }
- void AP_Mount::handle_param_value(const mavlink_message_t &msg)
- {
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
- if (_backends[instance] != nullptr) {
- _backends[instance]->handle_param_value(msg);
- }
- }
- }
- void AP_Mount::send_gimbal_report(mavlink_channel_t chan)
- {
- for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
- if (_backends[instance] != nullptr) {
- _backends[instance]->send_gimbal_report(chan);
- }
- }
- }
- AP_Mount *AP_Mount::_singleton;
- namespace AP {
- AP_Mount *mount()
- {
- return AP_Mount::get_singleton();
- }
- };
|