Skip to content

HDMap Example

Note

Example directory: [SimOne installation directory]\SimOneAPI\Tutorial\HDMap

Algorithm Overview

(1) Start the simulation use case: When a SimOne simulation use case starts, the system generates a URL and sends it to the HDMap API.

(2) Load the map file: The HDMap API sends an HTTP request using the received URL to load the .xodr map file specified at use case creation from the data platform. The map file is loaded into memory for subsequent use.

(3) Real-time data provision: Based on the ego vehicle's dynamic position on the static map, the HDMap API returns key map data to third-party driving algorithms in real time, including map ground truth, road network information, lane and lane marking types, and more.

Algorithm Flow

HDMap API

Note

[SimOne installation path]/SimOne/SimOneAPI/include/SimOneHDMapAPI.h

  • Pseudocode example — get the nearest lane to the ego vehicle's current position:
#include "SimOneServiceAPI.h"
#include "SimOneHDMapAPI.h"
#include "SimOneSensorAPI.h"
#include "SSD/SimPoint3D.h"
#include "SSD/SimString.h"

int main(int argc, char* argv[])
{
        const char* mv_id = "0"; // Ego vehicle ID
        bool isJoinTimeLoop = false; // Whether to join frame synchronization
        const char* serverIP = "127.0.0.1"; // BridgeIO IP

    // Step1: Initialize SimOne API
    InitSimOneAPI(mv_id, isJoinTimeLoop, serverIP);

    // Step2: Load the HD map — the map file is specified when the use case is created in SimOne
        int timeout = 20; // HDMap loading timeout (seconds); the function returns if timed out
        if (!SimOneAPI::LoadHDMap(timeout)) // Retrieve and load the map file from the data platform
        {
                std::cout << "LoadHDMap Failed!" << std::endl;
        return 0;
        }

        std::unique_ptr<SimOne_Data_Gps> pGPS = std::make_unique<SimOne_Data_Gps>();
        while (true)
        {
        // Step3: Get ego vehicle GPS data
                if (!GetGps(0/*vehicleId*/, pGPS.get()))
                {
                        std::cout << "Get GPS Failed!" << std::endl;
                }
        else
        {
            // Input: ego vehicle's current position (3D point)
            SSD::SimPoint3D pos(pGps->posX, pGps->posY, pGps->posZ);
            // Output: lane ID in format roadId_sectionIndex_laneId
            //   e.g. "1_0_-1" = first lane to the right of the road reference line;
            //        "1_0_2"  = second lane to the left
            SSD::SimString laneId;
            // Output: s-t coordinates of the ego vehicle position relative to the detected lane
            double s, t;
            // Output: s-t coordinates relative to the road centerline (approximate);
            //   use GetRoadST API for a more precise value
            double s_toCenterLine, t_toCenterLine;

            // Step 4: Get the lane closest to the input position (own lane takes priority)
            if (!GetNearMostLane(pos, laneId, s, t, s_toCenterLine, t_toCenterLine))
                {
                std::cout << "Error: lane is not found." << std::endl;
                }
            else
            {
                std::cout << "lane id: " << laneId.GetString() << std::endl;;
                std::cout << "s: " << s << "    t: " << t << std::endl;
                std::cout << "s_toCenterLine: " << s_toCenterLine << "  t_toCenterLine: " << t_toCenterLine << std::endl;
            }
        }

                std::this_thread::sleep_for(std::chrono::milliseconds(100));
        }

        return 0;
}

Build Environment

  • HDMap API Tutorial project directory structure:
Tutorial
    ├── bin
    │   ├── DynamicsTest
    │   ├── HDMap
    │   ├── logServer.txt
    │   ├── log_taskImage.txt
    │   ├── PNCSample
    │   ├── SensorSample
    │   └── SensorV2X
    ├── Build
    │   ├── build_debug.bat
    │   ├── build_release
    │   ├── build_release.bat
    │   ├── CMakeLists.txt
    │   ├── gen_make_debug.sh
    │   ├── gen_make_release.sh
    │   ├── gen_vs_proj_debug.bat
    │   ├── gen_vs_proj_release.bat
    │   ├── rebuild_debug.sh
    │   └── rebuild_release.sh
    ├── HDMap
    │   ├── CMakeLists.txt
    │   ├── gen_vs_proj.bat
    │   ├── include
    │   ├── src

    bin:   Output directory
    Build: Build directory
    V2X:   V2X API example source directory

Build:

CMakeLists.txt supports generating projects for Windows and Ubuntu.

  • Windows:

  • Enter the Build directory and run gen_vs_proj_debug.bat or gen_vs_proj_release.bat to generate a Visual Studio project.

  • Open the Visual Studio project and build the HDMap project.

  • Linux:

  • cd Build

  • ./gen_make_debug.sh (or ./gen_make_release.sh)

  • cd build_debug (or cd build_release)

  • make -j4

Usage

  • Call the corresponding HDMap APIAPI Feature Support

  • API testing:

  • Start SimOne and create a new use case.

  • Create a new ego vehicle (set the control mode to Manual / API Control).

  • Run the use case (select the ego vehicle).

  • Build the test code; the executable is generated in the bin directory.

  • Run the example program and view the results.