Skip to content
Snippets Groups Projects

Fix sector sensor and remove trailing whitespaces

Merged Felix Wege requested to merge 2022_updates into master
1 file
+ 31
31
Compare changes
  • Side-by-side
  • Inline
+ 31
31
@@ -93,21 +93,21 @@ void CLI::init() {
} while (_robotName.length() < 4);
do // Read address of arena server
{
std::cout << "Enter server address [XX.XX.XX.XX]: " << std::endl;
std::cin >> _serverAddress;
} while (_serverAddress.empty());
do // Read address of arena server
{
std::cout << "Enter server port: " << std::endl;
std::cin >> _serverPort;
} while (_serverPort == 123123123123);
robotName = _robotName;
serverAddress = _serverAddress;
serverPort = _serverPort;
@@ -121,7 +121,7 @@ void CLI::startCLI() {
// update scene
clearScene();
printScene(commands);
// read new input
std::string input;
input = getUserInput();
@@ -174,7 +174,7 @@ void CLI::printScene(std::string fixedMessage/* = "" */) {
std::cout << "________________________________________________________________________________ " << std::endl;
if(fixedMessage != ""){
std::cout << fixedMessage << std::endl;
std::cout << "________________________________________________________________________________ " << std::endl;
std::cout << "________________________________________________________________________________ " << std::endl;
}
std::cout << "" << std::endl;
std::cout << " < Log: > " << std::endl;
@@ -236,7 +236,7 @@ void CLI::sensors(){
+ std::string(" sector --> get sector sensor readings | speed --> get current speed\n\n")
+ std::string(" exit --> go back to 'commands' ");
updateScene(fixedMessage);
std::string input = "";
while(true){
input = getUserInput();
@@ -252,7 +252,7 @@ void CLI::commSeq(){
+ std::string(" measureLat --> measure latencies\n\n")
+ std::string(" exit --> go back to 'commands' ");
updateScene(fixedMessage);
std::string input = "";
while(true){
input = getUserInput();
@@ -269,7 +269,7 @@ void CLI::behavior(){
+ std::string(" targetBraking --> start TargetBreaking behavior\n\n")
+ std::string(" exit --> go back to 'commands' ");
updateScene(fixedMessage);
std::string input = "";
while(true){
input = getUserInput();
@@ -288,7 +288,7 @@ void CLI::tBehavior(){
+ std::string(" tStop --> stops current behavior\n\n")
+ std::string(" exit --> go back to 'commands' ");
updateScene(fixedMessage);
std::string input = "";
while(true){
input = getUserInput();
@@ -327,7 +327,7 @@ float CLI::speed(){
* TODO Aufgabe 1.4
* Testen Sie Robot::getSpeed() indem sie "speed" im CLI aufrufen
* TODO Aufgabe 3.2
* Wenn Sie Robot::getSpeedAsync() implementiert haben,
* Wenn Sie Robot::getSpeedAsync() implementiert haben,
* rufen Sie statt der ersten die zweite Zeile auf (die getSpeedAsync verwendet).
*/
@@ -353,14 +353,14 @@ void CLI::simple(){
/*
* TODO Aufgabe 1.4
* TODO Aufgabe 1.4
* warten, bis Roboter steht und Wegstreckenzähler erneut ausgeben.
*/
// warten, bis Geschwindigkeit 0 erreicht hat.
// vvvv--
// ^^^^--
float dist2 = 42.0; // TODO: Wegstreckenzähler auslesen (dist2 wird unten ausgegeben)
// vvvv--
// ^^^^--
@@ -383,11 +383,11 @@ void CLI::measureLat(){
std::chrono::time_point<std::chrono::high_resolution_clock> t_start;
std::chrono::time_point<std::chrono::high_resolution_clock> t_end;
t_start = std::chrono::high_resolution_clock::now();
t_start = std::chrono::high_resolution_clock::now();
for (unsigned int i=0; i<100; ++i) {
usleep(10e3);
}
t_end = std::chrono::high_resolution_clock::now();
t_end = std::chrono::high_resolution_clock::now();
int microseconds = std::chrono::duration_cast<std::chrono::microseconds>(t_end - t_start).count()/100;
logString("Time for usleep(10e3): " + std::to_string(microseconds) + "us");
@@ -470,7 +470,7 @@ void CLI::processInput(std::string input){
running = false;
} else if(input == "telnet"){
telnet();
telnet();
} else if((pos = input.find("logsize")) == 0) {
std::string s_size = "";
@@ -511,8 +511,8 @@ void CLI::processInput(std::string input){
catch (const std::invalid_argument& ia) {
logString("INVALID INPUT ARGUMENT " + s_size + " - <UNSIGNED INT> EXPECTED");
size = -1;
}
}
setLogSize(size);
logstring = "logsize : new size = " + std::to_string(LOGSIZE);
}
@@ -528,7 +528,7 @@ void CLI::processInput(std::string input){
}
speedVal = newSpeed;
p_robot->speed(newSpeed);
} else if(input == "s" || input == "S"){
int newSpeed = speedVal - 1.0;
if(abs(newSpeed) > maxSpeed){
@@ -540,11 +540,11 @@ void CLI::processInput(std::string input){
}
speedVal = newSpeed;
p_robot->speed(newSpeed);
} else if(input == "a" || input == "A"){
p_robot->turn(-10.0);
logstring += " : -10° turn (left)";
} else if(input == "d" || input == "D") {
p_robot->turn(10.0);
logstring += " : +10° turn (right)";
@@ -555,7 +555,7 @@ void CLI::processInput(std::string input){
} else if ((pos = input.find("SETSPEED")) == 0 || (pos = input.find("setspeed")) == 0){
std::string s_newSpeed = "";
float newSpeed = -42.0;
if(input.size() > 8){ // additional parameter given
s_newSpeed = input.substr(9, input.size()-9);
try{
@@ -607,7 +607,7 @@ void CLI::processInput(std::string input){
logstring += ": set behavior to BrakeTest(speed = " + param + ")";
brakeTest(param);
*/
// First level functions
// First level functions
else if(input == "sensors"){
sensors();
} else if(input == "commSeq"){
@@ -627,7 +627,7 @@ void CLI::processInput(std::string input){
} else if ((pos = input.find("line")) == 0) {
std::string s_angle = "";
double angle = 0;
if(input.size() > 4){ // additional parameter given
s_angle = input.substr(5, input.size()-5);
try{
@@ -667,8 +667,8 @@ void CLI::processInput(std::string input){
logString("INVALID INPUT ARGUMENT " + s_sec + " - <INTEGER> EXPECTED");
sec = -42;
}
if(sec != -2 && sec != -1 && sec != 1 && sec != 2) {
while(sec != -2 && sec != -1 && sec != 1 && sec != 2){
if(sec != -2 && sec != -1 && sec != 0 && sec != 1 && sec != 2) {
while(sec != -2 && sec != -1 && sec != 0 && sec != 1 && sec != 2){
updateScene("\nGive sector <int> [-2,2]: ");
std::string s_sec;
std::cout << "> ";
@@ -683,7 +683,7 @@ void CLI::processInput(std::string input){
}
}
} else {
while(sec != -2 && sec != -1 && sec != 1 && sec != 2){
while(sec != -2 && sec != -1 && sec != 0 && sec != 1 && sec != 2){
updateScene("\nGive sector <int> [-2,2]: ");
std::string s_sec;
std::cout << "> ";
@@ -700,13 +700,13 @@ void CLI::processInput(std::string input){
logstring = "sector(" + std::to_string(sec) + ") = " + std::to_string(sector(sec));
} else if(input == "speed"){
logstring += " = " + std::to_string(speed());
}
}
//// commSeq
else if(input == "simple"){
simple();
} else if(input == "measureLat"){
measureLat();
}
}
//// behavior
else if((pos = input.find("brakeTest")) == 0){
if(input.size() > 9){ // additional parameter given
@@ -726,7 +726,7 @@ void CLI::processInput(std::string input){
}
logstring += ": set behavior to TargetBraking(speed = " + param + ")";
targetBraking(param);
}
}
//// tBehavior
else if((pos = input.find("tTargetBraking")) == 0){
if(input.size() > 14){
@@ -756,7 +756,7 @@ void CLI::processInput(std::string input){
logstring += ": behavior stopped";
tStop();
}
// Invalid command
// Invalid command
else {
logstring += " <-- is no valid command!...";
}
Loading