0

車の現在の位置を取得するためにSUMO(TRACIサーバー)にクエリを実行する関数をTRACIクライアントで作成しました。これはXY座標系で正しくなっています。ここで、取得した XY 位置を緯度と経度に変更したいと思います。http://www.sumo.dlr.de/wiki/TraCI/Simulation_Value_Retrieval#Command_0x82:_Position_Conversionにあるドキュメントに従ってコーディングしまし たが、エラーが発生しました!! . コードを見てください

TraCITestClient::Position TraCITestClient::getPosition()
{
send_commandGetVariable(0xa4, 0x42, "veh1");

tcpip::Storage inMsg;
try {
    std::string acknowledgement;
    check_resultState(inMsg, 0xa4, false, &acknowledgement);

} catch (tcpip::SocketException& e) {
    pos.x = -1;
    pos.y = -1;
    return pos;
}
check_commandGetResult(inMsg, 0xa4, -1, false);
// report result state
try {
    int variableID = inMsg.readUnsignedByte();
    std::string objectID = inMsg.readString();

    int valueDataType = inMsg.readUnsignedByte();

    pos.x = inMsg.readDouble();
    pos.y = inMsg.readDouble();

} catch (tcpip::SocketException& e) {
    std::stringstream msg;
    msg << "Error while receiving command: " << e.what();
    errorMsg(msg);
    pos.x = -1;
    pos.y = -1;
    return pos;
}

//till here i am getting correct value in pos.x and pos.y

// now i want to convert these XY coordinates to actual Lat Long


    tcpip::Storage* tmp = new tcpip::Storage;


    tmp->writeByte(TYPE_COMPOUND);
    tmp->writeInt(2);


    tmp->writeDouble(pos.x);
    tmp->writeDouble(pos.y);
    tmp->writeByte(TYPE_UBYTE);

    tmp->writeUnsignedByte(POSITION_LON_LAT);

send_commandGetVariable(0x82, 0x58, "veh1",tmp); //**here i am getting error**

tcpip::Storage inMsgX;
try {
    std::string acknowledgement;
    check_resultState(inMsgX, 0x82, false, &acknowledgement);

} catch (tcpip::SocketException& e) {
    return pos;
}
check_commandGetResult(inMsgX, 0x82, -1, false);
// report result state
try {

    int variableID = inMsgX.readUnsignedByte();
    std::string objectID = inMsgX.readString();

    int valueDataType = inMsgX.readUnsignedByte();


    pos.x = inMsgX.readDouble();
    pos.y = inMsgX.readDouble();

} catch (tcpip::SocketException& e) {
    std::stringstream msg;
    msg << "Error while receiving command: " << e.what();
    errorMsg(msg);
    return pos;
}

return pos;
}

したがって、SUMO サーバーで発生するエラーは次のとおりです。エラー: tcpip::Storage::readIsSafe: ストレージから 823066624 バイトを読み取りたいが、残り 20 バイトしか終了していません (エラー時)。

4

1 に答える 1

0

車輪を再発明する必要はありません。src/utils/traci/TraCIAPI.h で利用可能な TraCI C++ API があります。あなたの最初の電話は

 TraCIPosition pos = TraCIAPI::VehicleScope::getPosition("veh1");

残念ながら、2 番目の呼び出しはまだ C++ API の一部ではありませんが、おそらく次を使用して修正できます。

tcpip::Storage* tmp = new tcpip::Storage;
tmp->writeByte(TYPE_COMPOUND);
tmp->writeInt(2);
tmp->writeByte(POSITION_2D);
tmp->writeDouble(pos.x);
tmp->writeDouble(pos.y);
tmp->writeByte(TYPE_UBYTE);
tmp->writeUnsignedByte(POSITION_LON_LAT);
send_commandGetVariable(CMD_GET_SIM_VARIABLE, POSITION_CONVERSION, "",tmp);

お使いのバージョンには最初の型指定子 (POSITION_2D) が含まれておらず、コマンドと変数に間違った 16 進コードが使用されていました。ここでは、16 進コードの代わりに定数を使用することをお勧めします。

于 2016-12-08T18:05:22.803 に答える