|
|
|
|
|
|
|
|
motors[3] += speed; |
|
|
motors[3] += speed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ControlModule::rotate(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; |
|
|
|
|
|
|
|
|
void ControlModule::drive(double ratio) |
|
|
|
|
|
{ |
|
|
|
|
|
motors[0] += ratio; |
|
|
|
|
|
motors[1] += ratio; |
|
|
|
|
|
motors[2] += ratio; |
|
|
|
|
|
motors[3] += ratio; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
motors[0] += speed; |
|
|
|
|
|
motors[1] -= speed; |
|
|
|
|
|
motors[2] += speed; |
|
|
|
|
|
motors[3] -= speed; |
|
|
|
|
|
|
|
|
void ControlModule::rotate(double ratio) |
|
|
|
|
|
{ |
|
|
|
|
|
motors[0] += ratio; |
|
|
|
|
|
motors[1] -= ratio; |
|
|
|
|
|
motors[2] += ratio; |
|
|
|
|
|
motors[3] -= ratio; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ControlModule::unit(){ |
|
|
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); |
|
|
|
|
|
rotate(angle); |
|
|
|
|
|
|
|
|
double rotationRatio = ratio(angle); |
|
|
|
|
|
rotate(rotationRatio); |
|
|
|
|
|
drive(1.0-rotationRatio); |
|
|
unit(); |
|
|
unit(); |
|
|
adjustSpeed(); |
|
|
adjustSpeed(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
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); |
|
|
|
|
|
} |