mirror of https://github.com/ArduPilot/ardupilot
uncrustify libraries/AC_PID/examples/AC_PID_test/AC_PID_test.pde
This commit is contained in:
parent
753ac6c27b
commit
2f5b292d50
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Example of PID library.
|
||||
2012 Code by Jason Short, Randy Mackay. DIYDrones.com
|
||||
*/
|
||||
* Example of PID library.
|
||||
* 2012 Code by Jason Short, Randy Mackay. DIYDrones.com
|
||||
*/
|
||||
|
||||
// includes
|
||||
#include <Arduino_Mega_ISR_Registry.h>
|
||||
|
@ -26,39 +26,39 @@ APM_RC_APM1 APM_RC;
|
|||
// setup function
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("ArduPilot Mega AC_PID library test");
|
||||
Serial.begin(115200);
|
||||
Serial.println("ArduPilot Mega AC_PID library test");
|
||||
|
||||
isr_registry.init();
|
||||
APM_RC.Init(&isr_registry); // APM Radio initialization
|
||||
isr_registry.init();
|
||||
APM_RC.Init(&isr_registry); // APM Radio initialization
|
||||
|
||||
delay(1000);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// main loop
|
||||
void loop()
|
||||
{
|
||||
// setup (unfortunately must be done here as we cannot create a global AC_PID object)
|
||||
AC_PID pid(0, PSTR("TESTPID_"), TEST_P, TEST_I, TEST_D, TEST_IMAX * 100);
|
||||
uint16_t radio_in;
|
||||
uint16_t radio_trim;
|
||||
int error;
|
||||
int control;
|
||||
float dt = 1000/50;
|
||||
// setup (unfortunately must be done here as we cannot create a global AC_PID object)
|
||||
AC_PID pid(0, PSTR("TESTPID_"), TEST_P, TEST_I, TEST_D, TEST_IMAX * 100);
|
||||
uint16_t radio_in;
|
||||
uint16_t radio_trim;
|
||||
int error;
|
||||
int control;
|
||||
float dt = 1000/50;
|
||||
|
||||
// display PID gains
|
||||
Serial.printf("P %f I %f D %f imax %f\n", pid.kP(), pid.kI(), pid.kD(), pid.imax());
|
||||
// display PID gains
|
||||
Serial.printf("P %f I %f D %f imax %f\n", pid.kP(), pid.kI(), pid.kD(), pid.imax());
|
||||
|
||||
// capture radio trim
|
||||
radio_trim = APM_RC.InputCh(0);
|
||||
// capture radio trim
|
||||
radio_trim = APM_RC.InputCh(0);
|
||||
|
||||
while( true ) {
|
||||
radio_in = APM_RC.InputCh(0);
|
||||
error = radio_in - radio_trim;
|
||||
control = pid.get_pid(error, dt);
|
||||
while( true ) {
|
||||
radio_in = APM_RC.InputCh(0);
|
||||
error = radio_in - radio_trim;
|
||||
control = pid.get_pid(error, dt);
|
||||
|
||||
// display pid results
|
||||
Serial.printf("radio: %d\t err: %d\t pid:%d\n", radio_in, error, control);
|
||||
delay(50);
|
||||
}
|
||||
// display pid results
|
||||
Serial.printf("radio: %d\t err: %d\t pid:%d\n", radio_in, error, control);
|
||||
delay(50);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue