ardupilot/libraries/PID/examples/pid/pid.cpp
Gustavo Jose de Sousa e925820d90 PID: standardize inclusion of libaries headers
This commit changes the way libraries headers are included in source files:

 - If the header is in the same directory the source belongs to, so the
 notation '#include ""' is used with the path relative to the directory
 containing the source.

 - If the header is outside the directory containing the source, then we use
 the notation '#include <>' with the path relative to libraries folder.

Some of the advantages of such approach:

 - Only one search path for libraries headers.

 - OSs like Windows may have a better lookup time.
2015-08-11 16:38:25 +10:00

60 lines
1.2 KiB
C++

/*
* Example of PID library.
* 2010 Code by Jason Short. DIYDrones.com
*/
#include <AP_HAL/AP_HAL.h>
#include <AP_Common/AP_Common.h>
#include <AP_Progmem/AP_Progmem.h>
#include <AP_Param/AP_Param.h>
#include <StorageManager/StorageManager.h>
#include <AP_Math/AP_Math.h>
#include <PID/PID.h> // ArduPilot Mega RC Library
#include <AP_HAL_AVR/AP_HAL_AVR.h>
#include <AP_HAL_SITL/AP_HAL_SITL.h>
#include <AP_HAL_Empty/AP_HAL_Empty.h>
const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;
long radio_in;
long radio_trim;
PID pid;
void setup()
{
hal.console->println("ArduPilot Mega PID library test");
hal.scheduler->delay(1000);
//rc.trim();
radio_trim = hal.rcin->read(0);
pid.kP(1);
pid.kI(0);
pid.kD(0.5f);
pid.imax(50);
pid.save_gains();
pid.kP(0);
pid.kI(0);
pid.kD(0);
pid.imax(0);
pid.load_gains();
hal.console->printf_P(
PSTR("P %f I %f D %f imax %f\n"),
pid.kP(), pid.kI(), pid.kD(), pid.imax());
}
void loop()
{
hal.scheduler->delay(20);
//rc.read_pwm();
long error = hal.rcin->read(0) - radio_trim;
long control= pid.get_pid(error, 1);
hal.console->print("control: ");
hal.console->println(control,BASE_DEC);
}
AP_HAL_MAIN();