2017-10-04 23:19:22 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AC_PID/AC_PID.h>
|
|
|
|
|
|
|
|
class AP_Winch_Backend;
|
|
|
|
|
|
|
|
class AP_Winch {
|
|
|
|
friend class AP_Winch_Backend;
|
2020-08-06 22:37:36 -03:00
|
|
|
friend class AP_Winch_PWM;
|
2020-07-24 05:29:43 -03:00
|
|
|
friend class AP_Winch_Daiwa;
|
2017-10-04 23:19:22 -03:00
|
|
|
|
|
|
|
public:
|
|
|
|
AP_Winch();
|
|
|
|
|
2020-07-24 05:29:25 -03:00
|
|
|
// Do not allow copies
|
|
|
|
AP_Winch(const AP_Winch &other) = delete;
|
|
|
|
AP_Winch &operator=(const AP_Winch&) = delete;
|
|
|
|
|
2017-10-04 23:19:22 -03:00
|
|
|
// indicate whether this module is enabled
|
|
|
|
bool enabled() const;
|
|
|
|
|
2020-07-24 05:29:25 -03:00
|
|
|
// true if winch is healthy
|
|
|
|
bool healthy() const;
|
|
|
|
|
2017-10-04 23:19:22 -03:00
|
|
|
// initialise the winch
|
2020-07-24 05:29:25 -03:00
|
|
|
void init();
|
2017-10-04 23:19:22 -03:00
|
|
|
|
|
|
|
// update the winch
|
|
|
|
void update();
|
|
|
|
|
|
|
|
// relax the winch so it does not attempt to maintain length or rate
|
2020-08-06 22:23:27 -03:00
|
|
|
void relax() { config.control_mode = ControlMode::RELAXED; }
|
2017-10-04 23:19:22 -03:00
|
|
|
|
2020-07-24 05:29:25 -03:00
|
|
|
// release specified length of cable (in meters)
|
|
|
|
void release_length(float length);
|
2017-10-04 23:19:22 -03:00
|
|
|
|
|
|
|
// deploy line at specified speed in m/s (+ve deploys line, -ve retracts line, 0 stops)
|
|
|
|
void set_desired_rate(float rate);
|
|
|
|
|
|
|
|
// get rate maximum in m/s
|
|
|
|
float get_rate_max() const { return MAX(config.rate_max, 0.0f); }
|
|
|
|
|
2020-07-24 05:29:25 -03:00
|
|
|
// send status to ground station
|
|
|
|
void send_status(const GCS_MAVLINK &channel);
|
|
|
|
|
|
|
|
// write log
|
|
|
|
void write_log();
|
|
|
|
|
|
|
|
// returns true if pre arm checks have passed
|
|
|
|
bool pre_arm_check(char *failmsg, uint8_t failmsg_len) const;
|
|
|
|
|
|
|
|
static AP_Winch *get_singleton();
|
|
|
|
|
2017-10-04 23:19:22 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-07-24 05:29:25 -03:00
|
|
|
enum class WinchType {
|
|
|
|
NONE = 0,
|
2020-08-06 22:37:36 -03:00
|
|
|
PWM = 1,
|
2020-07-24 05:29:43 -03:00
|
|
|
DAIWA = 2
|
2020-07-24 05:29:25 -03:00
|
|
|
};
|
2017-10-04 23:19:22 -03:00
|
|
|
|
|
|
|
// winch states
|
2020-07-24 05:29:25 -03:00
|
|
|
enum class ControlMode : uint8_t {
|
|
|
|
RELAXED = 0, // winch is realxed
|
|
|
|
POSITION, // moving or maintaining a target length (from an external source)
|
|
|
|
RATE, // extending or retracting at a target rate (from an external source)
|
|
|
|
RATE_FROM_RC // extending or retracting at a target rate (from RC input)
|
|
|
|
};
|
2017-10-04 23:19:22 -03:00
|
|
|
|
|
|
|
struct Backend_Config {
|
|
|
|
AP_Int8 type; // winch type
|
|
|
|
AP_Float rate_max; // deploy or retract rate maximum (in m/s).
|
|
|
|
AP_Float pos_p; // position error P gain
|
2020-07-24 05:29:25 -03:00
|
|
|
ControlMode control_mode; // state of winch control (using target position or target rate)
|
2017-10-04 23:19:22 -03:00
|
|
|
float length_desired; // target desired length (in meters)
|
|
|
|
float rate_desired; // target deploy rate (in m/s, +ve = deploying, -ve = retracting)
|
|
|
|
} config;
|
|
|
|
|
|
|
|
AP_Winch_Backend *backend;
|
2020-07-24 05:29:25 -03:00
|
|
|
|
|
|
|
static AP_Winch *_singleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Winch *winch();
|
2017-10-04 23:19:22 -03:00
|
|
|
};
|