AP_HAL: Add RCOutput interactive example with Menu

This commit is contained in:
hiro2233 2016-04-01 05:03:22 -04:00 committed by Lucas De Marchi
parent cc24f323d2
commit 7814841cd6
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1 @@
include ../../../../mk/apm.mk

View File

@ -0,0 +1,88 @@
/*
Simple test of RC output interface with Menu
*/
#include <AP_Common/AP_Common.h>
#include <AP_HAL/AP_HAL.h>
#include <AP_Menu/AP_Menu.h>
#define MENU_FUNC(func) FUNCTOR_BIND(&commands, &Menu_Commands::func, int8_t, uint8_t, const Menu::arg *)
#define ESC_HZ 490
#define SERVO_HZ 50
class Menu_Commands {
public:
/* Menu commands to drive a SERVO type with
* repective PWM output freq defined by SERVO_HZ
*/
int8_t menu_servo(uint8_t argc, const Menu::arg *argv);
/* Menu commands to drive a ESC type with
* repective PWM output freq defined by ESC_HZ
*/
int8_t menu_esc(uint8_t argc, const Menu::arg *argv);
};
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
Menu_Commands commands;
static uint16_t pwm = 1500;
static int8_t delta = 1;
/* Function to drive a RC output TYPE especified */
void drive(uint16_t hz_speed) {
hal.rcout->set_freq(0xFF, hz_speed);
while (1) {
for (uint8_t i = 0; i < 14; i++) {
hal.rcout->write(i, pwm);
pwm += delta;
if (delta > 0 && pwm >= 2000) {
delta = -1;
hal.console->printf("reversing\n");
} else if (delta < 0 && pwm <= 1000) {
delta = 1;
hal.console->printf("normalizing\n");
}
}
hal.scheduler->delay(5);
if (hal.console->available()) {
break;
}
}
}
int8_t Menu_Commands::menu_servo(uint8_t argc, const Menu::arg *argv) {
drive(SERVO_HZ);
return 0;
}
int8_t Menu_Commands::menu_esc(uint8_t argc, const Menu::arg *argv) {
drive(ESC_HZ);
return 0;
}
const struct Menu::command rcoutput_menu_commands[] = {
{ "servo", MENU_FUNC(menu_servo) },
{ "esc", MENU_FUNC(menu_esc) },
};
MENU(menu, "Menu: ", rcoutput_menu_commands);
void setup(void) {
hal.console->println("Starting AP_HAL::RCOutput test");
for (uint8_t i = 0; i < 14; i++) {
hal.rcout->enable_ch(i);
}
}
void loop(void) {
/* We call and run the menu, you can type help into menu to show commands
* available */
menu.run();
}
AP_HAL_MAIN();

View File

@ -0,0 +1,26 @@
LIBRARIES += AP_ADC
LIBRARIES += AP_AHRS
LIBRARIES += AP_Airspeed
LIBRARIES += AP_Baro
LIBRARIES += AP_BattMonitor
LIBRARIES += AP_Common
LIBRARIES += AP_Compass
LIBRARIES += AP_Declination
LIBRARIES += AP_GPS
LIBRARIES += AP_InertialSensor
LIBRARIES += AP_AccelCal
LIBRARIES += AP_Math
LIBRARIES += AP_Mission
LIBRARIES += AP_NavEKF
LIBRARIES += AP_Notify
LIBRARIES += AP_Param
LIBRARIES += AP_Rally
LIBRARIES += AP_RangeFinder
LIBRARIES += AP_Scheduler
LIBRARIES += AP_Terrain
LIBRARIES += AP_Vehicle
LIBRARIES += DataFlash
LIBRARIES += Filter
LIBRARIES += GCS_MAVLink
LIBRARIES += StorageManager
LIBRARIES += AP_Menu

View File

@ -0,0 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
def build(bld):
bld.ap_example(
use='ap',
)