基础服务类¶
ServiceAPI¶
帧同步与回调函数¶
SimOne 系统中的帧同步是基于虚拟时间的逻辑帧,这意味着整个系统的操作都是按帧进行的:
(1)帧同步的概念:
- 系统中的每个动作都依赖于逻辑帧的执行。
- 一帧的执行时间在现实中可以很短(如 0.00001 秒)或很长(如 100000 秒),而与真实时间解耦。
- 通过基于帧的时间控制,可以灵活地调节仿真系统的运行速度,例如加速或减缓案例运行。
(2)获取 SimOne 数据的方法:
- 回调函数:当系统有新数据时,系统会通过注册的回调函数通知用户获取数据。
- 主动调用 API:用户可以主动调用 API(如:
GetGps)来获取当前帧的数据。如果系统帧没有进步,连续调用将返回相同的数据。
(3)帧同步和数据获取的结合:
- 使用帧同步 API,可控制 SimOne 系统案例的运行时间。在某个给定帧内的数据,无论调用多少次获取数据的 API,都将是相同的。
- 如果不使用帧同步控制,直接调用 API 或回调函数获取数据的方式更为直接,适用于仅需获取场景数据的使用案例。
选择车辆并初始化¶
注意
该操作可以设定是否使用同步帧功能
1、帧同步(保证实时性和稳定性)
2、非帧同步(提高运行效率)
| 事件 | API |
|---|---|
| 初始化 SimOne API | SIMONE_API bool InitSimOneAPI(const char mainVehicleId = "0", bool isFrameSync = false, const char serverIP = "127.0.0.1", int port = 23789, void(startCase)()=0, void(endCase)()=0, int registerNodeId=0); |
| 多车版本-初始化 SimOne API | SIMONE_API bool InitSimOneAPIEx(char mainVehicleIdList, int count, bool isFrameSync = false, const char serverIP = "127.0.0.1", int port = 23789, void(startCase)() = 0, void(*endCase)() = 0, int registerNodeId = 0); |
| 初始化 SimOne API 带超时 | SIMONE_API bool InitSimOneAPIWithTimeOut(const char mainVehicleId = "0", bool isFrameSync = false, const char serverIP = "127.0.0.1", int port = 23789, int timeOutMS = -1, void(startCase)() = 0, void(endCase)() = 0, int registerNodeId = 0); |
| 多车版本 - 初始化 SimOne API 带超时 | SIMONE_API bool InitSimOneAPIExWithTimeOut(char mainVehicleIdList, int count, bool isFrameSync = false, const char serverIP = "127.0.0.1", int port = 23789, int timeOutMS = -1, void(startCase)() = 0, void(*endCase)() = 0, int registerNodeId = 0); |
| 参数名 | 解释 |
|---|---|
| mainVehicleId | 主车 ID(范围从 0 到 9) |
| isFrameSync | 是否同步帧 |
| serverIP | BridgeIO 服务器 IP 地址 |
| port | BridgeIO 服务器端口号 |
| startCase | 用例 开始前调用的回调函数 |
| endCase | 用例 结束后调用的回调函数 |
| registerNodeId | 注册节点 ID(保留参数,预留后续扩展使用) |
| count | 主车辆 ID 数量 |
| timeOutMS | 超时时间,以毫秒为单位 |
获取主车状态¶
| 事件 | API |
|---|---|
| 主动获取主车状态 | SIMONE_API bool GetMainVehicleStatus(const char mainVehicleId, SimOne_Data_MainVehicle_Status pMainVehicleStatus); |
| 回调方式获取主车状态 | SIMONE_API bool SetMainVehicleStatusUpdateCB(void(cb)(const char mainVehicleId, SimOne_Data_MainVehicle_Status *pMainVehicleStatus)); |
| 参数名 | 解释 |
|---|---|
| mainVehicleId | 主车的 ID |
| pMainVehicleStatus | 指向主车状态信息的指针 |
SimOne_Data_MainVehicle_Status 结构体说明:
| 参数名 | 解释 |
|---|---|
| mainVehicleId | 主车 ID 的队列 |
| mainVehicleStatus | 对应的状态 |
其他函数说明¶
| 类别 | 事件 | API |
|---|---|---|
| 退出 | 退出 API Node | SIMONE_API bool TerminateSimOneAPI(); |
| 获取 用例 信息 | 获取 用例 详情 | SIMONE_API bool GetCaseInfo(SimOne_Data_CaseInfo *pCaseInfo); |
| 获取 用例 运行状态 | SIMONE_API ESimOne_Case_Status GetCaseRunStatus(); | |
| 获取主车信息列表 | SIMONE_API bool GetMainVehicleList(SimOne_Data_MainVehicle_Info *pMainVehicleInfo); | |
| 获取高精度地图元数据信息 | SIMONE_API bool GetHDMapData(SimOne_Data_Map* hdMap); | |
| 获取当前库的版本号 | SIMONE_API const char *GetVersion(); | |
| 案例控制 | 等待并获取当前帧值 | SIMONE_API int Wait(); |
| 进行下一帧 | SIMONE_API void NextFrame(int frame); //frame 为具体的第几帧 | |
| 暂停,用于非帧同步调试 | SIMONE_API int Pause(); | |
| 继续,用于非帧同步调试 | SIMONE_API int Continue(); | |
| 自动回调帧数据 | 仿真场景中每帧的回调函数 | SIMONE_API bool SetFrameCB(void(*FrameStart)(int frame), void(*FrameEnd)(int frame)); |
| 截取 Node 信息 | Node 通信数据发送 API | SIMONE_API bool SendRouteMessage(int length, void* pBuffer, int msgId, int toNodeId, ESimOne_Client_Type toNodeType); |
| Node 通信数据接收 API | SIMONE_API bool ReceiveRouteMessageCB(void(*cb)(int fromId, ESimOne_Client_Type fromType, int length, const void* pBuffer, int commandId)); | |
| 设置日志格式 | 日志设置接口 | SIMONE_API bool SetLogOut(ESimOne_LogLevel_Type level, const char *format, ...); |
SimOne_Data_CaseInfo 如下:
| 参数名 | 解释 |
|---|---|
| caseName | 用例 名称 |
| caseId | 用例 ID |
| taskId | 任务 ID |
SimOne_Data_MainVehicle_Info 结构如下:
| 参数名 | 解释 |
|---|---|
| size | 车辆数量 |
| id_list | 车辆 ID |
| type_list | 车辆类型 |
SimOne_Data_Map 结构如下:
| 参数名 | 解释 |
|---|---|
| openDrive | 地图名称 |
| openDriveUrl | 地图下载的URL |
| opendriveMd5 | 地图文件的MD5值 |