cleaning
refactore all components now have a base class compnent for loop functions
This commit is contained in:
+10
-36
@@ -11,6 +11,7 @@
|
||||
#include "moveControl.h"
|
||||
|
||||
MoveControl::MoveControl() {
|
||||
this->loopDelay = 20;
|
||||
this->left_motor = new MotorControl();
|
||||
this->right_motor = new MotorControl();
|
||||
this->left_speedometer = new Speedometer(M_ENCODE_LEFT, WHEEL_DIAMETER, ENC_STEPS);
|
||||
@@ -36,7 +37,12 @@ MoveControl::MoveControl() {
|
||||
this->right_pid->SetMode(AUTOMATIC);
|
||||
|
||||
this->left_motor->init(M_PWM_1, PWM_CHANNEL_M1, M_DIR_11, M_DIR_12);
|
||||
this->right_motor->init(M_PWM_2, PWM_CHANNEL_M2, M_DIR_21, M_DIR_22);
|
||||
this->right_motor->init(M_PWM_2, PWM_CHANNEL_M2, M_DIR_21, M_DIR_22);
|
||||
|
||||
this->addChildComponent(this->left_motor);
|
||||
this->addChildComponent(this->right_motor);
|
||||
this->addChildComponent(this->left_speedometer);
|
||||
this->addChildComponent(this->right_speedometer);
|
||||
}
|
||||
|
||||
MoveControl::~MoveControl() {
|
||||
@@ -52,39 +58,7 @@ MoveControl::~MoveControl() {
|
||||
|
||||
}
|
||||
|
||||
void MoveControl::loop() {
|
||||
uint16_t left_motor_time = this->left_motor->loop();
|
||||
uint16_t right_motor_time = this->right_motor->loop();
|
||||
uint16_t left_speed_time = this->left_speedometer->loop();
|
||||
uint16_t right_speed_time = this->right_speedometer->loop();
|
||||
|
||||
if (left_motor_time > 50
|
||||
|| right_motor_time > 50
|
||||
|| left_speed_time > 50
|
||||
|| right_speed_time > 50) {
|
||||
|
||||
// Dont count overTimeCounter if one speedometer is in TestMode.
|
||||
if (left_speed_time == UINT16_MAX || right_speed_time == UINT16_MAX)
|
||||
this->overTimeCounter--;
|
||||
|
||||
this->overTimeCounter++;
|
||||
if (this->overTimeCounter >= this->overTimeMax) {
|
||||
char buf[128];
|
||||
sprintf(buf, "left M: %d, right M %d, left S %d, right S %d in moveControl::loop\n",
|
||||
left_motor_time, right_motor_time, left_speed_time, right_speed_time);
|
||||
std::cout << buf;
|
||||
this->overTimeCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (millis() - this->lastMillis < this->delay)
|
||||
return;
|
||||
|
||||
this->runMoveControl();
|
||||
this->lastMillis = millis();
|
||||
}
|
||||
|
||||
void MoveControl::runMoveControl() {
|
||||
void MoveControl::run() {
|
||||
this->updateCurrentWheelSpeed();
|
||||
this->calcTargetWheelSpeed();
|
||||
|
||||
@@ -207,8 +181,8 @@ void MoveControl::regulateMotors() {
|
||||
case Status::Drive :
|
||||
this->left_motor->setTargetPower( (int8_t) this->left_pid_out);
|
||||
this->right_motor->setTargetPower( (int8_t) this->right_pid_out);
|
||||
this->setSpeedometerDirection(this->left_speedometer, this->left_pid_out);
|
||||
this->setSpeedometerDirection(this->right_speedometer, this->right_pid_out);
|
||||
this->setSpeedometerDirection(this->left_speedometer, this->left_motor->getPower());
|
||||
this->setSpeedometerDirection(this->right_speedometer, this->right_motor->getPower());
|
||||
break;
|
||||
|
||||
case Status::Raw :
|
||||
|
||||
Reference in New Issue
Block a user