質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

5003閲覧

Visual studioにおけるビルド時のエラー” tCarCtrl' のメンバーではありません”

muton

総合スコア31

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2018/12/20 10:59

編集2018/12/20 11:33

発生している問題・エラーメッセージ

オープンソースコードのカーシュミレーションソフトにおいて作成した車両制御システムの実用性を検討したいと考えています. そこで,ビルドを行うと #ifdef TL_ENABLE_RESTARTS /* If Simulink has requested a restart process this before anything else */ if (tlData->controlFlag == TL_RESTART_RACE) { car->ctrl.askRestart = true; return; } #endif のcar->ctrl.askRestart = true;という行で以下のエラーが発生します Visual studio のバージョンは2017です. どのような原因が考えられるでしょうか. 宜しくお願い致します. 重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態 エラー C2039 'askRestart': 'tCarCtrl' のメンバーではありません。 matlab c:\users\owner\desktop\torcs-1.3.7\src\drivers\verifiableautonomy-torcslink-2f28237\matlab.cpp 153 エラー (アクティブ) E0135 class "tCarCtrl" にメンバー "askRestart" がありません matlab C:\Users\owner\Desktop\torcs-1.3.7\src\drivers\VerifiableAutonomy-TORCSLink-2f28237\matlab.cpp 153

C++コード

#include <ctime> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <tgf.h> #include <track.h> #include <car.h> #include <raceman.h> #include <robottools.h> #include <robot.h> #include "TORCSLink.h" 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 void shutdown(int index); static int InitFuncPt(int index, void *pt); static void endRace(int index, tCarElt *car, tSituation *s); /* Module entry point */ extern "C" int matlab(tModInfo *modInfo) { /* Set up shared memory */ if (tlInitSharedMemory() != 0) { printf("matlab robots: Error initialising shared memory!\n"); } /* Clear all structures */ memset(modInfo, 0, N_VEHICLES*sizeof(tModInfo)); for (int i = 0; i < N_VEHICLES; i++) { char name[64]; sprintf(name, "matlab %d", i); modInfo[i].name = strdup(name); modInfo[i].desc = strdup(name); modInfo[i].fctInit = InitFuncPt; modInfo[i].gfId = ROB_IDENT; modInfo[i].index = i; } printf("matlab robots: Initialised!\n"); return 0; } /* Module interface initialization */ static int InitFuncPt(int index, void *pt) { tRobotItf *itf = (tRobotItf *)pt; 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 = NULL; /* 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; } /* Called for every track change or new race */ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s) { /* Don't load any particular car set up */ *carParmHandle = NULL; } /* Start a new race */ static void newRace(int index, tCarElt* car, tSituation *sit) { // Zero data store memset((void*)tlData,0,sizeof(TORCSData_t)); tlData->controlFlag = TL_NO_DATA; printf("matlab %d: Online\n",index); } int lastEnable = 0; /* Called once per robot update */ static int oncePerCycle(double t) { /* Inform user when enabling/disabling */ if (lastEnable != tlData->enable) { if (tlData->enable) { printf("matlab robots: Enabled!\n"); } else { printf("matlab robots: Disabled!\n"); } } lastEnable = tlData->enable; /* If we are disabled, occasionally let the user know we're still alive, but otherwise do nothing */ if (tlData->enable < 1) { tlData->controlFlag = TL_READY; /* Tell Simulink we're ready and waiting... */ if (fmod(t, 10) <= RCM_MAX_DT_SIMU) { printf("matlab robots: Disabled (t=%.0fs)\n", t); } return -1; } else { tlData->controlFlag = TL_NO_DATA; } /* We want to block TORCS until we have an update from Simulink this ensures the two remain in sync Ensure we timeout after 10s so we don't block forever if Simulink dies on us */ int startT = std::time(0); int timeout = 0; while (tlData->enable == 1 && tlData->controlFlag == TL_NO_DATA) { if ((std::time(0) - startT) > 5) { startT = std::time(0); switch (timeout) { case 0: printf("matlab robots: No data from Simulink in the last 5 seconds... waiting 5 more...\n"); timeout++; break; case 1: printf("matlab robots: No data from Simulink in the last 10 seconds... disabling robot...\n"); tlData->enable = 0; return -1; } } } return 0; } double lastTime = 0.0; /* Drive during race */ static void drive(int index, tCarElt* car, tSituation *s) { /* We don't want control before the race starts */ if (s->currentTime < 0) { return; } #ifdef TL_ENABLE_RESTARTS /* If Simulink has requested a restart process this before anything else */ if (tlData->controlFlag == TL_RESTART_RACE) { car->ctrl.askRestart = true; return; } #endif if ((s->currentTime - lastTime) > RCM_MAX_DT_ROBOTS / 2) { if (oncePerCycle(s->currentTime) < 0) { return; } else { lastTime = s->currentTime; } } /* If we've got this far then we have new data from Simulink, update our control */ car->ctrl.accelCmd = tlData->vehicle[index].control.throttle; car->ctrl.brakeCmd = tlData->vehicle[index].control.brake; car->ctrl.clutchCmd = tlData->vehicle[index].control.clutch; car->ctrl.gear = tlData->vehicle[index].control.gear; car->ctrl.steer = tlData->vehicle[index].control.steering; /* Update the outputs of our vehicle */ #ifdef TL_USE_DOUBLE_POSITION tlData->vehicle[index].data.position[0] = car->pub.DynGCg.posD.x; tlData->vehicle[index].data.position[1] = car->pub.DynGCg.posD.y; tlData->vehicle[index].data.position[2] = car->pub.DynGCg.posD.z; #else tlData->vehicle[index].data.position[0] = car->pub.DynGCg.pos.x; tlData->vehicle[index].data.position[1] = car->pub.DynGCg.pos.y; tlData->vehicle[index].data.position[2] = car->pub.DynGCg.pos.z; #endif tlData->vehicle[index].data.velocity[0] = car->pub.DynGCg.vel.x; tlData->vehicle[index].data.velocity[1] = car->pub.DynGCg.vel.y; tlData->vehicle[index].data.velocity[2] = car->pub.DynGCg.vel.z; tlData->vehicle[index].data.acceleration[0] = car->pub.DynGCg.acc.x; tlData->vehicle[index].data.acceleration[1] = car->pub.DynGCg.acc.y; tlData->vehicle[index].data.acceleration[2] = car->pub.DynGCg.acc.z; tlData->vehicle[index].data.angle[0] = car->pub.DynGCg.pos.ax; tlData->vehicle[index].data.angle[1] = car->pub.DynGCg.pos.ay; tlData->vehicle[index].data.angle[2] = car->pub.DynGCg.pos.az; tlData->vehicle[index].data.angularVelocity[0] = car->pub.DynGC.vel.ax; tlData->vehicle[index].data.angularVelocity[1] = car->pub.DynGC.vel.ay; tlData->vehicle[index].data.angularVelocity[2] = car->pub.DynGC.vel.az; double error = RtTrackSideTgAngleL(&(car->_trkPos)) - car->_yaw; error = fmod(error + 2*PI,2*PI); // Normalise heading angle if (error > PI) { error = error - 2*PI; } tlData->vehicle[index].data.headingError = error; tlData->vehicle[index].data.lateralError = car->_trkPos.toMiddle; tlData->vehicle[index].data.roadDistance = RtGetDistFromStart(car); double curvature = 0.0; if (car->_trkPos.seg->radius > 0) { curvature = 1.0/car->_trkPos.seg->radius; if (car->_trkPos.seg->type == TR_RGT) { curvature *= -1; } } tlData->vehicle[index].data.roadCurvature = curvature; tlData->vehicle[index].data.engineRPM = car->_enginerpm * 9.54929659; // For some reason RPM is actually rad/s! } // End of the current race. static void endRace(int index, tCarElt *car, tSituation *s) { printf("matlab %d: Offline\n", index); } // Called before the module is unloaded. static void shutdown(int index) { tlCloseSharedMemory(); }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

if (tlData->controlFlag == TL_RESTART_RACE) {という行で以下のエラーが発生します

間違いです。

car->ctrl.askRestart = true;

ビルドエラーはこの行で発生しているように見受けられます。

エラーは発生せずビルドは無事に終了しています.

無事終了していません。

これ以上は、tCarElt構造体?クラス?の内容が不明なため、どなたも回答できないと思われます。

tCarEltにカーソルを合わせ、F12キーを押して定義へジャンプした上で、この内容を追記いただけますでしょうか。

投稿2018/12/20 11:31

kazto

総合スコア7196

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

muton

2018/12/20 11:37

回答ありがとうございます. 誤字修正致しました. tCarEltにカーソルを合わせ、F12キーを押し,飛んだ箇所のコードを追記します.宜しくお願い致します. /** Car structure (tCarElt). This is the main car structure, used everywhere in the code. */ typedef struct CarElt { int index; /**< car index */ tInitCar info; /**< public */ tPublicCar pub; /**< public */ tCarRaceInfo race; /**< public */ tPrivCar priv; /**< private */ tCarCtrl ctrl; /**< private */ tCarPitCmd pitcmd; /**< private */ struct RobotItf *robot; /**< private */ struct CarElt *next; } tCarElt;
kazto

2018/12/20 11:45

では、次お手数ですが同様にtCarCtrlでF12で定義に飛んで、同様に内容を追記お願いします。
muton

2018/12/21 02:44

tCarCtrlでF12で定義に飛んだ箇所になります.宜しくお願い致します. typedef struct { tdble steer; /**< Steer command [-1.0, 1.0] */ tdble accelCmd; /**< Accelerator command [0.0, 1.0] */ tdble brakeCmd; /**< Brake command [0.0, 1.0] */ tdble clutchCmd; /**< Clutch command [0.0, 1.0] */ int gear; /**< [-1,6] for gear selection */ int raceCmd; /**< command issued by the driver */ #define RM_CMD_NONE 0 /**< No race command */ #define RM_CMD_PIT_ASKED 1 /**< Race command: Pit asked */ char msg[4][32]; /**< 4 lines of 31 characters 0-1 from car 2-3 from race engine */ #define RM_MSG_LEN 31 float msgColor[4]; /**< RGBA of text */ int lightCmd; /**< Lights command */ #define RM_LIGHT_HEAD1 0x00000001 /**< head light 1 */ #define RM_LIGHT_HEAD2 0x00000002 /**< head light 2 */ } tCarCtrl;
kazto

2018/12/21 06:10

`tCarCtrl`構造体のメンバに`askRestart`と言うものは存在していません。これによりエラーが発生しています。
muton

2018/12/21 06:26

回答ありがとうございます. `tCarCtrl`構造体のメンバに`askRestart`を追加すればよろしいのでしょうか. また,追加するのであればどのようにして追加すれば良いでしょうか. 宜しくお願い致します.
kazto

2018/12/21 07:39

追加することにどんな意味があるのかは、このプログラムの設計を知っている方にしか分かり得ません。 追加して良いのか、当該行を削除すればいいのかは、設計次第になります。
muton

2018/12/21 08:02

回答ありがとうございます. 追加機能のためにaskRestartを追加したいと考えているのですが, どのように定義すれば良いでしょうか.
kazto

2018/12/21 08:57

そろそろ、ご自身でお考えになれるレベルまで来ています。 どのように追加すればいいと思いますか?(逆質問)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問