moved pid settings to menuIntInput
This commit is contained in:
@@ -13,81 +13,10 @@
|
|||||||
|
|
||||||
MenuPidSettings::MenuPidSettings(PID* pid) {
|
MenuPidSettings::MenuPidSettings(PID* pid) {
|
||||||
this->pid = pid;
|
this->pid = pid;
|
||||||
this->values[0] = (uint8_t) pid->GetKp();
|
|
||||||
this->values[1] = (uint8_t) pid->GetKi();
|
|
||||||
this->values[2] = (uint8_t) pid->GetKd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuPidSettings::down() {
|
void MenuPidSettings::action(int16_t* values, uint8_t length) {
|
||||||
if (values[curPos] > 0)
|
if (length != 3)
|
||||||
values[curPos]--;
|
return;
|
||||||
|
this->pid->SetTunings(values[0], values[1], values[2]);
|
||||||
this->printMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuPidSettings::up() {
|
|
||||||
if (values[curPos] < UINT8_MAX)
|
|
||||||
values[curPos]++;
|
|
||||||
|
|
||||||
this->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuPidSettings::right() {
|
|
||||||
if (curPos < NUM_VAL - 1)
|
|
||||||
curPos++;
|
|
||||||
else
|
|
||||||
curPos = 0;
|
|
||||||
|
|
||||||
this->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuPidSettings::left() {
|
|
||||||
if (curPos > 0)
|
|
||||||
curPos--;
|
|
||||||
else
|
|
||||||
curPos = NUM_VAL - 1;
|
|
||||||
|
|
||||||
this->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuPidSettings::no() {
|
|
||||||
if (parentMenu)
|
|
||||||
this->parentMenu->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuPidSettings::yes() {
|
|
||||||
this->pid->SetTunings(this->values[0], this->values[1], this->values[2]);
|
|
||||||
if (parentMenu)
|
|
||||||
this->parentMenu->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuPidSettings::printMenu() {
|
|
||||||
char buf[17];
|
|
||||||
switch (this->curPos) {
|
|
||||||
case 0:
|
|
||||||
sprintf(buf, "_%3.d_ %3.d %3.d ", this->values[0], this->values[1], this->values[2]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
sprintf(buf, " %3.d _%3.d_ %3.d ", this->values[0], this->values[1], this->values[2]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
sprintf(buf, " %3.d %3.d _%3.d_", this->values[0], this->values[1], this->values[2]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (this->lcd) {
|
|
||||||
lcd->clear();
|
|
||||||
lcd->setCursor(0, 0);
|
|
||||||
lcd->print(" P I D ");
|
|
||||||
lcd->setCursor(0, 1);
|
|
||||||
lcd->print(buf);
|
|
||||||
}
|
|
||||||
std::cout << " P I D " << std::endl;
|
|
||||||
std::cout << buf << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,17 +12,15 @@
|
|||||||
#ifndef PID_SETTINGS_H
|
#ifndef PID_SETTINGS_H
|
||||||
#define PID_SETTINGS_H
|
#define PID_SETTINGS_H
|
||||||
|
|
||||||
#include "menuControl.h"
|
#include "menuIntInput.h"
|
||||||
#include <PID_v1.h>
|
#include <PID_v1.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define NUM_VAL 3
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A class to tune the PID settings
|
* @brief A class to tune the PID settings
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class MenuPidSettings : public MenuControl {
|
class MenuPidSettings : public MenuIntInputWrapper {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Menu Pid Settings object
|
* @brief Construct a new Menu Pid Settings object
|
||||||
@@ -31,50 +29,10 @@ class MenuPidSettings : public MenuControl {
|
|||||||
*/
|
*/
|
||||||
MenuPidSettings(PID* pid);
|
MenuPidSettings(PID* pid);
|
||||||
|
|
||||||
/**
|
void action(int16_t* values, uint8_t length);
|
||||||
* @brief Decrement selected value
|
|
||||||
*/
|
|
||||||
void down() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Increment selected value
|
|
||||||
*/
|
|
||||||
void up() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Select next value
|
|
||||||
*/
|
|
||||||
void right() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Select previous value
|
|
||||||
*/
|
|
||||||
void left() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Leave menu without saving
|
|
||||||
*/
|
|
||||||
void no() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Leave menu with saving
|
|
||||||
*/
|
|
||||||
void yes() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prints the Information to display and console
|
|
||||||
*
|
|
||||||
* The informations are only printed to the display if it
|
|
||||||
* set.
|
|
||||||
*/
|
|
||||||
void printMenu() override;
|
|
||||||
|
|
||||||
void update() override {};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PID* pid;
|
PID* pid;
|
||||||
uint8_t values[NUM_VAL];
|
|
||||||
uint8_t curPos = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -274,8 +274,10 @@ void makeMenu() {
|
|||||||
main_m = new Menu();
|
main_m = new Menu();
|
||||||
Menu* mode_m = new Menu();
|
Menu* mode_m = new Menu();
|
||||||
Menu* pid_m = new Menu();
|
Menu* pid_m = new Menu();
|
||||||
MenuPidSettings* pidl_m = new MenuPidSettings(moveController.getPID(0));
|
MenuIntInput* pidl_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(0)));
|
||||||
MenuPidSettings* pidr_m = new MenuPidSettings(moveController.getPID(1));
|
MenuIntInput* pidr_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(1)));
|
||||||
|
// MenuPidSettings* pidl_m = new MenuPidSettings(moveController.getPID(0));
|
||||||
|
// MenuPidSettings* pidr_m = new MenuPidSettings(moveController.getPID(1));
|
||||||
MenuManualControl* man_m = new MenuManualControl(driveManager);
|
MenuManualControl* man_m = new MenuManualControl(driveManager);
|
||||||
MenuCaptureRoute* cap_m = new MenuCaptureRoute(driveManager);
|
MenuCaptureRoute* cap_m = new MenuCaptureRoute(driveManager);
|
||||||
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
|
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
|
||||||
@@ -332,4 +334,15 @@ void makeMenu() {
|
|||||||
MenuAction* pidr_e = new MenuAction("Right", pidr_m);
|
MenuAction* pidr_e = new MenuAction("Right", pidr_m);
|
||||||
pid_m->addEntry(pidl_e);
|
pid_m->addEntry(pidl_e);
|
||||||
pid_m->addEntry(pidr_e);
|
pid_m->addEntry(pidr_e);
|
||||||
|
|
||||||
|
// Other config
|
||||||
|
pidl_m->setMinMax(0, UINT8_MAX);
|
||||||
|
pidl_m->setEntry(0, "P-Part", (uint8_t) moveController.getPID(0)->GetKp());
|
||||||
|
pidl_m->setEntry(1, "I-Part", (uint8_t) moveController.getPID(0)->GetKi());
|
||||||
|
pidl_m->setEntry(2, "D-Part", (uint8_t) moveController.getPID(0)->GetKd());
|
||||||
|
|
||||||
|
pidr_m->setMinMax(0, UINT8_MAX);
|
||||||
|
pidr_m->setEntry(0, "P-Part", (uint8_t) moveController.getPID(1)->GetKp());
|
||||||
|
pidr_m->setEntry(1, "I-Part", (uint8_t) moveController.getPID(1)->GetKi());
|
||||||
|
pidr_m->setEntry(2, "D-Part", (uint8_t) moveController.getPID(1)->GetKd());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user