AP_EPM: EPM cargo gripper library

This commit is contained in:
ctech4285 2013-12-17 13:59:14 +09:00 committed by Randy Mackay
parent 62fcfd8d9b
commit c8aff81c48
2 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,84 @@
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/*
* AP_EPM.cpp
*
* Created on: DEC 6, 2013
* Author: Andreas Jochum
*/
#include <AP_HAL.h>
#include "AP_EPM.h"
extern const AP_HAL::HAL& hal;
const AP_Param::GroupInfo AP_EPM::var_info[] PROGMEM = {
// @Param: ENABLE
// @DisplayName: EPM Enable/Disable
// @Description: EPM enable/disable. Note enabling will disable the external LEDs on the APM2
// @User: Standard
// @Values: 0:Disabled, 1:Enabled
AP_GROUPINFO("ENABLE", 0, AP_EPM, _enabled, 0),
AP_GROUPEND
};
AP_EPM::AP_EPM(void)
{
AP_Param::setup_object_defaults(this, var_info);
}
void AP_EPM::init()
{
// return immediately if not enabled
if (!_enabled || !EPM_SUPPORTED) {
return;
}
hal.gpio->pinMode(EPM_PIN_1, GPIO_OUTPUT);
hal.gpio->pinMode(EPM_PIN_2, GPIO_OUTPUT);
neutral();
}
bool AP_EPM::enabled()
{
if (!EPM_SUPPORTED) {
return false;
}
return _enabled;
}
void AP_EPM::on()
{
// return immediately if not enabled
if (!_enabled || !EPM_SUPPORTED) {
return;
}
hal.gpio->write(EPM_PIN_1, 1);
hal.gpio->write(EPM_PIN_2, 0);
}
void AP_EPM::off()
{
// return immediately if not enabled
if (!_enabled || !EPM_SUPPORTED) {
return;
}
hal.gpio->write(EPM_PIN_1, 0);
hal.gpio->write(EPM_PIN_2, 1);
}
void AP_EPM::neutral()
{
// return immediately if not enabled
if (!_enabled || !EPM_SUPPORTED) {
return;
}
hal.gpio->write(EPM_PIN_1, 0);
hal.gpio->write(EPM_PIN_2, 0);
}

66
libraries/AP_EPM/AP_EPM.h Normal file
View File

@ -0,0 +1,66 @@
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/*
* AP_EPM.h
*
* Created on: DEC 06, 2013
* Author: Andreas Jochum
*/
/// @file AP_EPM.h
/// @brief AP_EPM control class
#ifndef __AP_EPM_h__
#define __AP_EPM_h__
#include <inttypes.h>
#include <AP_Common.h>
#include <AP_Param.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_APM2
#define EPM_PIN_1 61 // On pin - AN7
#define EPM_PIN_2 62 // Off pin - AN8
#define EPM_SUPPORTED true
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1
#define EPM_PIN_1 -1 // to be determine
#define EPM_PIN_2 -1 // to be determine
#define EPM_SUPPORTED false
#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4
#define EPM_PIN_1 -1 // to be determine
#define EPM_PIN_2 -1 // to be determine
#define EPM_SUPPORTED false
#else
#define EPM_PIN_1 -1 // not supported
#define EPM_PIN_2 -1 // not supported
#define EPM_SUPPORTED false
#endif
/// @class AP_EPM
/// @brief Class to manage the EPM_CargoGripper
class AP_EPM {
public:
AP_EPM();
// setup the epm pins
void init();
// enabled - true if the epm is enabled
bool enabled();
// activate the EPM
void on();
// de-activate the EPM
void off();
// do nothing
void neutral();
static const struct AP_Param::GroupInfo var_info[];
private:
AP_Int8 _enabled;
};
#endif /* _AP_EPM_H_ */