123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include "AP_Winch.h"
- #include "AP_Winch_Servo.h"
- extern const AP_HAL::HAL& hal;
- const AP_Param::GroupInfo AP_Winch::var_info[] = {
-
-
-
-
-
- AP_GROUPINFO_FLAGS("_ENABLE", 0, AP_Winch, _enabled, 0, AP_PARAM_FLAG_ENABLE),
-
-
-
-
-
- AP_GROUPINFO("_TYPE", 1, AP_Winch, config.type, 1),
-
-
-
-
-
-
- AP_GROUPINFO("_RATE_MAX", 2, AP_Winch, config.rate_max, 1.0f),
-
-
-
-
-
- AP_GROUPINFO("_POS_P", 3, AP_Winch, config.pos_p, AP_WINCH_POS_P),
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AP_SUBGROUPINFO(config.rate_pid, "_RATE_", 4, AP_Winch, AC_PID),
- AP_GROUPEND
- };
- AP_Winch::AP_Winch()
- {
- AP_Param::setup_object_defaults(this, var_info);
- }
- bool AP_Winch::enabled() const
- {
- if (!_enabled) {
- return false;
- }
- return ((config.type > 0) && (backend != nullptr));
- }
- void AP_Winch::init(const AP_WheelEncoder *wheel_encoder)
- {
-
- if (!_enabled.get()) {
- return;
- }
- switch(config.type.get()) {
- case 0:
- break;
- case 1:
- backend = new AP_Winch_Servo(config);
- break;
- default:
- break;
- }
- if (backend != nullptr) {
- backend->init(wheel_encoder);
- }
- }
- void AP_Winch::release_length(float length, float rate)
- {
- config.length_desired = config.length_curr + length;
- config.state = STATE_POSITION;
- if (is_zero(rate)) {
- config.rate_desired = config.rate_max;
- } else {
- config.rate_desired = constrain_float(fabsf(rate), -get_rate_max(), get_rate_max());
- }
- }
- void AP_Winch::set_desired_rate(float rate)
- {
- config.rate_desired = constrain_float(rate, -get_rate_max(), get_rate_max());
- config.state = STATE_RATE;
- }
- #define PASS_TO_BACKEND(function_name) \
- void AP_Winch::function_name() \
- { \
- if (!enabled()) { \
- return; \
- } \
- if (backend != nullptr) { \
- backend->function_name(); \
- } \
- }
- PASS_TO_BACKEND(update)
- #undef PASS_TO_BACKEND
|