Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJonas committed Dec 11, 2017
1 parent d0148e7 commit 992bb51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup_linux.sh
Original file line number Diff line number Diff line change
@@ -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 ]
Expand Down
15 changes: 14 additions & 1 deletion src/drivers/pid_driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/drivers/pid_driver/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Driver {
float getAccel(tCarElt *car);
void handleSpeed();
void handleSteering();
float getGoalPosX();

float getBrake(tCarElt *car);
int getGear(tCarElt *car);
Expand Down

0 comments on commit 992bb51

Please sign in to comment.