refactore
all components now have a base class compnent for loop functions
This commit is contained in:
2023-08-18 10:47:35 +02:00
parent 25d37e3970
commit 11d21e2e89
35 changed files with 303 additions and 511 deletions
+3 -45
View File
@@ -20,6 +20,7 @@
#include "speedometer.h"
#include "moveControlConfig.h"
#include "debugTimes.h"
#include "component.h"
/**
@@ -30,7 +31,7 @@
* given target speed to calculate a new duty cycle for the motors.
*
*/
class MoveControl {
class MoveControl : public Component {
public:
/**
* @brief used to set driving status
@@ -58,22 +59,6 @@ class MoveControl {
*/
~MoveControl();
/**
* @brief Calls runMoveControl() to update all Values.
*
* Besides that this function calls the loop() functions for the motors and encodes.
* This function should be called every mainloop. If the delay is not reached, than the
* functions returns immediately.
* @see runMoveControl()
* @see setDelay()
*/
void loop();
/**
* @brief Normally called repeatedly by loop() to calculate new values.
*/
void runMoveControl();
/**
* @brief Set the Status
*
@@ -159,36 +144,11 @@ class MoveControl {
uint16_t getDutycycleLeft() const { return this->left_motor->getDutycycle(); }
uint16_t getDutycycleRight() const { return this->right_motor->getDutycycle(); }
/**
* @brief Set the min delay between each loop
*
* @param delay_ time in Milliseconds
*/
void setDelay(uint8_t delay) { this->delay = delay; }
private:
void run() override;
void setSpeedometerDirection(Speedometer *speedometer, double value);
/**
* @brief Converts values into wheel speeds
*
* Converts target speed and target rotationspeed into
* wheel speeds
*/
void calcTargetWheelSpeed();
/**
* @brief Set the target power to motors
*
* Checks if the driving_status is set to Drive.
* If yes, then the motors get the pid_out values as targetpower.
* If no, then the motors target power is set to zero.
*/
void regulateMotors();
/**
* @brief Updates the wheel speeds with speedometer
*/
void updateCurrentWheelSpeed();
MotorControl *left_motor;
@@ -210,11 +170,9 @@ class MoveControl {
double left_pid_out;
double right_pid_out;
uint8_t delay = 20;
uint8_t overTimeCounter = 0;
uint8_t overTimeMax = 100;
int8_t rawPowerLeft = 0;
int8_t rawPowerRight = 0;
uint32_t lastMillis = 0;
};
#endif // MOVE_CONTROL_H