AP_Gripper: a general gripper frontend
This commit is contained in:
parent
5a96db5a44
commit
a8435de65a
81
libraries/AP_Gripper/AP_Gripper.cpp
Normal file
81
libraries/AP_Gripper/AP_Gripper.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#include "AP_Gripper.h"
|
||||||
|
|
||||||
|
#include "AP_Gripper_Servo.h"
|
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
|
#define GRIPPER_GRAB_PWM_DEFAULT 1900
|
||||||
|
#define GRIPPER_RELEASE_PWM_DEFAULT 1100
|
||||||
|
|
||||||
|
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
|
||||||
|
// @Description: PWM value sent to Gripper to initiate grabbing the cargo
|
||||||
|
// @User: Advanced
|
||||||
|
// @Range: 1000 2000
|
||||||
|
AP_GROUPINFO("GRAB", 2, AP_Gripper, config.grab_pwm, GRIPPER_GRAB_PWM_DEFAULT),
|
||||||
|
|
||||||
|
// @Param: RELEASE
|
||||||
|
// @DisplayName: Gripper Release PWM
|
||||||
|
// @Description: PWM value sent to Gripper to release the cargo
|
||||||
|
// @User: Advanced
|
||||||
|
// @Range: 1000 2000
|
||||||
|
AP_GROUPINFO("RELEASE", 3, AP_Gripper, config.release_pwm, GRIPPER_RELEASE_PWM_DEFAULT),
|
||||||
|
|
||||||
|
AP_GROUPEND
|
||||||
|
};
|
||||||
|
|
||||||
|
AP_Gripper::AP_Gripper()
|
||||||
|
{
|
||||||
|
AP_Param::setup_object_defaults(this, var_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
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() \
|
||||||
|
{ \
|
||||||
|
if (backend != nullptr) { \
|
||||||
|
backend->function_name(); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
PASS_TO_BACKEND(grab)
|
||||||
|
PASS_TO_BACKEND(release)
|
||||||
|
PASS_TO_BACKEND(update)
|
||||||
|
|
||||||
|
#undef PASS_TO_BACKEND
|
52
libraries/AP_Gripper/AP_Gripper.h
Normal file
52
libraries/AP_Gripper/AP_Gripper.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
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_Param/AP_Param.h>
|
||||||
|
|
||||||
|
class AP_Gripper_Backend;
|
||||||
|
|
||||||
|
class AP_Gripper {
|
||||||
|
public:
|
||||||
|
AP_Gripper();
|
||||||
|
|
||||||
|
// initialise the gripper
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// grab - move the servo to the grab position
|
||||||
|
void grab();
|
||||||
|
|
||||||
|
// release - move the servo output to the release position
|
||||||
|
void release();
|
||||||
|
|
||||||
|
// update - should be called at at least 10hz
|
||||||
|
void update();
|
||||||
|
|
||||||
|
static const struct AP_Param::GroupInfo var_info[];
|
||||||
|
|
||||||
|
// parameters
|
||||||
|
AP_Int8 _enabled; // grabber enable/disable
|
||||||
|
|
||||||
|
struct Backend_Config {
|
||||||
|
AP_Int8 type; // grabber type (e.g. EPM or servo)
|
||||||
|
AP_Int16 grab_pwm; // PWM value sent to Gripper to initiate grabbing the cargo
|
||||||
|
AP_Int16 release_pwm; // PWM value sent to Gripper to release the cargo
|
||||||
|
} config;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
AP_Gripper_Backend *backend;
|
||||||
|
};
|
14
libraries/AP_Gripper/AP_Gripper_Backend.cpp
Normal file
14
libraries/AP_Gripper/AP_Gripper_Backend.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "AP_Gripper_Backend.h"
|
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
|
void AP_Gripper_Backend::init()
|
||||||
|
{
|
||||||
|
init_gripper();
|
||||||
|
}
|
||||||
|
|
||||||
|
// update - should be called at at least 10hz
|
||||||
|
void AP_Gripper_Backend::update()
|
||||||
|
{
|
||||||
|
update_gripper();
|
||||||
|
}
|
46
libraries/AP_Gripper/AP_Gripper_Backend.h
Normal file
46
libraries/AP_Gripper/AP_Gripper_Backend.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
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_Gripper/AP_Gripper.h>
|
||||||
|
|
||||||
|
class AP_Gripper_Backend {
|
||||||
|
public:
|
||||||
|
AP_Gripper_Backend(struct AP_Gripper::Backend_Config &_config) :
|
||||||
|
config(_config) { }
|
||||||
|
|
||||||
|
// initialise the gripper backend
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// update - should be called at at least 10hz
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// grab - move the servo to the grab position
|
||||||
|
virtual void grab() = 0;
|
||||||
|
|
||||||
|
// release - move the servo output to the release position
|
||||||
|
virtual void release() = 0;
|
||||||
|
|
||||||
|
// type-specific intiailisations:
|
||||||
|
virtual void init_gripper() = 0;
|
||||||
|
|
||||||
|
// type-specific periodic updates:
|
||||||
|
virtual void update_gripper() { };
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
struct AP_Gripper::Backend_Config &config;
|
||||||
|
};
|
24
libraries/AP_Gripper/AP_Gripper_Servo.cpp
Normal file
24
libraries/AP_Gripper/AP_Gripper_Servo.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <AP_Gripper/AP_Gripper_Servo.h>
|
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
|
void AP_Gripper_Servo::init_gripper()
|
||||||
|
{
|
||||||
|
// move the servo to the release position
|
||||||
|
RC_Channel_aux::set_radio(RC_Channel_aux::k_gripper, config.release_pwm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AP_Gripper_Servo::grab()
|
||||||
|
{
|
||||||
|
// move the servo to the release position
|
||||||
|
RC_Channel_aux::set_radio(RC_Channel_aux::k_gripper, config.grab_pwm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AP_Gripper_Servo::release()
|
||||||
|
{
|
||||||
|
// move the servo to the release position
|
||||||
|
RC_Channel_aux::set_radio(RC_Channel_aux::k_gripper, config.release_pwm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// type-specific periodic updates:
|
||||||
|
void AP_Gripper_Servo::update_gripper() { };
|
40
libraries/AP_Gripper/AP_Gripper_Servo.h
Normal file
40
libraries/AP_Gripper/AP_Gripper_Servo.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
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_Gripper/AP_Gripper_Backend.h>
|
||||||
|
#include <RC_Channel/RC_Channel.h>
|
||||||
|
|
||||||
|
class AP_Gripper_Servo : public AP_Gripper_Backend {
|
||||||
|
public:
|
||||||
|
|
||||||
|
AP_Gripper_Servo(struct AP_Gripper::Backend_Config &_config) :
|
||||||
|
AP_Gripper_Backend(_config) { }
|
||||||
|
|
||||||
|
// grab - move the servo to the grab position
|
||||||
|
void grab() override;
|
||||||
|
|
||||||
|
// release - move the servo output to the release position
|
||||||
|
void release() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// type-specific intiailisations:
|
||||||
|
void init_gripper() override;
|
||||||
|
|
||||||
|
// type-specific periodic updates:
|
||||||
|
void update_gripper() override;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user