From 992bb516417ef774af2db147069f25e9cf8030da Mon Sep 17 00:00:00 2001 From: Jonas Natzer Date: Mon, 11 Dec 2017 10:43:09 +0100 Subject: [PATCH] Update --- setup_linux.sh | 1 + src/drivers/pid_driver/driver.cpp | 15 ++++++++++++++- src/drivers/pid_driver/driver.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/setup_linux.sh b/setup_linux.sh index 824b37e..a3c3bea 100755 --- a/setup_linux.sh +++ b/setup_linux.sh @@ -1,6 +1,7 @@ #! /bin/bash [ -z "$1" ] && exit 1 +[ ! -d "$1" ] && exit 1 mkdir -p $1/drivers/human 2>/dev/null if [ ! -e $1/drivers/human/car.xml ] || [ drivers/human/car.xml -nt $1/drivers/human/car.xml ] diff --git a/src/drivers/pid_driver/driver.cpp b/src/drivers/pid_driver/driver.cpp index af25807..f353234 100644 --- a/src/drivers/pid_driver/driver.cpp +++ b/src/drivers/pid_driver/driver.cpp @@ -19,6 +19,7 @@ const float Driver::ABS_MINSPEED = 3.0; /* [m/s] */ const float Y_DIST_TO_MIDDLE = 5.0; const float GOAL_POS_Y = -20; const float GOAL_POS_X = 0; +const float MIN_DIST_X = 1; Driver::Driver(int index) { float dt = 0.02; @@ -90,12 +91,24 @@ void Driver::drive(tCarElt *car, tSituation *s) { void Driver::handleSteering() { float currentPosX = getOpponentDistanceX(opponent[0]); - car->ctrl.steer = _pidSteer.step(GOAL_POS_X, 0.0, currentPosX, angle); + float goalX = getGoalPosX(); + std::cout << "goalX: " << goalX << std::endl; + car->ctrl.steer = _pidSteer.step(goalX, 0.0, currentPosX, angle); if (getSpeed() < 0) car->ctrl.steer *= -1; std::cout << "Steering: " << car->ctrl.steer << std::endl; } +float Driver::getGoalPosX(){ + float dist = GOAL_POS_X + MIN_DIST_X * std::(1/getOpponentDistanceY(opponent[0])); + // Always overtake on the side of the front car, that directs towards the center of the street + if(car->_trkPos.toMiddle - getOpponentDistanceX(opponent[0]) < 0){ + dist *= -1; + } + // std::cout << car->_trkPos.toMiddle - getOpponentDistanceX(opponent[0]) << std::endl; + return dist; +} + // This decides over the current speed void Driver::handleSpeed() { // This is for abs diff --git a/src/drivers/pid_driver/driver.h b/src/drivers/pid_driver/driver.h index 20ca754..d1fd4f1 100644 --- a/src/drivers/pid_driver/driver.h +++ b/src/drivers/pid_driver/driver.h @@ -49,6 +49,7 @@ class Driver { float getAccel(tCarElt *car); void handleSpeed(); void handleSteering(); + float getGoalPosX(); float getBrake(tCarElt *car); int getGear(tCarElt *car);