Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/yasarba71520/Line-Following-Robot
This commit is contained in:
commit
6a55bda519
@ -48,24 +48,20 @@ void ControlModule::moveSide(int imageColumsMiddle, int contourColumsMiddle){
|
|||||||
motors[3] += speed;
|
motors[3] += speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlModule::rotate(double angle){
|
void ControlModule::drive(double ratio)
|
||||||
double minAngularSpeed = -1.0;
|
{
|
||||||
double maxAngularSpeed = 1.0;
|
motors[0] += ratio;
|
||||||
double speedRange = maxAngularSpeed - minAngularSpeed;
|
motors[1] += ratio;
|
||||||
|
motors[2] += ratio;
|
||||||
|
motors[3] += ratio;
|
||||||
|
}
|
||||||
|
|
||||||
double minAngle = -90.0;
|
void ControlModule::rotate(double ratio)
|
||||||
double maxAngle = 90.0;
|
{
|
||||||
double angularRange = maxAngle - minAngle;
|
motors[0] += ratio;
|
||||||
|
motors[1] -= ratio;
|
||||||
double progress = angle - minAngle;
|
motors[2] += ratio;
|
||||||
double progressPercent = progress/angularRange;
|
motors[3] -= ratio;
|
||||||
|
|
||||||
double speed = minAngularSpeed + progressPercent*speedRange;
|
|
||||||
|
|
||||||
motors[0] += speed;
|
|
||||||
motors[1] -= speed;
|
|
||||||
motors[2] += speed;
|
|
||||||
motors[3] -= speed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlModule::unit(){
|
void ControlModule::unit(){
|
||||||
@ -87,8 +83,9 @@ void ControlModule::unit(){
|
|||||||
|
|
||||||
void ControlModule::calcSpeeds(int imageColumsMiddle, int contourColumsMiddle, double angle){
|
void ControlModule::calcSpeeds(int imageColumsMiddle, int contourColumsMiddle, double angle){
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
//moveSide(imageColumsMiddle, contourColumsMiddle);
|
double rotationRatio = ratio(angle);
|
||||||
rotate(angle);
|
rotate(rotationRatio);
|
||||||
|
drive(1.0-rotationRatio);
|
||||||
unit();
|
unit();
|
||||||
adjustSpeed();
|
adjustSpeed();
|
||||||
}
|
}
|
||||||
@ -97,4 +94,21 @@ std::vector<double> ControlModule::readMotors()
|
|||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
return std::vector<double> {motors[0], motors[1], motors[2], motors[3]};
|
return std::vector<double> {motors[0], motors[1], motors[2], motors[3]};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ControlModule::ratio(double angle)
|
||||||
|
{
|
||||||
|
double minAngularSpeed = -1.0;
|
||||||
|
double maxAngularSpeed = 1.0;
|
||||||
|
double speedRange = maxAngularSpeed - minAngularSpeed;
|
||||||
|
|
||||||
|
double minAngle = -90.0;
|
||||||
|
double maxAngle = 90.0;
|
||||||
|
double angularRange = maxAngle - minAngle;
|
||||||
|
|
||||||
|
double progress = angle - minAngle;
|
||||||
|
double progressPercent = progress/angularRange;
|
||||||
|
|
||||||
|
double speed = minAngularSpeed + progressPercent*speedRange;
|
||||||
|
return abs(speed);
|
||||||
|
}
|
@ -17,8 +17,10 @@ public:
|
|||||||
~ControlModule();
|
~ControlModule();
|
||||||
void adjustSpeed();
|
void adjustSpeed();
|
||||||
void moveSide(int imageColumsMiddle, int contourColumsMiddle);
|
void moveSide(int imageColumsMiddle, int contourColumsMiddle);
|
||||||
void rotate(double angle);
|
void rotate(double ratio);
|
||||||
|
void drive(double ratio);
|
||||||
void unit(); //Brings the max Value to 1.0
|
void unit(); //Brings the max Value to 1.0
|
||||||
|
double ratio(double angle);
|
||||||
|
|
||||||
void calcSpeeds(int imageColumsMiddle, int contourColumsMiddle, double angle); //Funktion to be called
|
void calcSpeeds(int imageColumsMiddle, int contourColumsMiddle, double angle); //Funktion to be called
|
||||||
std::vector<double> readMotors();
|
std::vector<double> readMotors();
|
||||||
|
@ -144,6 +144,10 @@ void Processing::calcAngles(FrameData &data, int imageColums, int imageRows, boo
|
|||||||
LFRVector b(contourCenter-focusPoint);
|
LFRVector b(contourCenter-focusPoint);
|
||||||
|
|
||||||
double angle = a.angle(b);
|
double angle = a.angle(b);
|
||||||
|
if (b.x < 0.0)
|
||||||
|
{
|
||||||
|
angle *= -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
//Write to Data
|
//Write to Data
|
||||||
data.angle = angle;
|
data.angle = angle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user