Home > Technology peripherals > AI > body text

Apollo partners with Carsim/TruckSim for joint simulation

WBOY
Release: 2024-01-13 16:51:16
forward
1236 people have browsed it

1. Background

Simulation plays an important role in autonomous driving research and development. It can greatly improve research and development efficiency and provide guarantee for the reliability of algorithms. As an excellent open source platform, Baidu Apollo system is very suitable for research by friends who are interested in learning autonomous driving. In addition, Carsim/Trucksim is a highly respected classic vehicle dynamics simulation tool.

This article introduces the method of realizing local real-time simulation through the combination of Apollo and Trucksim. It is suitable for beginners to build a simulation platform and study the Apollo system.

2. Architecture design

The core code of the Apollo project is implemented in C. Common interfaces for Trucksim include simulink, Python and C language. This article will first introduce the architecture of Apollo, simulink and Trucksim joint simulation, and discuss the problems existing in this simulation system. Next, we will focus on the joint simulation of Apollo and Trucksim.

2.1 Apollo, simulink and Trucksim solutions

Simulink and Apollo can communicate through ROS. Since Apollo's message data format is protobuf, and Simulink's ROS tool only supports standard ROS messages (ROS msg), a format conversion node can be added to Apollo to achieve compatibility. Regarding the solution of Simulink calling Trucksim, there are many resources on the Internet for reference, so I will not go into details.

Apollo partners with Carsim/TruckSim for joint simulation

simulink solution diagram

2.2 Apollo, rosbridge and Trucksim solutions

Establish websocket communication between the QT project and the Apollo project. In the Apollo project, the mutual conversion between ros messages (or cyber messages) and websockets is realized by adding the rosbridge (or cyber_bridge) module. The QT project is implemented in C as a websocket client and calls Trucksim's dynamic library to realize the function of running Trucksim in real time.

Apollo partners with Carsim/TruckSim for joint simulation

rosbridge solution diagram

3. Function implementation

3.1 Apollo, simulink and Trucksim solutions

3.1.1 Simulink configuration

The Simulink toolkit has a ROS support package, and the ROS network address is configured as shown in Figure 2. Hostname/IP Address and Port are the address and port number of ROS_MASTER_URI respectively, which are explained in the communication mechanism above.

Apollo partners with Carsim/TruckSim for joint simulation

Configure ROS network address

ROS subscriber receives messages from the interface, so the Topic, Message type, and Sample time must correspond to the program in the interface.

Apollo partners with Carsim/TruckSim for joint simulation

Configuring ros subcribe

In order to facilitate debugging and verification, now start ROS on the MATLAB side. The configuration process is as follows:

MATLAB setting instructions:

>> setenv('ROS_MASTER_URI','http://192.168.103.122:11311')>> setenv('ROS_IP','192.168.103.198')>> rosinit('192.168.103.122')
Copy after login

3.1.2 TruckSim configuration

Configuration interface

Trucksim is a wizard-based programming. Parameter configuration interface: Select 5A Tractor (SS_SSS) for trucks. See Figure 3 for specific parameters. Control interface: Select simulink for Models.

Apollo partners with Carsim/TruckSim for joint simulation

Main interface

Apollo partners with Carsim/TruckSim for joint simulation

Input parameter configuration interface

Apollo partners with Carsim/TruckSim for joint simulation

Output parameter configuration interface

3.2 Apollo, rosbridge and Trucksim solutions

3.2.1 Configuring rosbridge in apollo

There are many online tutorials for rosbridge installation. This article will not go into details.

The usage is as follows:

cd ros_pkgs_ws

catkin_make

Start rosbridge

source /apollo/ros_pkgs_ws/devel/setup.bash

PATH=/usr/local/miniconda2/bin:$PATH

roslaunch rosbridge_server rosbridge_websocket.launch

3.2.1 Qt project configuration instructions

3.2.1.1 Qt and CMake version information

Apollo partners with Carsim/TruckSim for joint simulation

3.2.1.3 Interface definition of Apollo project and QT project

Apollo partners with Carsim/TruckSim for joint simulation

/apollo/trucksim/pose

{"op":"publish","topic":"/apollo/tucksim/pose","msg": {"header": {"timestamp_sec":1572253610.76292, "sequence_num":77}, "trucksimpose": {"XCG_TM":30.9964522249, // 单位:m "YCG_TM":0.657853758823, // 单位:m "ZCG_TM":1.00644079555, // 单位:m "YAW":-0.015505948987, // 单位:rad "VX":7.81497285565, // 单位:m/s "STEER_SW":2.84450684087, // 单位:rad "AV_Y":0.133153549217, // 单位:rad/s "GEARSTAT":5.0, // 无单位 "XCG_TM2":22.5890979801, // 单位:m "YCG_TM2":-0.471483304991, // 单位:m "ZCG_TM2":2.08466406388, // 单位:m "YAW_2":-0.0253130178796, // 单位:rad "VY":0.326368169782, // 单位:m/s "DISTANCE":31.0034324244, // 单位:m "DELTA_YAW":-0.015505948987, // 单位:rad "DISTANCE_2":22.5940178822, // 单位:m "DELTA_YAW_2":-0.0253130178796 // 单位:rad/s } }}
Copy after login

4. 使用心得

  1. TruckSim模型离散时间补偿设置为0.001s,即模型更新频率为1000hz,选择每个步长更新两次的积分方法(如:AM-2, RK-2等)。

注释:
1)真车是一个高阶非线性连续系统,TruckSim通过固定时间步长离散系统来模拟真车,当模型步长选择较大时(如之前设置的0.01s),模型较不准;TruckSim模型是由悬架系统-动力系统-转向系统-制动系统-轮胎模型-空气动力学等系统构成的复杂系统,当其中一个或多个系统因为时间步长太大而很不准时,就会出现车抖动比较明显的现象。

2)模型更新频率设为1000hz是TruckSim官网推荐的,经验证,这个频率能解决车抖动问题。

  1. 接口线程加载频率用定时器控制,加载调用simfile.sim,license和DLL的频率设置为1000hz,与Trucksim模型离散步长一致。

注释:
受3中积分方法决定,当选择每个步长更新两次的积分方法,VS_EXT_EQ_IN和VS_EXT_EQ_OUT更新频率是加载频率的2倍,为2000hz。

Apollo partners with Carsim/TruckSim for joint simulation

原文链接:https://mp.weixin.qq.com/s/8QNp5iQebE3lPJzEgq_bOA

The above is the detailed content of Apollo partners with Carsim/TruckSim for joint simulation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!