Compare commits

..
5 Commits
Author SHA1 Message Date
zeunerti74726 3dea00a8d1 Too big too handle 2023-03-03 19:48:03 +01:00
zeunerti74726 960b05e76f Testfahrten 2023-03-03 18:57:35 +01:00
zeunerti74726 94e9c4ba7a Faster! 2023-03-03 18:47:41 +01:00
zeunerti74726 6da9bfff54 Bugs found during tests 2023-03-03 18:46:31 +01:00
zeunerti74726 c40b69ebe2 Save video 2023-03-03 18:45:03 +01:00
4 changed files with 42 additions and 15 deletions
@@ -36,7 +36,7 @@ void ControlModule::adjustSpeed(){
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
motors[i] *= maxSpeed; motors[i] *= factor;
} }
}; };
@@ -85,7 +85,7 @@ void ControlModule::calcSpeeds(int imageColumsMiddle, int contourColumsMiddle, d
std::unique_lock<std::mutex> lock(mtx); std::unique_lock<std::mutex> lock(mtx);
double rotationRatio = ratio(angle); double rotationRatio = ratio(angle);
rotate(rotationRatio); rotate(rotationRatio);
drive(1.0-rotationRatio); drive(1.0-std::fabs(rotationRatio));
unit(); unit();
adjustSpeed(); adjustSpeed();
} }
@@ -102,13 +102,21 @@ double ControlModule::ratio(double angle)
double maxAngularSpeed = 1.0; double maxAngularSpeed = 1.0;
double speedRange = maxAngularSpeed - minAngularSpeed; double speedRange = maxAngularSpeed - minAngularSpeed;
double minAngle = -90.0; double minAngle = -20.0;
double maxAngle = 90.0; double maxAngle = 20.0;
double angularRange = maxAngle - minAngle; double angularRange = maxAngle - minAngle;
if(angle < minAngle)
{
angle = minAngle;
}
if(angle > maxAngle)
{
angle = maxAngle;
}
double progress = angle - minAngle; double progress = angle - minAngle;
double progressPercent = progress/angularRange; double progressPercent = progress/angularRange;
double speed = minAngularSpeed + progressPercent*speedRange; double speed = minAngularSpeed + progressPercent*speedRange;
return std::fabs(speed); return speed;
} }
+1 -1
View File
@@ -66,7 +66,7 @@ double LFR_UART::byteToDouble(int8_t in){
void LFR_UART::sendTelegram(double wheel1, double wheel2, double wheel3, double wheel4){ void LFR_UART::sendTelegram(double wheel1, double wheel2, double wheel3, double wheel4){
std::chrono::milliseconds now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()); std::chrono::milliseconds now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
unsigned int deltaMs = static_cast<unsigned int>((now-last).count()); unsigned int deltaMs = static_cast<unsigned int>((now-last).count());
if (deltaMs < 250 && (std::fabs(wheel1)+std::fabs(wheel2)+std::fabs(wheel3)+std::fabs(wheel4)) > 0.0005) if (deltaMs < 50 && (std::fabs(wheel1)+std::fabs(wheel2)+std::fabs(wheel3)+std::fabs(wheel4)) > 0.0005)
{ {
std::cout << "Too fast" << std::endl; std::cout << "Too fast" << std::endl;
return; return;
+22 -8
View File
@@ -104,16 +104,26 @@ LFR_StateMachine::LFR_StateMachine():
currentState = &State::Idle::getInstance(); currentState = &State::Idle::getInstance();
currentState->enter(this); currentState->enter(this);
//Start the permanent loop cv::VideoWriter writer = cv::VideoWriter("video_200.avi", cv::VideoWriter::fourcc('M','J','P','G'), 4.0, cv::Size(videoWidth, videoHeight), true);
char input;
std::cout << "press q to quit" << std::endl; auto t_start = std::chrono::high_resolution_clock::now();
std::cin >> input; auto t_end = std::chrono::high_resolution_clock::now();
std::cout << "binned" << std::endl; double dur = std::chrono::duration<double, std::milli>(t_end-t_start).count();
while (input != 'q')
while(dur < 60000)
{ {
std::cin >> input; t_end = std::chrono::high_resolution_clock::now();
std::cout << "binned" << std::endl; dur = std::chrono::duration<double, std::milli>(t_end-t_start).count();
{
this_thread::sleep_for(std::chrono::milliseconds(50));
std::unique_lock<std::mutex> lock(imgMutex);
if(!this->image.empty())
{
writer.write(this->image);
} }
}
}
writer.release();
std::cout << "Exiting central" << std::endl; std::cout << "Exiting central" << std::endl;
} }
@@ -146,6 +156,10 @@ void LFR_StateMachine::enterAutonomous()
double delta = static_cast<double>(deltaMs) / 1000.0; double delta = static_cast<double>(deltaMs) / 1000.0;
double frameRate = 1.0 / static_cast<double>(delta);*/ double frameRate = 1.0 / static_cast<double>(delta);*/
double frameRate = -1.0; double frameRate = -1.0;
{
std::unique_lock<std::mutex> lock(imgMutex);
image = result.rawImage;
}
if (result.validLane) if (result.validLane)
{ {
+6 -1
View File
@@ -16,7 +16,7 @@ class LFR_StateMachine
const int videoHeight = 720; const int videoHeight = 720;
const int videoWidth = 1280; const int videoWidth = 1280;
const int gaussKernelSize = 11; const int gaussKernelSize = 11;
const double maxSpeed = 0.5; const double maxSpeed = 0.20;
std::mutex mutex; std::mutex mutex;
@@ -24,6 +24,9 @@ class LFR_StateMachine
LFR_UART uartCommunicator; LFR_UART uartCommunicator;
LFR_Socket socket; LFR_Socket socket;
std::mutex imgMutex;
Mat image;
vector<string> split (string s, string delimiter) const; vector<string> split (string s, string delimiter) const;
void sanitize (string& s) const; void sanitize (string& s) const;
bool checkStringValidity (const std::vector<std::string>& s) const; bool checkStringValidity (const std::vector<std::string>& s) const;
@@ -36,3 +39,5 @@ public:
inline LFR_IState* getCurrentState() const {return currentState;} inline LFR_IState* getCurrentState() const {return currentState;}
void setState(LFR_IState& newState); void setState(LFR_IState& newState);
}; };