Compare commits
5
Commits
397e6fe331
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dea00a8d1 | ||
|
|
960b05e76f | ||
|
|
94e9c4ba7a | ||
|
|
6da9bfff54 | ||
|
|
c40b69ebe2 |
@@ -36,7 +36,7 @@ void ControlModule::adjustSpeed(){
|
||||
|
||||
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);
|
||||
double rotationRatio = ratio(angle);
|
||||
rotate(rotationRatio);
|
||||
drive(1.0-rotationRatio);
|
||||
drive(1.0-std::fabs(rotationRatio));
|
||||
unit();
|
||||
adjustSpeed();
|
||||
}
|
||||
@@ -102,13 +102,21 @@ double ControlModule::ratio(double angle)
|
||||
double maxAngularSpeed = 1.0;
|
||||
double speedRange = maxAngularSpeed - minAngularSpeed;
|
||||
|
||||
double minAngle = -90.0;
|
||||
double maxAngle = 90.0;
|
||||
double minAngle = -20.0;
|
||||
double maxAngle = 20.0;
|
||||
double angularRange = maxAngle - minAngle;
|
||||
|
||||
if(angle < minAngle)
|
||||
{
|
||||
angle = minAngle;
|
||||
}
|
||||
if(angle > maxAngle)
|
||||
{
|
||||
angle = maxAngle;
|
||||
}
|
||||
double progress = angle - minAngle;
|
||||
double progressPercent = progress/angularRange;
|
||||
|
||||
double speed = minAngularSpeed + progressPercent*speedRange;
|
||||
return std::fabs(speed);
|
||||
return speed;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ double LFR_UART::byteToDouble(int8_t in){
|
||||
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());
|
||||
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;
|
||||
return;
|
||||
|
||||
+22
-8
@@ -104,16 +104,26 @@ LFR_StateMachine::LFR_StateMachine():
|
||||
currentState = &State::Idle::getInstance();
|
||||
currentState->enter(this);
|
||||
|
||||
//Start the permanent loop
|
||||
char input;
|
||||
std::cout << "press q to quit" << std::endl;
|
||||
std::cin >> input;
|
||||
std::cout << "binned" << std::endl;
|
||||
while (input != 'q')
|
||||
cv::VideoWriter writer = cv::VideoWriter("video_200.avi", cv::VideoWriter::fourcc('M','J','P','G'), 4.0, cv::Size(videoWidth, videoHeight), true);
|
||||
|
||||
auto t_start = std::chrono::high_resolution_clock::now();
|
||||
auto t_end = std::chrono::high_resolution_clock::now();
|
||||
double dur = std::chrono::duration<double, std::milli>(t_end-t_start).count();
|
||||
|
||||
while(dur < 60000)
|
||||
{
|
||||
std::cin >> input;
|
||||
std::cout << "binned" << std::endl;
|
||||
t_end = std::chrono::high_resolution_clock::now();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -146,6 +156,10 @@ void LFR_StateMachine::enterAutonomous()
|
||||
double delta = static_cast<double>(deltaMs) / 1000.0;
|
||||
double frameRate = 1.0 / static_cast<double>(delta);*/
|
||||
double frameRate = -1.0;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(imgMutex);
|
||||
image = result.rawImage;
|
||||
}
|
||||
|
||||
if (result.validLane)
|
||||
{
|
||||
|
||||
+6
-1
@@ -16,7 +16,7 @@ class LFR_StateMachine
|
||||
const int videoHeight = 720;
|
||||
const int videoWidth = 1280;
|
||||
const int gaussKernelSize = 11;
|
||||
const double maxSpeed = 0.5;
|
||||
const double maxSpeed = 0.20;
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
@@ -24,6 +24,9 @@ class LFR_StateMachine
|
||||
LFR_UART uartCommunicator;
|
||||
LFR_Socket socket;
|
||||
|
||||
std::mutex imgMutex;
|
||||
Mat image;
|
||||
|
||||
vector<string> split (string s, string delimiter) const;
|
||||
void sanitize (string& s) const;
|
||||
bool checkStringValidity (const std::vector<std::string>& s) const;
|
||||
@@ -36,3 +39,5 @@ public:
|
||||
inline LFR_IState* getCurrentState() const {return currentState;}
|
||||
void setState(LFR_IState& newState);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user