24 lines
652 B
C++
24 lines
652 B
C++
#include "ControlledMotor.h"
|
|
|
|
ControlledMotor::ControlledMotor() {
|
|
// this->isControlledMotor = true;
|
|
this->type = Type::ControlledMotor;
|
|
}
|
|
|
|
ControlledMotor::ControlledMotor(Motor* motor, Encoder* encoder) {
|
|
this->motor = motor;
|
|
this->encoder = encoder;
|
|
}
|
|
|
|
void ControlledMotor::SetTargetSpeed(float velocity) {
|
|
this->targetVelocity = velocity;
|
|
}
|
|
|
|
void ControlledMotor::Update(float timeStep) {
|
|
float velocity = GetActualSpeed();
|
|
float error = targetVelocity - velocity;
|
|
|
|
float acceleration =
|
|
error * timeStep * pidP; // Just P is used at this moment
|
|
motor->SetSpeed(targetVelocity + acceleration); // or something like that
|
|
} |