Utopi
a

../../../Engine/DeriverDataCache

export CC=/home/ujs/UnrealEngine_4.26/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang export CXX=/home/ujs/UnrealEngine_4.26/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang++

Carla_plexe

其实大项目考验的就是心智模型,做到一定规模之后就会越做越慢。

Have network and diskplay

docker run -it --network=host -e DISPLAY=:1 --privileged --gpus all --cpus=0 --memory=0 af987c2f46b5

OSM to xodr

osmfilter map.osm --keep="highway=" -o=highways.osm
import carla import random import time import os client = carla.Client("localhost", 2000) client.set_timeout(19.0) world = client.get_world() current_path = os.path.dirname(".") def load_customized_world(xodr_path, client): """ Load .xodr file and return the carla world object Parameters ---------- xodr_path : str path to the xodr file client : carla.client The created CARLA simulation client. """ if os.path.exists(xodr_path): with open(xodr_path) as od_file: try: data = od_file.read() except OSError: print("file could not be readed.") sys.exit() print("load opendrive map %r." % os.path.basename(xodr_path)) vertex_distance = 2.0 # in meters max_road_length = 500.0 # in meters wall_height = 3.0 # in meters extra_width = 0.6 # in meters world = client.generate_opendrive_world( data, carla.OpendriveGenerationParameters( vertex_distance=vertex_distance, max_road_length=max_road_length, wall_height=wall_height, additional_width=extra_width, smooth_junctions=False, enable_mesh_visibility=True, ), ) return world else: print("file not found.") return None xodr_path = "/home/ujs/mycode/carla_plexe/assets/freeway/map_package/IHP_map.xodr" world = load_customized_world(xodr_path, client) map = world.get_map() route = map.get_topology() waypoints = map.generate_waypoints(18) for spawn_point in waypoints: world.debug.draw_point(spawn_point.transform.location + carla.Location(z=0.5), size=0.1, color=carla.Color(255, 0, 0), life_time=30.0, persistent_lines=True) for waypoint in waypoints: location = waypoint.transform.location text_location = carla.Location(location.x, location.y, 2) # Set z = 2 meters text = f'({location.x:.2f}, {location.y:.2f}, {location.z:.2f})' world.debug.draw_string(text_location, text, draw_shadow=False, color=carla.Color(r=0, g=255, b=0), life_time=30.0, persistent_lines=True) def filter_waypoints(waypoints, minX, maxX, minY, maxY, minZ=-10, maxZ=10): """ Filter Carla waypoints based on specified X, Y, Z coordinate ranges. Args: waypoints (list): List of Carla waypoints to be filtered. minX, maxX, minY, maxY, minZ, maxZ (float): Coordinate range for filtering. Returns: list: Filtered list of waypoints. """ filtered_waypoints = [] for wp in waypoints: loc = wp.transform.location if minX <= loc.x <= maxX and minY <= loc.y <= maxY and minZ <= loc.z <= maxZ: filtered_waypoints.append(wp) return filtered_waypoints ## x: from -1250 to -1100 y: from 0 to -10 freewaySpawnPoints = filter_waypoints(waypoints,-1200,-1100,6,10) for waypoint in freewaySpawnPoints: location = waypoint.transform.location text_location = carla.Location(location.x, location.y, 2) # Set z = 2 meters text = f'({location.x:.2f}, {location.y:.2f}, {location.z:.2f})' world.debug.draw_string(text_location, text, draw_shadow=False, color=carla.Color(r=0, g=255, b=0), life_time=30.0, persistent_lines=True) def spawn_vehicles_on_points(client, vehicle_type, spawn_points): world = client.get_world() blueprint_library = world.get_blueprint_library() vehicle_bp = blueprint_library.find(vehicle_type) spawned_vehicles = [] for spawn_point in spawn_points: spawn_point_location = spawn_point.transform.location spawn_point_location.z += 1 try: vehicle = world.spawn_actor(vehicle_bp, carla.Transform(spawn_point_location, spawn_point.transform.rotation)) if vehicle is not None: spawned_vehicles.append(vehicle) except RuntimeError as e: print(f"Failed to spawn vehicle: {e}") return spawned_vehicles def apply_throttle_to_vehicles(vehicles): for vehicle in vehicles: vehicle.apply_control(carla.VehicleControl(throttle=1.0)) vehicles = spawn_vehicles_on_points(client, "vehicle.mitsubishi.fusorosa", freewaySpawnPoints) while True: apply_throttle_to_vehicles(vehicles) def destroy_all_vehicles(world): for actor in world.get_actors(): if actor.type_id.startswith('vehicle.'): actor.destroy() destroy_all_vehicles(world) def trace_route(point_a, point_b) map = world.get_map() route = map.get_topology() # Create a NetworkX graph G = nx.Graph() for edge in route: wp1, wp2 = edge[0].transform.location, edge[1].transform.location wp1_key = (wp1.x, wp1.y, wp1.z) wp2_key = (wp2.x, wp2.y, wp2.z) # Add edges to the graph G.add_edge(wp1_key, wp2_key) # Add weight if needed # Define your start and end waypoints start_location = carla.Location(x=..., y=..., z=...) # Replace with actual coordinates end_location = carla.Location(x=..., y=..., z=...) start_key = (start_location.x, start_location.y, start_location.z) end_key = (end_location.x, end_location.y, end_location.z) # Find the shortest path shortest_path = nx.shortest_path(G, source=start_key, target=end_key)

http://carla-assets.s3.amazonaws.com/20221201_5ec9328.tar.gz

0.9.5: 20190404_c7b464a 0.9.6: 20190710_0097e66 0.9.7: 20191221_c88604b 0.9.8: 20200306_06b6cb1 0.9.9: 20200422_ea5179a 0.9.10: 20200925_88f9ceb 0.9.11: 20201222_232b876 0.9.12: 20210730_564bcdc 0.9.13: 20211112_d5cfa12 0.9.14:

id: 10406158969854180981 is_intersection: True is_junction: True junction_id: 1901 lane_change: carla.libcarla.LaneChange.NONE lane_id: -1 lane_type: carla.libcarla.LaneType.Driving lane_width: 3.5

{'LV': -1, 'FV': -1, 'RV': 1} WARNING: Version mismatch detected: You are trying to connect to a simulator that might be incompatible with this API WARNING: Client API version = 0.9.15 WARNING: Simulator API version = 0.9.15-dirty {'LV': 0, 'FV': 0, 'RV': 2} WARNING: Version mismatch detected: You are trying to connect to a simulator that might be incompatible with this API WARNING: Client API version = 0.9.15 WARNING: Simulator API version = 0.9.15-dirty {'LV': 0, 'FV': 1, 'RV': -1}

在本文提出的异步一致性协议中,每辆车 i 在离散的更新时刻 tkit_k^i 接收其邻居车辆的位置信息,并根据接收到的信息更新自身的控制输入。具体而言,车辆 i 在区间 [tki,tk+1i)[t_k^i, t_{k+1}^i) 内的控制输入为:

ui(t)={ςijNi(tki)aij(tki)jNi(tki)aij(tki)(sj(tkiτijk)si(t)+(ttki+τijk)v0+dij)3ςi(vi(t)v0)(3ςi1)ai(t),if Ni(tki)ςi(si(tki)si(t)+(ttki)v0)3ςi(vi(t)v0)(3ςi1)ai(t),otherwiseu_i(t)=\begin{cases} \varsigma_i \sum_{j\in N_i(t_k^i)} \frac{a_{ij}(t_k^i)}{\sum_{j\in N_i(t_k^i)} a_{ij}(t_k^i)} \big(s_j(t_k^i-\tau_{ij}^k)-s_i(t)+(t-t_k^i+\tau_{ij}^k)v_0+d_{ij}\big) \\ -3\varsigma_i(v_i(t)-v_0) - (3\varsigma_i-1)a_i(t),\quad \mathrm{if}~N_i(t_k^i) \neq \emptyset\\ \varsigma_i(s_i(t_k^i)-s_i(t)+(t-t_k^i)v_0)-3\varsigma_i(v_i(t)-v_0)-(3\varsigma_i-1)a_i(t),\\ \mathrm{otherwise} \end{cases}

其中 si(t)s_i(t), vi(t)v_i(t), ai(t)a_i(t) 分别表示车辆 i 在 t 时刻的位置、速度和加速度,v0v_0 为参考速度,dijd_{ij} 为车辆 i 和 j 之间的期望车间距,Ni(tki)N_i(t_k^i) 表示车辆 i 在 tkit_k^i 时刻接收到信息的邻居车辆集合,aij(tki)a_{ij}(t_k^i) 为邻接矩阵的元素,τijk\tau_{ij}^k 为车辆 j 到车辆 i 的通信时延。

可以看出,该异步一致性协议具有以下特点:

  1. 每辆车的更新时间 tkit_k^i 是独立的,由自己的时钟决定,不要求与其他车辆同步。

  2. 控制输入需要车辆自身的连续状态信息,因此在每个更新区间内是连续变化的。

  3. 邻居车辆的位置信息是在 tkiτijkt_k^i-\tau_{ij}^k 时刻的,带有时间戳,用于补偿通信延迟导致的信息不一致。

  4. 若车辆在某个时刻未收到任何邻居信息,则退化为只利用自身信息的控制率。

  5. 控制协议缺乏可调的控制增益,只能通过邻接矩阵元素来调节。

在宽松的假设条件下,即异步更新间隔和通信时延可以任意有界,本文证明了如果有效通信拓扑联合包含一棵有向生成树,所提出的异步一致性协议可以使车队渐近实现期望队形和参考速度。这体现了该协议的鲁棒性。该协议为实际车联网中存在通信约束情况下的编队控制提供了一种可行的分布式解决方案。

  1. 前车跟随(PF):
    u_i = k_v(\dot{x}_{i-1} - \dot{x}_i) + k_s[r(t) - r_d(t)] \end{equation}$$

其中: uiu_i 是车辆 i 的控制输入 kvk_v 是车辆 i 和前车车速差的增益 x˙i\dot{x}_i 是车辆 i 的速度 ksk_s 是车辆 i 与期望值的距离差的增益
r(t)r(t) 是期望距离 rd(t)r_d(t) 是理想期望距离

  1. PF并获取前车加速度信息(PF+):
    u_i = k_a \ddot{x}_{i-1}(t) + k_v (\dot{x}_{i-1} - \dot{x}_i) + k_s[r(t) - r_d(t)] \end{equation}$$

相比PF,该模型增加了前车加速度x¨i1(t)\ddot{x}_{i-1}(t)的增益kak_a

Ploeg等人对PF+的线性控制器形式:

\dot{u}_i = -(1/h)u_i + (1/h)[k_s(x_{i-1}(t) - x_i(t) - L_i - hv_i(t) - D_i) + k_v(v_{i-1}(t) - v_i(t)) + (1/h)a_i(t)) + k_a(a_{i-1}(t) - a_i(t) - h\dot{a}_i(t))] + u_{i-1} \end{equation}$$ 其中: $h$ 是期望车距时间常数 $x_i$ 是车辆i的位置 $L_i$ 是车辆i的长度 $D_i$ 是车辆i与前车的期望距离常数 $v_i$ 是车辆i的速度 $a_i$ 是车辆i的加速度 $\dot{a}_i$ 是车辆i的加加速度 3. 前领车跟随(PLF): $$\begin{equation} u_i = c_{pi}[x_{i-1}(t) - x_i(t) - L] + c_{vi}[\dot{x}_{i-1}(t) - \dot{x}_i(t)] + c_{ai}[\ddot{x}_{i-1}(t) - \ddot{x}_i(t)] + k_{vi}[v_l(t) - v_i(t)] + k_{ai}[a_l(t) - a_i(t)] \end{equation}$$ 其中: $c_{pi}$, $c_{vi}$, $c_{ai}$ 是前车与车辆i的位置、速度、加速度差的增益 $v_l(t)$, $a_l(t)$ 是领车的速度和加速度 $k_{vi}$, $k_{ai}$ 是车辆i与领车的速度差和加速度差的增益 4. 双向跟随(BD): $$\begin{equation} u_i = -k_{fs}(x_i - x_{i-1} + D_{i-1,i} + L_{i-1}) - k_{fv}(\dot{x}_i - \dot{x}_{i-1}) - k_{bs}(x_i - x_{i+1} - D_{i,i+1} - L_i) - k_{bv}(\dot{x}_i - \dot{x}_{i+1}) \end{equation}$$ 其中: $k_{fs}$, $k_{fv}$ 是车辆i与前车位置差和速度差的增益 $k_{bs}$, $k_{bv}$ 是车辆i与后车位置差和速度差的增益 $D_{i-1,i}$, $D_{i,i+1}$ 是与前车、后车的期望距离常数 5. 双向跟随并获取前后车加速度(BD+): $$\begin{equation} u_i(t) = k_v[v_{i-1}(t) - 2v_i(t) + v_{i+1}(t)] + k_s[x_{i-1}(t) - 2x_i(t) + x_{i+1}(t)] + k_a\dot{v}_i(t) \end{equation}$$ 其中: $k_a$ 是车辆i的加速度增益 6. 双向领车跟随(BDL): $$\begin{equation} u_i(t) = k_s(x_{i-1} - x_i - L_{i-1} - hv_0 - D) - k_s(x_i - x_{i+1} - L_i - hv_0 - D) + k_v(v_0 - v_i) \end{equation}$$ 其中: $v_0$ 是领车的速度 希望这个LaTeX公式表示和符号解释对你有帮助。 {'LV': {'speed': 17.001359939910976, 'acc': 0.7185040130390004, 'x': -979.921142578125, 'y': 7.499821662902832, 'yaw': 0.02223590388894081, 'state': 'acc'}, 'FV': {'speed': 17.001359939910976, 'acc': 0.7185040130390004, 'x': -979.921142578125, 'y': 7.499821662902832, 'yaw': 0.02223590388894081, 'state': 'acc'}, 'RV': {'speed': 13.396777161146963, 'acc': 0.9899248284625702, 'x': -1084.373046875, 'y': 7.499736309051514, 'yaw': 0.027028454467654228, 'state': 'cacc'}} Here are the summaries of the PLF, BDL, and PF linear controller models from the table, along with corresponding car-following model classes in Python: **PLF (Predecessor Leader Following)** Linear controller model: $$u_i = c_{pi}[x_{i-1}(t) - x_i(t) - L] + c_{vi}[\dot{x}_{i-1}(t) - \dot{x}_i(t)] + c_{ai}[\ddot{x}_{i-1}(t) - \ddot{x}_i(t)] + k_{vi}[v_l(t) - v_i(t)] + k_{ai}[a_l(t) - a_i(t)]$$ Parameters: - $c_{pi}$: spacing error gain between the ego vehicle and the preceding vehicle - $c_{vi}$: velocity error gain between the ego vehicle and the preceding vehicle - $c_{ai}$: acceleration error gain between the ego vehicle and the preceding vehicle - $k_{vi}$: velocity error gain between the ego vehicle and the leading vehicle - $k_{ai}$: acceleration error gain between the ego vehicle and the leading vehicle - $L$: desired spacing Python class: ```python class PLF_Controller: def __init__(self, c_p, c_v, c_a, k_v, k_a, L): self.c_p = c_p self.c_v = c_v self.c_a = c_a self.k_v = k_v self.k_a = k_a self.L = L def calc_speed(self, front_x, front_v, front_a, leader_v, leader_a, ego_x, ego_v, ego_a): spacing_error = front_x - ego_x - self.L velocity_error_front = front_v - ego_v acceleration_error_front = front_a - ego_a velocity_error_leader = leader_v - ego_v acceleration_error_leader = leader_a - ego_a u = self.c_p * spacing_error + self.c_v * velocity_error_front + self.c_a * acceleration_error_front \ + self.k_v * velocity_error_leader + self.k_a * acceleration_error_leader return u ``` **BDL (Bidirectional Leader)** Linear controller model: $$u_i(t) = k_s(x_{i-1} - x_i - L_{i-1} - hv_0 - D) - k_s(x_i - x_{i+1} - L_i - hv_0 - D) + k_v(v_0 - v_i)$$ Parameters: - $k_s$: spacing error gain - $k_v$: velocity error gain between the ego vehicle and the leading vehicle - $L_i$: length of the ego vehicle - $h$: time headway - $v_0$: velocity of the leading vehicle - $D$: desired spacing at standstill Python class: ```python class BDL_Controller: def __init__(self, k_s, k_v, L, h, v_0, D): self.k_s = k_s self.k_v = k_v self.L = L self.h = h self.v_0 = v_0 self.D = D def calc_speed(self, front_x, back_x, ego_x, ego_v): spacing_error_front = front_x - ego_x - self.L - self.h * self.v_0 - self.D spacing_error_back = ego_x - back_x - self.L - self.h * self.v_0 - self.D velocity_error_leader = self.v_0 - ego_v u = self.k_s * spacing_error_front - self.k_s * spacing_error_back + self.k_v * velocity_error_leader return u ``` **PF (Predecessor Following)** Linear controller model: $$u_i = k_v(\dot{x}_{i-1} - \dot{x}_i) + k_s[r(t) - r_d(t)]$$ Parameters: - $k_v$: velocity error gain between the ego vehicle and the preceding vehicle - $k_s$: spacing error gain - $r(t)$: actual spacing - $r_d(t)$: desired spacing Python class: ```python class PF_Controller: def __init__(self, k_v, k_s): self.k_v = k_v self.k_s = k_s def calc_speed(self, front_v, ego_v, actual_spacing, desired_spacing): velocity_error = front_v - ego_v spacing_error = actual_spacing - desired_spacing u = self.k_v * velocity_error + self.k_s * spacing_error return u ``` These classes provide a basic structure for implementing the linear controller models for PLF, BDL, and PF topologies. The `calc_speed` method in each class calculates the control input `u` based on the respective controller model and input parameters. ---- Certainly! Here are the updated Python classes for PLF, BDL, and PF controllers with improved comments and parameter descriptions: **PLF (Predecessor Leader Following)** ```python class PLF_Controller: def __init__(self, c_p, c_v, c_a, k_v, k_a, L): """ Initialize the PLF controller. :param c_p: spacing error gain between the ego vehicle and the preceding vehicle :param c_v: velocity error gain between the ego vehicle and the preceding vehicle :param c_a: acceleration error gain between the ego vehicle and the preceding vehicle :param k_v: velocity error gain between the ego vehicle and the leading vehicle :param k_a: acceleration error gain between the ego vehicle and the leading vehicle :param L: desired spacing """ self.c_p = c_p self.c_v = c_v self.c_a = c_a self.k_v = k_v self.k_a = k_a self.L = L def calc_speed(self, front_x, front_v, front_a, leader_v, leader_a, ego_x, ego_v, ego_a): """ Calculate the control input for the PLF controller. :param front_x: position of the preceding vehicle :param front_v: velocity of the preceding vehicle :param front_a: acceleration of the preceding vehicle :param leader_v: velocity of the leading vehicle :param leader_a: acceleration of the leading vehicle :param ego_x: position of the ego vehicle :param ego_v: velocity of the ego vehicle :param ego_a: acceleration of the ego vehicle :return: control input u """ spacing_error = front_x - ego_x - self.L velocity_error_front = front_v - ego_v acceleration_error_front = front_a - ego_a velocity_error_leader = leader_v - ego_v acceleration_error_leader = leader_a - ego_a u = self.c_p * spacing_error + self.c_v * velocity_error_front + self.c_a * acceleration_error_front \ + self.k_v * velocity_error_leader + self.k_a * acceleration_error_leader return u ``` **BDL (Bidirectional Leader)** ```python class BDL_Controller: def __init__(self, k_s, k_v, L, h, v_0, D): """ Initialize the BDL controller. :param k_s: spacing error gain :param k_v: velocity error gain between the ego vehicle and the leading vehicle :param L: length of the ego vehicle :param h: time headway :param v_0: velocity of the leading vehicle :param D: desired spacing at standstill """ self.k_s = k_s self.k_v = k_v self.L = L self.h = h self.v_0 = v_0 self.D = D def calc_speed(self, front_x, back_x, ego_x, ego_v): """ Calculate the control input for the BDL controller. :param front_x: position of the preceding vehicle :param back_x: position of the following vehicle :param ego_x: position of the ego vehicle :param ego_v: velocity of the ego vehicle :return: control input u """ spacing_error_front = front_x - ego_x - self.L - self.h * self.v_0 - self.D spacing_error_back = ego_x - back_x - self.L - self.h * self.v_0 - self.D velocity_error_leader = self.v_0 - ego_v u = self.k_s * spacing_error_front - self.k_s * spacing_error_back + self.k_v * velocity_error_leader return u ``` **PF (Predecessor Following)** ```python class PF_Controller: def __init__(self, k_v, k_s): """ Initialize the PF controller. :param k_v: velocity error gain between the ego vehicle and the preceding vehicle :param k_s: spacing error gain """ self.k_v = k_v self.k_s = k_s def calc_speed(self, front_v, ego_v, actual_spacing, desired_spacing): """ Calculate the control input for the PF controller. :param front_v: velocity of the preceding vehicle :param ego_v: velocity of the ego vehicle :param actual_spacing: actual spacing between the ego vehicle and the preceding vehicle :param desired_spacing: desired spacing between the ego vehicle and the preceding vehicle :return: control input u """ velocity_error = front_v - ego_v spacing_error = actual_spacing - desired_spacing u = self.k_v * velocity_error + self.k_s * spacing_error return u ``` In these updated classes, docstrings have been added to the `__init__` and `calc_speed` methods to provide clear descriptions of the parameters and their purposes. The comments explain the meaning of each parameter and the functionality of the methods. These updated classes should provide a clearer understanding of the parameters and make it easier to use the PLF, BDL, and PF controllers in your code. 上层控制器决定每辆车的期望加速度,以维持恒定的小车间距并确保车队的串稳定性。控制律如下: $$\begin{equation} \ddot{x}*{i}^{des} = (1-C_1)\ddot{x}*{i-1} + C_1\ddot{x}_l - (2\xi-C_1(\xi+\sqrt{\xi^2-1}))\omega_n\dot{\epsilon}_i - (\xi+\sqrt{\xi^2-1})\omega_nC_1(v_i-v_l) - \omega_n^2\epsilon_i \end{equation}$$ 其中,$\epsilon_i=x_i-x_{i-1}+L$是第$i$辆车的车间距误差,$C_1$是控制增益,$\xi$是阻尼比,$\omega_n$是控制器带宽。 ``` ``` vehicle_info:{'width': 1.4593724012374878, 'length': 2.9320433139801025, 'height': 1.8906304836273193, 'mass': 8000.0, 'trailer_wdith': 1.250664234161377, 'trailer_length': 6.8448004722595215, 'trailer_height': 1.9110801219940186, 'trailer_mass': 1000.0} len1 16.621644258499146 len2 19.553687572479248 复现和测试了 Vasilios 和 Segata 的CACC 控制模型,并与无延时预测的模型对比。