git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6415 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 99d4638e2f901da00071e83a973794033109eeb2
Former-commit-id: df10a9e6469f253ffaaa90e2f23e588a13114749
This commit is contained in:
madbad 2016-06-02 15:07:57 +00:00
parent 30c49f4930
commit 65f9417516
5 changed files with 304 additions and 23 deletions

View file

@ -1163,22 +1163,13 @@ static void common_drive(const int index, tCarElt* car, tSituation *s)
/* Force feedback hack */
//float force = car->_steerTq * 32760 * 5;
float force = car->_steerTq * 32760 / 400 * -1;
//float force = car->_steerTq * 32760 / 400 * -1;
// tdble skidAng = atan2(car->_speed_Y, car->_speed_X) - car->_yaw;
// NORM_PI_PI(skidAng);
//tdble skidAng=0;
float force = (car->_steerTq /*- skidAng*/ * 32760);//adjusted by skid
if (force > 32760) force = 32760;
if (force < -32760) force = -32760;
GfOut("##FF## force = %f\n", car->_steerTq);
GfOut("##FF## applied force = %f\n", force);
GfOut("##FF## direction = %d\n", force < 0 ? 9000 : 27000);
GfOut("##FF## value = %d\n", abs((int)force));
/*
GfOut("FRNT_RGT = %f\n", car->_wheel[FRNT_RGT]);
GfOut("FRNT_LFT = %f\n" , car->_wheel[FRNT_LFT]); //based on 36000 degree of rotation
*/ // if force is below 0 we turn anticlock-wise
// if force is below 0 we turn anticlock-wise
// if force is over 0 we turn clock-wise
gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), abs((int)force), force < 0 ? 9000 : 27000 );
//gfctrlJoyRumble(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), 0.9);
@ -1633,6 +1624,71 @@ static void common_drive(const int index, tCarElt* car, tSituation *s)
#endif
#endif
if (force > 32760) force = 32760;
if (force < -32760) force = -32760;
extern GfTelemetry telemetry;
telemetry.start();//start a new "data row"
//telemetry.log("paramName","ParamValue");
//tdble skidAng = atan2(car->_speed_Y, car->_speed_X) - car->_yaw;
//NORM_PI_PI(skidAng);
telemetry.log("Time-RaceTime",(float)s->currentTime);
telemetry.log("Time-LapTime", (float)car->_curLapTime);
telemetry.log("FF-steerTq",car->_steerTq);
telemetry.log("FF-appliedForce",force);
telemetry.log("FF-direction",force);
telemetry.log("FF-value",abs((int)force));
telemetry.log("Slip-Slip",slip);
telemetry.log("Carx-x", car->_speed_x);
telemetry.log("Cary-y", car->_speed_y);
//telemetry.log("Skid-skidAng", skidAng);
telemetry.log("Lap-Lap", (float)car->_laps);
telemetry.log("Dist-Dist", (float)HCtx[idx]->distToStart);
telemetry.log("Accelx-Ax", (float)car->_accel_x);
telemetry.log("Accely-Ay", (float)car->_accel_y);
telemetry.log("Command-Steer", (float)car->_steerCmd);
telemetry.log("TrottleBrake-Throttle", (float)car->_accelCmd);
telemetry.log("TrottleBrake-Brake", (float)car->_brakeCmd);
telemetry.log("EngineRPM-EngineRPM", (float)car->_enginerpm);
telemetry.log("Gear-Gear", (float)HCtx[idx]->gear);
telemetry.log("Speed-Speed", (float)car->_speed_x);
telemetry.log("Position-x", car->_pos_X);
telemetry.log("Position-y", car->_pos_Y);
telemetry.log("Position-z", car->_pos_Z);
telemetry.log("Damage-Damage", car->_dammage);
telemetry.log("Collision-Collision", car->priv.collision);
telemetry.log("Fuel-Fuel", car->_fuel);
telemetry.log("BrakeTemp-1",car->_brakeTemp(0));
telemetry.log("BrakeTemp-2",car->_brakeTemp(1));
telemetry.log("BrakeTemp-3",car->_brakeTemp(2));
telemetry.log("BrakeTemp-4",car->_brakeTemp(3));
//track segment that the car is on
//carElt->_wheelSeg(i)
//center of gravity of the car
//telemetry.log("GC-GC",car->pub.DynGC); //.acc.x vel.x
//telemetry.log("GC-GCg",car->pub.DynGCg); //.acc.x vel.x pos.x //see car.h
//telemetry.log("",);
/*
GfOut("FRNT_RGT = %f\n", car->_wheel[FRNT_RGT]);
GfOut("FRNT_LFT = %f\n" , car->_wheel[FRNT_LFT]); //based on 36000 degree of rotation
*/
HCtx[idx]->lap = car->_laps;
}//common_drive

View file

@ -29,6 +29,7 @@
#include <cerrno>
#include <cmath>
#include <cstring>
#include <sstream>
#ifdef __MINGW32__
#include <fstream> // std::fstream
@ -1001,3 +1002,174 @@ GfSleep(double seconds)
{
SDL_Delay((Uint32)(seconds*1000)); // ms.
}
//to string (from c++11)
template <typename T>
std::string to_string(T value)
{
std::ostringstream os ;
os << value ;
return os.str() ;
}
GfTelemetry::GfTelemetry(){
// this->params_names.append("\"loop\"");
this->lastDataLogTime = std::clock();
this->count = 0;
this->doLog=true;
this->headerWritten=false;
}
GfTelemetry::~GfTelemetry(){
}
void GfTelemetry::start(){
//GfOut("\n\n\n#############%i\n\n\n\n\n\n", this->params_values.size());
//write to file every 10kb
if(this->params_values.size() > 10000){
this->plot();
}
//how much time is passed from the last run
std::clock_t curTime = std::clock();
float elapsedTime = (curTime - this->lastDataLogTime) / (float) CLOCKS_PER_SEC;
//GfOut("\n%f\n", elapsedTime);
this->data.clear();
if (elapsedTime > 0.1){
//GfOut("\n%f\n", elapsedTime);
this->lastDataLogTime = std::clock();
this->doLog=true;
this->count= this->count+1;
this->params_values.append("\r\n");
// this->params_values.append(to_string(count));
}else{
this->doLog=false;
}
}
void GfTelemetry::end(){
}
void GfTelemetry::log(std::string name, std::string value){
name.insert(0,"\"");
name.append("\"");
if(this->doLog){
std::map<std::string,std::string>::iterator it;
it = this->data.find(name);
if (it == this->data.end()){
this->data[name] = value;
std::size_t found = this->params_names.find(name,0);
if(found==std::string::npos){
this->params_names.append(name);
this->params_names.append(",");
}
this->params_values.append(value);
this->params_values.append(",");
}
}
return;
}
void GfTelemetry::log(std::string name, int value){
if(this->count==0){
return;
}
return this->log(name,to_string(value));
}
void GfTelemetry::log(std::string name, float value){
if(this->count==0){
return;
}
return this->log(name,to_string(value));
}
void GfTelemetry::plot(){
std::string output;
output.append("\r\n");
//output.append(this->params_names);
if(!this->headerWritten){
output.append("\r\n");
output.append(this->params_names);
this->headerWritten=true;
}
output.append(this->params_values);
std::string telemetryFile = GfLocalDir();
telemetryFile.append("telemetry.txt");
FILE * pFile;
pFile = fopen (telemetryFile.c_str(), "a"); //"a"=append to file "w"=empty file and write to it
fwrite (output.data() , sizeof(char), output.length(), pFile);
fclose (pFile);
//empty the strings
this->params_values.clear();
return;
}
/*
void GfTelemetry::createSqliteDb(){
int result;
std::string telemetryDb = GfLocalDir();
telemetryDb.append("telemetry.db");
result = sqlite3_open(telemetryDb, telemetryDb.c_str());
if (result) {
GfLogError("Unable to open Database: %s\n", sqlite3_errmsg(replayDB));
sqlite3_close(replayDB);
replayDB = NULL;
} else {
GfLogInfo("Replay Database Opened 0x8%8.8X\n\n\n\n", replayDB);
// speed up database by turning of synchronous behaviour, ie. don't wait for disk
sqlite3_exec(replayDB, "PRAGMA synchronous = OFF", NULL, NULL, NULL);
}
}
void GfTelemetry::openSqliteDb(){
}
void GfTelemetry::closeSqliteDb(){
sqlite3_close(replayDB);
}
void GfTelemetry::createSqliteTable(){
char query[200];
int result;
sprintf(query, "CREATE TABLE IF NOT EXISTS data (timestamp, lap, datablob BLOB)", i);
result = sqlite3_exec(replayDB, query, 0, 0, 0);
if (result) {
printf("Unable to create table data: %s\n", sqlite3_errmsg(replayDB));
}
}
void GfTelemetry::saveData(){
char query[200];
int result;
// Do everything in 1 transaction for speed
sqlite3_exec(replayDB, "BEGIN TRANSACTION", NULL, NULL, NULL);
sprintf(query, "INSERT INTO car%d (timestamp, lap, datablob) VALUES (%f, %d, ?)", nCarInd,
pSource->s->currentTime, pSrcCar->_laps);
result = sqlite3_exec(replayDB, query, 0, 0, 0);
if (result) {
GfLogInfo("Unable to instert into table: %s\n", sqlite3_errmsg(replayDB));
}
}
*/
GfTelemetry telemetry;

View file

@ -31,6 +31,8 @@
#endif
#include "osspec.h"
#include <ctime>
#include <map>
// DLL exported symbols declarator for Windows.
#ifdef WIN32
@ -997,6 +999,30 @@ TGF_API void GfFormFreeCommandNew(void *cmd);
// Maximun value of a key code (Has to be the least greater 2^N - 1 >= SDLK_LAST)
#define GF_MAX_KEYCODE 0x1FF
TGF_API class GfTelemetry{
public:
void start();
void log (std::string name, std::string value);
void log (std::string name, int value);
void log (std::string name, float value);
void plot();
std::clock_t lastDataLogTime;
int count;
bool doLog;
bool headerWritten;
std::map<std::string,std::string> data;
void end();
std::string params_names;
std::string params_values;
//constructor
GfTelemetry();
//destructor
~GfTelemetry();
};
#endif /* __TGF__H__ */

View file

@ -258,6 +258,9 @@ main(int argc, char *argv[])
const std::string strAppName(pApp->name());
delete pApp;
extern GfTelemetry telemetry;
telemetry.plot();
// That's all (but trace what we are doing).
if (piUserItf && piRaceEngine)
GfLogInfo("Exiting normally from %s.\n", strAppName.c_str());

View file

@ -19,6 +19,7 @@
#include <tgf.h>
#include "sim.h"
#include <sstream>
static const char *WheelSect[4] = {SECT_FRNTRGTWHEEL, SECT_FRNTLFTWHEEL, SECT_REARRGTWHEEL, SECT_REARLFTWHEEL};
static const char *SuspSect[4] = {SECT_FRNTRGTSUSP, SECT_FRNTLFTSUSP, SECT_REARRGTSUSP, SECT_REARLFTSUSP};
@ -457,14 +458,37 @@ void SimWheelUpdateForce(tCar *car, int index)
car->carElt->_wheelSlipAccel(index) = sx*v;
car->carElt->_reaction[index] = reaction_force;
car->carElt->_tyreEffMu(index) = mu;
if(index == 1){
GfOut("##FF## Index - = %i\n", index);
GfOut("##FF## SA - Slip Angle = %f\n", wheel->sa);
GfOut("##FF## MU - = %f\n", mu);
GfOut("##FF## Norm - = %f\n", car->carElt->_wheelSlipNorm(index));
GfOut("##FF## Opt - = %f\n", car->carElt->_wheelSlipOpt(index));
GfOut("##FF## Norm/opt - = %f\n", car->carElt->_wheelSlipNorm(index)/car->carElt->_wheelSlipOpt(index));
}
//if(index == 1){
//GfOut(" (%i) Index - = %i\n", index);
//GfOut("#%i", index); //index
/*
GfOut("#%f", wheel->sa); //SA
GfOut("#%f", mu); //MU
GfOut("#%f", car->carElt->_wheelSlipNorm(index)); //NORM
GfOut("#%f", car->carElt->_wheelSlipOpt(index)); //OPT
GfOut("#%f", car->carElt->_wheelSlipNorm(index)/car->carElt->_wheelSlipOpt(index)); //NORM/OPT
*/
extern GfTelemetry telemetry;
//telemetry.start();//start a new "data row"
//telemetry.log("paramName","ParamValue");
std::ostringstream paramname;
paramname.str("");
paramname << "WHEEL SA-" << index;
telemetry.log(paramname.str(),wheel->sa);
paramname.str("");
paramname << "WHEEL MU-" << index;
telemetry.log(paramname.str(),mu);
paramname.str("");
paramname << "WHEEL NORM-" << index;
telemetry.log(paramname.str(),car->carElt->_wheelSlipNorm(index));
paramname.str("");
paramname << "WHEEL OPT-" << index;
telemetry.log(paramname.str(),car->carElt->_wheelSlipOpt(index));
paramname.str("");
paramname << "WHEEL NORM/OPT-" << index;
telemetry.log(paramname.str(),car->carElt->_wheelSlipNorm(index)/car->carElt->_wheelSlipOpt(index));
//}
tdble Work = 0.0;