forked from fmirus/torcs-1.3.7
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructure code, explicit pid controllers
- Loading branch information
1 parent
4ca3705
commit 40c5ebe
Showing
14 changed files
with
332 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/home/jonas/tmp/torcs-1.3.7/src/modules/simu/simuv2/SOLID-2.0/src/libsolid.a | ||
/home/jonas/torcs-1.3.7/src/modules/simu/simuv2/SOLID-2.0/src/libsolid.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
# | ||
# file : torcsdoc.conf | ||
# created : Mon Jan 31 23:57:03 CET 2000 | ||
# copyright : (C) 2000-2014 by Eric Espie, Bernhard Wymann | ||
# email : [email protected] | ||
# version : $Id: torcsdoc.conf.in,v 1.6.2.5 2014/05/20 12:12:45 berniw Exp $ | ||
# copyright : (C) 2000-2014 by Eric Espie, Bernhard Wymann | ||
# email : [email protected] | ||
# version : $Id: torcsdoc.conf.in,v 1.6.2.5 2014/05/20 12:12:45 berniw Exp $ | ||
# | ||
############################################################################## | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "pidAcc.h" | ||
|
||
#include <iostream> | ||
#include <cmath> | ||
|
||
|
||
PidAcc::PidAcc(){} | ||
|
||
PidAcc::PidAcc( float dt, float Kp, float Kd, float Ki ) : | ||
_dt(dt), | ||
_Kp(Kp), | ||
_Kd(Kd), | ||
_Ki(Ki), | ||
_preError(0), | ||
_integral(0) | ||
{ | ||
} | ||
|
||
|
||
float PidAcc::step( float setpoint, float currentVal, float maxAcc) | ||
{ | ||
|
||
// Calculate error | ||
float error = setpoint - currentVal; | ||
|
||
// Proportional term | ||
float Pout = _Kp * error; | ||
|
||
// Integral term | ||
_integral += error * _dt; | ||
float Iout = _Ki * _integral; | ||
|
||
// Derivative term | ||
float derivative = (error - _preError) / _dt; | ||
float Dout = _Kd * derivative; | ||
|
||
// Calculate total output | ||
float output = Pout + Iout + Dout; | ||
// std::cout << "P: " << Pout << ", I: " << Iout << " D: " << Dout << std::endl; | ||
|
||
// Restrict to max/min | ||
if( output > maxAcc ) | ||
output = maxAcc; | ||
else if( output < -1 * maxAcc ) | ||
output = -1 * maxAcc; | ||
|
||
// Save error to previous error | ||
_preError = error; | ||
|
||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PID_ACC_H | ||
#define PID_ACC_H | ||
|
||
class PidAcc{ | ||
public: | ||
PidAcc(); | ||
PidAcc(float dt, float Kp, float Kd, float Ki); | ||
|
||
float step(float setPoint, float currentVal, float maxAcc); | ||
|
||
private: | ||
float _dt, _Kp, _Kd, _Ki, _preError, _integral; | ||
}; | ||
|
||
|
||
#endif // PID_ACC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "pidSteer.h" | ||
|
||
#include <cmath> | ||
#include <iostream> | ||
|
||
PidSteer::PidSteer() {} | ||
|
||
PidSteer::PidSteer(float dt, float Kp, float Kd, float Ki, float G1, float G2, float max) | ||
: _dt(dt), _Kp(Kp), _Kd(Kd), _Ki(Ki), _G1(G1), _G2(G2), _preError(0), _integral(0), _max(max) {} | ||
|
||
float PidSteer::step(float setpoint1, float setpoint2, float currentVal1, float currentVal2) { | ||
|
||
// Calculate error | ||
float error1 = 1 * (setpoint1 - currentVal1); | ||
float error2 = 1 * (setpoint2 - currentVal2); | ||
// std::cout << "1: " << error1 << ", 2: " << error2 << std::endl; | ||
float error = _G1 * error1 + _G2 * error2; | ||
|
||
// Proportional term | ||
float Pout = _Kp * error; | ||
|
||
// Integral term | ||
_integral += error * _dt; | ||
float Iout = _Ki * _integral; | ||
|
||
// Derivative term | ||
float derivative = (error - _preError) / _dt; | ||
float Dout = _Kd * derivative; | ||
|
||
// Calculate total output | ||
float output = Pout + Iout + Dout; | ||
// std::cout << "P: " << Pout << ", I: " << Iout << " D: " << Dout << std::endl; | ||
|
||
// Restrict to max/min | ||
if (output > _max) | ||
output = _max; | ||
else if (output < -1 * _max) | ||
output = -1 * _max; | ||
|
||
// Save error to previous error | ||
_preError = error; | ||
|
||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef PID_STEER_H | ||
#define PID_STEER_H | ||
|
||
class PidSteer { | ||
public: | ||
PidSteer(); | ||
// PidSteer(float dt, float Kp, float Kd, float Ki, float max); | ||
PidSteer(float dt, float Kp, float Kd, float Ki, float G1, float G2, float max); | ||
|
||
// float step(float setPoint, float currentVal); | ||
float step(float setpoint1, float setpoint2, float currentVal1, float currentVal2); | ||
|
||
private: | ||
float _dt, _Kp, _Kd, _Ki, _G1, _G2, _preError, _integral, _max; | ||
}; | ||
|
||
#endif // PID_STEER_H |
Oops, something went wrong.