Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tap_esc: add support for MC_AIRMODE #9173

Merged
merged 2 commits into from
Mar 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/drivers/tap_esc/tap_esc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <lib/mathlib/mathlib.h>
#include <systemlib/px4_macros.h>
#include <drivers/device/device.h>
#include <px4_module_params.h>
#include <uORB/uORB.h>
#include <uORB/topics/actuator_controls.h>
#include <uORB/topics/actuator_outputs.h>
Expand All @@ -51,17 +52,15 @@
#include <uORB/topics/input_rc.h>
#include <uORB/topics/esc_status.h>
#include <uORB/topics/multirotor_motor_limits.h>
#include <uORB/topics/parameter_update.h>

#include <drivers/drv_hrt.h>
#include <drivers/drv_mixer.h>
#include <lib/mixer/mixer.h>
#include <systemlib/param/param.h>
#include <systemlib/pwm_limit/pwm_limit.h>

#include "tap_esc_common.h"

#define NAN_VALUE (0.0f/0.0f)

#ifndef B250000
#define B250000 250000
#endif
Expand All @@ -81,7 +80,7 @@
*/

static int _uart_fd = -1; //todo:refactor in to class
class TAP_ESC : public device::CDev
class TAP_ESC : public device::CDev, public ModuleParams
{
public:
enum Mode {
Expand Down Expand Up @@ -115,6 +114,7 @@ class TAP_ESC : public device::CDev
// subscriptions
int _armed_sub;
int _test_motor_sub;
int _params_sub;
orb_advert_t _outputs_pub;
actuator_outputs_s _outputs;
actuator_armed_s _armed;
Expand Down Expand Up @@ -142,6 +142,12 @@ class TAP_ESC : public device::CDev
unsigned _current_update_rate;
ESC_UART_BUF uartbuf;
EscPacket _packet;


DEFINE_PARAMETERS(
(ParamBool<px4::params::MC_AIRMODE>) _airmode ///< multicopter air-mode
)

void subscribe();

void work_start();
Expand Down Expand Up @@ -169,11 +175,13 @@ TAP_ESC *tap_esc = nullptr;

TAP_ESC::TAP_ESC(int channels_count):
CDev("tap_esc", TAP_ESC_DEVICE_PATH),
ModuleParams(nullptr),
_is_armed(false),
_poll_fds_num(0),
_mode(MODE_4PWM), //FIXME: what is this mode used for???
_armed_sub(-1),
_test_motor_sub(-1),
_params_sub(-1),
_outputs_pub(nullptr),
_armed{},
_esc_feedback_pub(nullptr),
Expand Down Expand Up @@ -576,6 +584,7 @@ TAP_ESC::cycle()
_to_mixer_status = orb_advertise(ORB_ID(multirotor_motor_limits), &multirotor_motor_limits);
_armed_sub = orb_subscribe(ORB_ID(actuator_armed));
_test_motor_sub = orb_subscribe(ORB_ID(test_motor));
_params_sub = orb_subscribe(ORB_ID(parameter_update));
_initialized = true;
}

Expand Down Expand Up @@ -613,6 +622,9 @@ TAP_ESC::cycle()
_current_update_rate = max_rate;
}

if (_mixers) {
_mixers->set_airmode(_airmode.get());
}


/* check if anything updated */
Expand Down Expand Up @@ -787,6 +799,16 @@ TAP_ESC::cycle()

}

/* check for parameter updates */
bool param_updated = false;
orb_check(_params_sub, &param_updated);

if (param_updated) {
struct parameter_update_s update;
orb_copy(ORB_ID(parameter_update), _params_sub, &update);
updateParams();
}


}

Expand All @@ -803,6 +825,7 @@ void TAP_ESC::work_stop()
_armed_sub = -1;
orb_unsubscribe(_test_motor_sub);
_test_motor_sub = -1;
orb_unsubscribe(_params_sub);

DEVICE_LOG("stopping");
_initialized = false;
Expand Down Expand Up @@ -844,7 +867,7 @@ int TAP_ESC::control_callback(uint8_t control_group, uint8_t control_index, floa
control_group == actuator_controls_s::GROUP_INDEX_ATTITUDE_ALTERNATE) &&
control_index == actuator_controls_s::INDEX_THROTTLE) {
/* set the throttle to an invalid value */
input = NAN_VALUE;
input = NAN;
}
}

Expand Down