2016-10-28 19:05:19 -03:00
|
|
|
#include "AP_Gripper.h"
|
|
|
|
|
2022-09-20 04:37:47 -03:00
|
|
|
#if AP_GRIPPER_ENABLED
|
|
|
|
|
2016-10-28 19:05:19 -03:00
|
|
|
#include "AP_Gripper_Servo.h"
|
2016-10-29 08:01:18 -03:00
|
|
|
#include "AP_Gripper_EPM.h"
|
2016-10-28 19:05:19 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
#define GRIPPER_GRAB_PWM_DEFAULT 1900
|
|
|
|
#define GRIPPER_RELEASE_PWM_DEFAULT 1100
|
2016-10-29 08:01:18 -03:00
|
|
|
// EPM PWM definitions
|
|
|
|
#define GRIPPER_NEUTRAL_PWM_DEFAULT 1500
|
2022-07-31 22:45:52 -03:00
|
|
|
#define GRIPPER_REGRAB_DEFAULT 0 // default EPM re-grab interval (in seconds) to ensure cargo is securely held
|
|
|
|
#define GRIPPER_AUTOCLOSE_DEFAULT 0.0 // default automatic close time (in seconds)
|
2016-10-28 19:05:19 -03:00
|
|
|
|
|
|
|
const AP_Param::GroupInfo AP_Gripper::var_info[] = {
|
|
|
|
// @Param: ENABLE
|
|
|
|
// @DisplayName: Gripper Enable/Disable
|
|
|
|
// @Description: Gripper enable/disable
|
|
|
|
// @User: Standard
|
|
|
|
// @Values: 0:Disabled, 1:Enabled
|
|
|
|
AP_GROUPINFO_FLAGS("ENABLE", 0, AP_Gripper, _enabled, 0, AP_PARAM_FLAG_ENABLE),
|
|
|
|
|
|
|
|
// @Param: TYPE
|
|
|
|
// @DisplayName: Gripper Type
|
|
|
|
// @Description: Gripper enable/disable
|
|
|
|
// @User: Standard
|
|
|
|
// @Values: 0:None,1:Servo,2:EPM
|
|
|
|
AP_GROUPINFO("TYPE", 1, AP_Gripper, config.type, 0),
|
|
|
|
|
|
|
|
// @Param: GRAB
|
|
|
|
// @DisplayName: Gripper Grab PWM
|
2017-05-15 20:20:26 -03:00
|
|
|
// @Description: PWM value in microseconds sent to Gripper to initiate grabbing the cargo
|
2016-10-28 19:05:19 -03:00
|
|
|
// @User: Advanced
|
|
|
|
// @Range: 1000 2000
|
2017-01-10 11:32:19 -04:00
|
|
|
// @Units: PWM
|
2016-10-28 19:05:19 -03:00
|
|
|
AP_GROUPINFO("GRAB", 2, AP_Gripper, config.grab_pwm, GRIPPER_GRAB_PWM_DEFAULT),
|
|
|
|
|
|
|
|
// @Param: RELEASE
|
|
|
|
// @DisplayName: Gripper Release PWM
|
2017-05-15 20:20:26 -03:00
|
|
|
// @Description: PWM value in microseconds sent to Gripper to release the cargo
|
2016-10-28 19:05:19 -03:00
|
|
|
// @User: Advanced
|
|
|
|
// @Range: 1000 2000
|
2017-01-10 11:32:19 -04:00
|
|
|
// @Units: PWM
|
2016-10-28 19:05:19 -03:00
|
|
|
AP_GROUPINFO("RELEASE", 3, AP_Gripper, config.release_pwm, GRIPPER_RELEASE_PWM_DEFAULT),
|
|
|
|
|
2016-10-29 08:01:18 -03:00
|
|
|
// @Param: NEUTRAL
|
|
|
|
// @DisplayName: Neutral PWM
|
2017-05-15 20:20:26 -03:00
|
|
|
// @Description: PWM value in microseconds sent to grabber when not grabbing or releasing
|
2016-10-29 08:01:18 -03:00
|
|
|
// @User: Advanced
|
|
|
|
// @Range: 1000 2000
|
2017-01-10 11:32:19 -04:00
|
|
|
// @Units: PWM
|
2016-10-29 08:01:18 -03:00
|
|
|
AP_GROUPINFO("NEUTRAL", 4, AP_Gripper, config.neutral_pwm, GRIPPER_NEUTRAL_PWM_DEFAULT),
|
|
|
|
|
|
|
|
// @Param: REGRAB
|
2022-07-31 22:45:52 -03:00
|
|
|
// @DisplayName: EPM Gripper Regrab interval
|
|
|
|
// @Description: Time in seconds that EPM gripper will regrab the cargo to ensure grip has not weakened; 0 to disable
|
2016-10-29 08:01:18 -03:00
|
|
|
// @User: Advanced
|
2017-01-06 12:15:35 -04:00
|
|
|
// @Range: 0 255
|
2017-05-02 10:43:35 -03:00
|
|
|
// @Units: s
|
2016-10-29 08:01:18 -03:00
|
|
|
AP_GROUPINFO("REGRAB", 5, AP_Gripper, config.regrab_interval, GRIPPER_REGRAB_DEFAULT),
|
|
|
|
|
2021-12-13 21:32:24 -04:00
|
|
|
// @Param: CAN_ID
|
2016-10-29 08:01:18 -03:00
|
|
|
// @DisplayName: EPM UAVCAN Hardpoint ID
|
|
|
|
// @Description: Refer to https://docs.zubax.com/opengrab_epm_v3#UAVCAN_interface
|
|
|
|
// @User: Standard
|
|
|
|
// @Range: 0 255
|
2021-12-13 21:32:24 -04:00
|
|
|
AP_GROUPINFO("CAN_ID", 6, AP_Gripper, config.uavcan_hardpoint_id, 0),
|
2016-10-29 08:01:18 -03:00
|
|
|
|
2022-07-31 22:45:52 -03:00
|
|
|
// @Param: AUTOCLOSE
|
|
|
|
// @DisplayName: Gripper Autoclose time
|
|
|
|
// @Description: Time in seconds that gripper close the gripper after opening; 0 to disable
|
|
|
|
// @User: Advanced
|
|
|
|
// @Range: 0.25 255
|
|
|
|
// @Units: s
|
|
|
|
AP_GROUPINFO("AUTOCLOSE", 7, AP_Gripper, config.autoclose_time, GRIPPER_AUTOCLOSE_DEFAULT),
|
|
|
|
|
2016-10-28 19:05:19 -03:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
|
|
|
AP_Gripper::AP_Gripper()
|
|
|
|
{
|
2019-02-10 14:31:01 -04:00
|
|
|
if (_singleton) {
|
2018-06-08 00:36:31 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
AP_HAL::panic("Too many grippers");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2019-02-10 14:31:01 -04:00
|
|
|
_singleton = this;
|
2018-06-08 00:36:31 -03:00
|
|
|
|
2016-10-28 19:05:19 -03:00
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
|
|
|
}
|
|
|
|
|
2018-06-08 00:36:31 -03:00
|
|
|
/*
|
|
|
|
* Get the AP_Gripper singleton
|
|
|
|
*/
|
2019-02-10 14:31:01 -04:00
|
|
|
AP_Gripper *AP_Gripper::_singleton = nullptr;
|
|
|
|
AP_Gripper *AP_Gripper::get_singleton()
|
2018-06-08 00:36:31 -03:00
|
|
|
{
|
2019-02-10 14:31:01 -04:00
|
|
|
return _singleton;
|
2018-06-08 00:36:31 -03:00
|
|
|
}
|
|
|
|
|
2016-10-28 19:05:19 -03:00
|
|
|
void AP_Gripper::init()
|
|
|
|
{
|
|
|
|
// return immediately if not enabled
|
|
|
|
if (!_enabled.get()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(config.type.get()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
2022-09-20 04:37:47 -03:00
|
|
|
#if AP_GRIPPER_SERVO_ENABLED
|
2016-10-28 19:05:19 -03:00
|
|
|
case 1:
|
2024-05-26 22:24:11 -03:00
|
|
|
backend = NEW_NOTHROW AP_Gripper_Servo(config);
|
2016-10-28 19:05:19 -03:00
|
|
|
break;
|
2022-09-20 04:37:47 -03:00
|
|
|
#endif
|
|
|
|
#if AP_GRIPPER_EPM_ENABLED
|
2016-10-29 08:01:18 -03:00
|
|
|
case 2:
|
2024-05-26 22:24:11 -03:00
|
|
|
backend = NEW_NOTHROW AP_Gripper_EPM(config);
|
2016-10-29 08:01:18 -03:00
|
|
|
break;
|
2022-09-20 04:37:47 -03:00
|
|
|
#endif
|
2016-10-28 19:05:19 -03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (backend != nullptr) {
|
|
|
|
backend->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update - should be called at at least 10hz
|
|
|
|
#define PASS_TO_BACKEND(function_name) \
|
|
|
|
void AP_Gripper::function_name() \
|
|
|
|
{ \
|
2016-10-29 08:01:18 -03:00
|
|
|
if (!enabled()) { \
|
|
|
|
return; \
|
|
|
|
} \
|
2016-10-28 19:05:19 -03:00
|
|
|
if (backend != nullptr) { \
|
|
|
|
backend->function_name(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
PASS_TO_BACKEND(grab)
|
|
|
|
PASS_TO_BACKEND(release)
|
|
|
|
PASS_TO_BACKEND(update)
|
|
|
|
|
|
|
|
#undef PASS_TO_BACKEND
|
2016-11-17 23:12:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
#define PASS_TO_BACKEND(function_name) \
|
|
|
|
bool AP_Gripper::function_name() const \
|
|
|
|
{ \
|
|
|
|
if (!enabled()) { \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
if (backend != nullptr) { \
|
|
|
|
return backend->function_name(); \
|
|
|
|
} \
|
|
|
|
return false; \
|
|
|
|
}
|
|
|
|
|
2016-11-18 03:52:15 -04:00
|
|
|
PASS_TO_BACKEND(valid)
|
2016-11-17 23:12:58 -04:00
|
|
|
PASS_TO_BACKEND(released)
|
|
|
|
PASS_TO_BACKEND(grabbed)
|
|
|
|
|
|
|
|
#undef PASS_TO_BACKEND
|
2018-06-08 00:36:31 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
|
2024-02-21 02:40:34 -04:00
|
|
|
AP_Gripper &gripper()
|
2018-06-08 00:36:31 -03:00
|
|
|
{
|
2024-02-21 02:40:34 -04:00
|
|
|
return *AP_Gripper::get_singleton();
|
2018-06-08 00:36:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2022-09-20 04:37:47 -03:00
|
|
|
|
|
|
|
#endif // AP_GRIPPER_ENABLED
|