2016-10-28 19:05:19 -03:00
|
|
|
#include "AP_Gripper.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
#define GRIPPER_REGRAB_DEFAULT 0 // default re-grab interval (in seconds) to ensure cargo is securely held
|
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
|
|
|
|
// @DisplayName: Gripper Regrab interval
|
|
|
|
// @Description: Time in seconds that gripper will regrab the cargo to ensure grip has not weakened; 0 to disable
|
|
|
|
// @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),
|
|
|
|
|
|
|
|
// @Param: UAVCAN_ID
|
|
|
|
// @DisplayName: EPM UAVCAN Hardpoint ID
|
|
|
|
// @Description: Refer to https://docs.zubax.com/opengrab_epm_v3#UAVCAN_interface
|
|
|
|
// @User: Standard
|
|
|
|
// @Range: 0 255
|
|
|
|
AP_GROUPINFO("UAVCAN_ID", 6, AP_Gripper, config.uavcan_hardpoint_id, 0),
|
|
|
|
|
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;
|
|
|
|
case 1:
|
|
|
|
backend = new AP_Gripper_Servo(config);
|
|
|
|
break;
|
2016-10-29 08:01:18 -03:00
|
|
|
case 2:
|
|
|
|
backend = new AP_Gripper_EPM(config);
|
|
|
|
break;
|
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 {
|
|
|
|
|
|
|
|
AP_Gripper *gripper()
|
|
|
|
{
|
2019-02-10 14:31:01 -04:00
|
|
|
return AP_Gripper::get_singleton();
|
2018-06-08 00:36:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|