OpenGLベースのシミュレータで時系列データを取得したいのですが...
Posted: 2012年11月17日(土) 06:18
今TORCSというオープンソースのドライブシミュレータを利用したくてソースをいじり始めているところです.
現在の開発環境はwindows visualstudio2008Expressです.
質問は走行中の自動車の時系列データ(car->_steerCmd, car->_gearCmd, car->_accelCmd, car->_brakeCmd, car->_clutchCmdなど...)
を取得したいのですが,プログラミング初心者でしてまだできていません.
以下のように,drive.cpp内のvoid Driver::drive(tSituation *s)内
から欲しいパラメータの時系列データを配列に格納したあと,
bt.cpp内のstatic void shutdown(int index)
で,自作したstatic void filewrite(float data[])という関数を実行できれば
いいのかなというところまで考えてみたのですが,まだできていません.
原因として,プログラムが大きいためメイン関数?(レース関係で実行している関数の実体の場所)がわからず,値の渡し方に苦戦しています.
またソリューション全体がとても大きいので簡潔に書いたつもりですが,
説明不足なところも多いと思うので,ソリューション全体の情報についても記載させてください.
ソリューション全体は
http://sourceforge.net/projects/torcs/f ... 2/download
にあります.
ドライブに関わるプロジェクト(bt)は
http://www1.axfc.net/uploader/so/2678822.zip
に置きました.
なお以下にbt内で関連している関数とクラスのみ掲載します.
drive.cpp
bt.cpp
すみませんがよろしくお願い致します.
現在の開発環境はwindows visualstudio2008Expressです.
質問は走行中の自動車の時系列データ(car->_steerCmd, car->_gearCmd, car->_accelCmd, car->_brakeCmd, car->_clutchCmdなど...)
を取得したいのですが,プログラミング初心者でしてまだできていません.
以下のように,drive.cpp内のvoid Driver::drive(tSituation *s)内
から欲しいパラメータの時系列データを配列に格納したあと,
bt.cpp内のstatic void shutdown(int index)
で,自作したstatic void filewrite(float data[])という関数を実行できれば
いいのかなというところまで考えてみたのですが,まだできていません.
原因として,プログラムが大きいためメイン関数?(レース関係で実行している関数の実体の場所)がわからず,値の渡し方に苦戦しています.
またソリューション全体がとても大きいので簡潔に書いたつもりですが,
説明不足なところも多いと思うので,ソリューション全体の情報についても記載させてください.
ソリューション全体は
http://sourceforge.net/projects/torcs/f ... 2/download
にあります.
ドライブに関わるプロジェクト(bt)は
http://www1.axfc.net/uploader/so/2678822.zip
に置きました.
なお以下にbt内で関連している関数とクラスのみ掲載します.
drive.cpp
#include "driver.h"
#include<iostream>
using namespace std;
// Static variables.
Cardata *Driver::cardata = NULL;
double Driver::currentsimtime;
Driver::Driver(int index)
{
INDEX = index;
}
Driver::~Driver()
{
delete opponents;
delete pit;
delete [] radius;
delete learn;
delete strategy;
if (cardata != NULL) {
delete cardata;
cardata = NULL;
}
}
void Driver::drive(tSituation *s)
{
memset(&car->ctrl, 0, sizeof(tCarCtrl));
update(s);
//pit->setPitstop(true);
if (isStuck())//車がスタックしている場合
{
car->_steerCmd = -mycardata->getCarAngle() / car->_steerLock;
car->_gearCmd = -1; // Reverse gear.
car->_accelCmd = 1.0f; // 100% accelerator pedal.
car->_brakeCmd = 0.0f; // No brakes.
car->_clutchCmd = 0.0f; // Full clutch (gearbox connected with engine).
}
else //通常時
{
car->_steerCmd = filterSColl(getSteer());
car->_gearCmd = getGear();
car->_brakeCmd = filterABS(filterBrakeSpeed(filterBColl(filterBPit(getBrake()))));
if (car->_brakeCmd == 0.0f)
{
car->_accelCmd = filterTCL(filterTrk(filterOverlap(getAccel())));
}
else
{
car->_accelCmd = 0.0f;
}
car->_clutchCmd = getClutch();
}
//ブレーキの位置とそのときかけているブレーキ量
/*if(car->_brakeCmd != 0.0f)
{
cout << car->_pos_X << ' '<< car->_pos_Y << ' '<< car->_brakeCmd <<endl;
}else
{
cout << "0.0\n" << endl;
}*/
float temp=car->_steerCmd;
value[i]=temp;
//cout<< value[i] << ' ' << i <<endl;
i++;
}
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
#include <tgf.h>
#include <track.h>
#include <car.h>
#include <raceman.h>
#include <robottools.h>
#include <robot.h>
#include "driver.h"
#define NBBOTS 10
static const char* botname[NBBOTS] = {
"bt 1", "bt 2", "bt 3", "bt 4", "bt 5",
"bt 6", "bt 7", "bt 8", "bt 9", "bt 10"
};
static const char* botdesc[NBBOTS] = {
"bt 1", "bt 2", "bt 3", "bt 4", "bt 5",
"bt 6", "bt 7", "bt 8", "bt 9", "bt 10"
};
static Driver *driver[NBBOTS];
static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s);
static void newRace(int index, tCarElt* car, tSituation *s);
static void drive(int index, tCarElt* car, tSituation *s);
static int pitcmd(int index, tCarElt* car, tSituation *s);
static void shutdown(int index, float data[]);
static int InitFuncPt(int index, void *pt);
static void endRace(int index, tCarElt *car, tSituation *s);
static void filewrite(float data[]);
static int InitFuncPt(int index, void *pt)
{
tRobotItf *itf = (tRobotItf *)pt;
// Create robot instance for index.
driver[index] = new Driver(index);
itf->rbNewTrack = initTrack; // Give the robot the track view called.
itf->rbNewRace = newRace; // Start a new race.
itf->rbDrive = drive; // Drive during race.
itf->rbPitCmd = pitcmd; // Pit commands.
itf->rbEndRace = endRace; // End of the current race.
itf->rbShutdown = shutdown; // Called before the module is unloaded.
itf->index = index; // Index used if multiple interfaces.
return 0;
}
//File write
static void filewrite(float data[])
{
FILE *fp;
char *fname = "dataset.csv";
char *s1 = "steer";
fp = fopen( fname, "w" );
if( fp == NULL )
{
printf( "%sファイルが開けません\n", fname );
}
else
{
int datasize = sizeof(data);
for(int i=0; i<datasize; i++)
{
fprintf( fp, "%f\n", data[i]);
}
printf( "%sファイル書き込みが終わりました\n", fname );
}
fclose( fp );
}
static void drive(int index, tCarElt* car, tSituation *s)
{
driver[index]->drive(s);
}
// Called before the module is unloaded.
static void shutdown(int index, float data[])
{
cout << "################レース終了###################"<< endl;
//FileWrite(value);
cout << data << endl;
for(int i=0; i<sizeof(data);i++)
{
cout << data[i] << endl;
}
delete driver[index];
}