Utopi
a

A. Simulation Platform and Cooperative Driving Frameworks

In the field of cooperative driving research, simulation platforms and frameworks play a crucial role. Researchers utilize these tools to develop and test collaborative driving algorithms, assessing their performance and stability. In this section, we will review current popular simulation platforms in academic field, such as SUMO, MATLAB/Simulink, and CARLA, as well as cooperative driving frameworks built upon them.

SUMO is an open-source, highly portable, microscopic, and continuous traffic simulation package designed to handle large networks.

Segata et al. [8]develop Plexe based on SUMO and OMNeT++ for studying cooperative driving systems with a modular approach. This simulation toolkit is very popular in the study of platooning control, vehicle-to-vehicle (V2V) and vehicle-to-infrastructure communication (V2X).

Karl et al. [9] proposed MOSAIC, a multi-domain simulation framework integrated with software like SUMO, OMNeT++, and ns-3, for deploying and testing advanced traffic control strategies. It facilitates the coupling of leading simulators across traffic, application, and communication domains.

However, cooperative driving frameworks based on SUMO primarily focus on macroscopic traffic flow and mobility patterns rather than detailed physical interactions. This limitation restricts the ability to simulate cooperative driving scenarios that require high-fidelity vehicle dynamics.

MATLAB is a widely used numerical computing environment and its Simulink platform supports multi-domain simulation and model-based design, which is essential for the development of vehicle control systems. Leveraging its rich set of libraries, researches can simulate the dynamic behavior of vehicles with high precision.

Palmieri et al. [10] introduced a co-simulation approach using MATLAB Simulink to create high-fidelity digital twin models of distributed multi-agent cyber-physical systems (CPSs), using the platoon system as a case study. Their method employs the FMI co-simulation standard to handle CPS complexity by breaking them into interconnected components for specific domains.

Chen et al. [11] utilized a co-simulation approach combining PreScan, Matlab, and Vissim to construct a platform for evaluating the cooperative driving behavior of autonomous vehicles. Their methodology focuses on the interaction between autonomous and human-driven vehicles, offering valuable insights into the safety performance of cooperative driving systems.

Despite MATLAB/Simulink offers the most comprehensive vehicle dynamics simulation ecosystem, the proprietary nature of MATLAB/Simulink may hinder wider community collaboration as most of the code based on it is not publicly available.

Carla is an open-source autonomous driving simulation platform that offers a flexible and scalable environment for testing and developing the autonomous vehicles. It features a high-fidelity rendering game engine and supports various sensors and controllers.

Xu et al. [12] introduced OpenCDA, a widely used open-source cooperative driving framework based on Carla. This comprehensive framework provides modules for perception, localization, and vehicle control, abstracting various elements to facilitate cooperative driving in different scenarios.

Carletti et al. [13] enhanced OpenCDA by integrating advanced communication models from ns-3, thereby providing researchers with a comprehensive tool to evaluate the impact of vehicular cooperative perception under various communication technologies.

Liu et al. [14] introduced an optimization-based approach for cooperative driving in urban environments. They integrated Artificial Potential Fields (APF) into a Model Predictive Control (MPC) scheme to represent traffic rules, effectively handling cooperative driving scenarios in CARLA simulations.

CARLA strikes a balance between physical fidelity and computational efficiency. Its open-source nature has led to increasing popularity in academia, and its flexible and rich interface design makes it an excellent choice for establishing cooperative driving simulation platforms.

B. Asynchronous problems in cooperative driving

Xu et al. [15] noted that traditional synchronization updates, such as global blocking synchronization, are inefficient due to processes waiting at the barrier. Consequently, high synchronization overhead has consistently been a significant performance issue in large-scale parallel agent-based traffic simulations.

Bin et al. [16] investigated synchronous and asynchronous update methods in traffic simulation. They suggest that asynchronous updates may introduce inconsistency in the simulation results since identical vehicles tend to perceive different traffic scenarios on the same simulation step. In contrast, synchronous updates ensure all vehicles perceive the same traffic scenario.

Zhan et al. [17] highlight that in real-world scenarios, each agent updates its dynamics at distinct time intervals defined by its own clock, leading to delay and inconsistency between the ground truth and measurements. They explored the problem of asynchronous platoon cooperative control under these conditions, taking into account intermittent and delayed information transmission. The researchers proposed an asynchronous consensus-based protocol for first-order multi-agent systems with switching topologies, accommodating large but bounded update intervals and communication delays.

Hu et al. [18] further classified the asynchronous problem into the mismatched and matched disturbances and estimated it through a finite-time disturbance observer.

Vehicle Agent is a crucial component in Intelligent Transportation Systems and a vital unit in cooperative driving. In this chapter, we will explain in detail the implementation of the Vehicle Agent to facilitate future researchers in developing advanced cooperative driving algorithms using our basic Vehicle Agent model.

Due to the high computational performance requirements of the perception workflow, we chose to implement autonomous driving vehicles as control-in-the-loop rather than perception-in-the-loop. This means that information related to obstacles and maps is directly obtained from the simulator. The Autonomous Vehicle class in the ACDCarla framework comprises several components, such as the communication manager, sensor manager, global router etc. These components become sub-objects in the agent class at initialization, and the control logic is concentrated in the planner's control loop to complete route planning, perception, decision-making, and control functions.

The Vehicle Agent generates an A* global router planner that builds a topology and a graph representation of the road network using the waypoints and road segments provided by the CARLA HD map. It then employs the A* search algorithm to find the optimal path between an origin and a destination location within the graph.

The primary autonomous driving control logic resides in the Frenet local planner's control loop. During each control loop iteration, the planner first updates the ego vehicle state, processes obstacle information, and checks the local waypoint buffer.

The local planner calculates the curvature cc of the waypoint buffer using three consecutive points: p1p_1, p2p_2, and p3p_3:

c=1p1p2p1p2p2p3p2p3c = 1 - \frac{\overrightarrow{p_1 p_2}}{|\overrightarrow{p_1 p_2}|} \cdot \frac{\overrightarrow{p_2 p_3}}{|\overrightarrow{p_2 p_3}|}

The target speed vtv_t is then determined based on the total curvature CC of the waypoint buffer, calculated as C=i=1n1ciC = \sum_{i=1}^{n-1} c_i, using the formula:

vt={max(10,vme6C)if C>0.0001vmotherwisev_t = \begin{cases} \max(10, v_m \cdot e^{-6C}) & \text{if } C > 0.0001 \\ v_m & \text{otherwise} \end{cases}

where vmv_m is the maximum speed and nn is the number of points in the buffer. This allows the vehicle to slow down appropriately when approaching turns or curves, ensuring smooth and safe navigation.

The system incorporates a collision avoidance check on the future waypoints buffer, which is based on the occupancy grid and considers both the current positions of obstacles and their predicted positions 3 seconds into the future. The prediction baseline method employs a simple physical dynamics model for forecasting. If the obstacles do not occupy the grid cells corresponding to the future waypoints, the system directly applies the cruising algorithm to reach the target speed, which by default utilizes the Intelligent Driver Model (IDM) algorithm, as shown in the following equation:

{a=max(bmax,amax[1(vv0)δ(ss)2])s=max(s0+vT+vΔv2amaxb,s0)\lbrace{ \begin{aligned} a &= \max\left(-b_{\max}, a_{\max}\left[1 - \left(\frac{v}{v_0}\right)^{\delta} - \left(\frac{s^*}{s}\right)^2\right]\right) \\ s^* &= \max\left(s_0 + vT + \frac{v\Delta v}{2\sqrt{a_{\max}b}}, s_0\right) \end{aligned} }

VariableDescription
aaAcceleration of the ego vehicle
bmaxb_{\max}Maximum brake deceleration
amaxa_{\max}Maximum acceleration
vvCurrent speed of the ego vehicle
v0v_0Speed limit or desired speed
δ\deltaAcceleration exponent
s0s_0Minimum safe distance
TTHuman reaction time
Δv\Delta vSpeed difference between the ego vehicle and the front vehicle (ego_v - front_v)
bbNormal deceleration
ssCurrent distance between the ego vehicle and the front vehicle

This approach ensures that the collision avoidance mechanism takes into account not only the real-time positions of obstacles but also their anticipated trajectories in the near future.

we utilize B-spline curves to generate smooth and feasible trajectories for the ego vehicle. The input data points, representing the waypoints of the ego vehicle's future path, are first preprocessed and then fitted using a B-spline curve approximation technique. The resulting B-spline curve is defined as a linear combination of B-spline basis functions and control points, as shown in Equation (1):

\begin{equation} \textbf{C}(u) = \sum_{i=0}^{n} \textbf{P}i N{i,p}(u) \end{equation}

where C(u)\textbf{C}(u) is the point on the B-spline curve at parameter value uu, Pi\textbf{P}i are the control points, Ni,p(u)N{i,p}(u) are the B-spline basis functions of degree pp, and nn is the number of control points.

Design of the platooning scenario and platoon vehicle agent

vi(t)=f(vi1(t),ai1(t),di(t),vi+1(t),ai+1(t),vi(t),ai(t),τi1,τi+1,vi1target(t))v_{i}(t) = f(v_{i-1}(t), a_{i-1}(t), d_{i}(t), v_{i+1}(t), a_{i+1}(t), v_{i}(t), a_{i}(t), \tau_{i-1}, \tau_{i+1}, v_{i-1}^{target}(t))

where vi(t)v_{i}(t) is the speed of the ii-th vehicle at time tt, vi1(t)v_{i-1}(t) is the speed of the leader vehicle at time tt, ai1(t)a_{i-1}(t) is the acceleration of the leader vehicle at time tt, di(t)d_{i}(t) is the distance between the ii-th vehicle and its preceding vehicle at time tt, vi+1(t)v_{i+1}(t) is the speed of the front vehicle at time tt, ai+1(t)a_{i+1}(t) is the acceleration of the front vehicle at time tt, vi(t)v_{i}(t) is the speed of the ego vehicle at time tt, ai(t)a_{i}(t) is the acceleration of the ego vehicle at time tt, τi1\tau_{i-1} and τi+1\tau_{i+1} are the communication delays from the leader and front vehicles, respectively, which can be used as parameters depending on the specific implementation, vi1target(t)v_{i-1}^{target}(t) is the target speed of the leader vehicle at time tt.

The longitudinal control of the vehicle is performed using a PID controller. The control output out(t)out(t), representing the throttle or brake command, is calculated based on the following equation:

out(t)=KPe(t)+KI0te(τ)dτ+KDde(t)dtout(t) = K_P e(t) + K_I \int_{0}^{t} e(\tau) d\tau + K_D \frac{de(t)}{dt}

where e(t)e(t) is the error between the target speed and the current speed at time tt, given by:

e(t)=vtarget(t)vcurrent(t)e(t) = v_{target}(t) - v_{current}(t)

Here, vtarget(t)v_{target}(t) is the target speed in m/s at time tt, and vcurrent(t)v_{current}(t) is the current speed of the vehicle in m/s at time tt. The proportional gain KPK_P is set to 1.0, the integral gain KIK_I is set to 0.05, the derivative gain KDK_D is set to 0, and the time step dtdt is set to 0.03 seconds.

The integral term 0te(τ)dτ\int_{0}^{t} e(\tau) d\tau is approximated using the sum of errors over a buffer of size 10:

0te(τ)dτi=09e(tidt)dt\int_{0}^{t} e(\tau) d\tau \approx \sum_{i=0}^{9} e(t - i \cdot dt) \cdot dt

The derivative term de(t)dt\frac{de(t)}{dt} is approximated using the difference between the current error and the previous error:

de(t)dte(t)e(tdt)dt\frac{de(t)}{dt} \approx \frac{e(t) - e(t - dt)}{dt}

The control output u(t)u(t) is then clipped to the range [-1, 1] to ensure that the throttle and brake commands remain within valid ranges. If u(t)0u(t) \geq 0, it represents the throttle command, and if u(t)<0u(t) < 0, the absolute value represents the brake command.

I apologize for the oversight. Let me clarify the meaning of τ\tau in the equations.

The longitudinal control of the vehicle is performed using a PID controller. The control output u(t)u(t), representing the throttle or brake command, is calculated based on the following equation:

u(t)=KPe(t)+KI0te(τ)dτ+KDde(t)dtu(t) = K_P e(t) + K_I \int_{0}^{t} e(\tau) d\tau + K_D \frac{de(t)}{dt}

where e(t)e(t) is the error between the target speed and the current speed at time tt, given by:

e(t)=vtarget(t)vcurrent(t)e(t) = v_{target}(t) - v_{current}(t)

Here, vtarget(t)v_{target}(t) is the target speed in km/h at time tt, and vcurrent(t)v_{current}(t) is the current speed of the vehicle in km/h at time tt. The proportional gain KPK_P is set to 1.0, the integral gain KIK_I is set to 0.05, the derivative gain KDK_D is set to 0, and the time step dtdt is set to 0.3 seconds.

In the integral term 0te(τ)dτ\int_{0}^{t} e(\tau) d\tau, τ\tau is a variable representing time in the integration. It is used to indicate that the error is integrated over the time interval from 0 to the current time tt. The integral term is approximated using the sum of errors over a buffer of size 10:

0te(τ)dτi=09e(tidt)dt\int_{0}^{t} e(\tau) d\tau \approx \sum_{i=0}^{9} e(t - i \cdot dt) \cdot dt

The derivative term de(t)dt\frac{de(t)}{dt} is approximated using the difference between the current error and the previous error:

de(t)dte(t)e(tdt)dt\frac{de(t)}{dt} \approx \frac{e(t) - e(t - dt)}{dt}

The control output u(t)u(t) is then clipped to the range [-1, 1] to ensure that the throttle and brake commands remain within valid ranges. If u(t)0u(t) \geq 0, it represents the throttle command, and if u(t)<0u(t) < 0, the absolute value represents the brake command.

The longitudinal PID controller aims to minimize the error between the target speed and the current speed of the vehicle by adjusting the throttle and brake commands based on the proportional, integral, and derivative terms of the error. The specific gains (KPK_P, KIK_I, KDK_D) and time step (dtdt) were chosen to achieve a satisfactory control performance.

(1) PATH CACC controller

The ACC and CACC car-following models of Milanés and Shladover were used as the basic simulation models (9). The responses of ACC followers were modeled as a second-order transfer function and are described by

ai,k=k1ei,k+k2(νi1,k1νi,k1)a_{i,k}=k_{1}\cdot e_{i,k}+k_{2}\cdot(\nu_{i-1,k-1}-\nu_{i,k-1})

where ei,ke_{i,k} is the gap error of vehicle ii at time step kk. Equation 3 shows that vehicle acceleration depends on a gap error and a speed difference with the preceding vehicle, where their feedback gain k1k_{1} and k2k_{2} is 0.23 s2^{-2} and 0.07 s1^{-1}​, respectively.

The classic CACC [50] implementation by California Berkeley PATH Laboratory is a widely used method. The PATH CACC control law is designed using a proportional-derivative (PD) controller and is given by:

{νi,k=νi,k1+kpei,k1+kde˙i,k1ei,k=xi1,k1xi,k1d0tdesvi,k1\begin{cases} \nu_{i,k}=\nu_{i,k-1}+k_{p}\cdot e_{i,k-1}+k_{d}\cdot\dot{e}_{i,k-1}\\ e_{i,k}=x_{i-1,k-1}-x_{i,k-1}-d_{0}-t_{\mathrm{des}}\cdot v_{i,k-1} \end{cases}

where νi,k\nu_{i,k} is the control input for vehicle ii at time step kk, ei,ke_{i,k} is the gap error, and e˙i,k\dot{e}_{i,k} is its derivative The parameters used in the control law are described in the following table:

ParameterDefault ValueDescription
kpk_p0.45Proportional gain for gap error
kdk_d0.25Derivative gain for gap rate error
d0d_02 mStandstill distance
tdest_{\mathrm{des}}0.5 sDesired time-gap

The control law aims to regulate the gap between vehicle ii and its preceding vehicle i1i-1 by adjusting the control input based on the gap error and gap rate error. The proportional and derivative gains, kpk_p and kdk_d, determine the response of the controller to the errors. The standstill distance, d0d_0, and the desired time-gap, tdest_{\mathrm{des}}, are used to calculate the desired gap.

Apologies for the confusion. Let me revise the academic paper section with the suggested changes:

CACC Algorithm

class Adaptive_CACCController: def __init__(self, headway_time=0.5, speed_control_gain=0.25, gap_control_gain_gap=-0.45, gap_control_gain_gap_dot=0.125, collision_avoidance_gain_gap=0.45, collision_avoidance_gain_gap_dot=0.05, emergency_threshold=2.0, headway_time_acc=1.0, speed_control_min_gap=0.06, feedforward_gain=1.0, observer_gain=0.1, sliding_mode_gain=0.1, spacing_err_queue_size=10, speed_err_queue_size=10): self.headway_time = headway_time self.speed_control_gain = speed_control_gain self.gap_control_gain_gap = gap_control_gain_gap self.gap_control_gain_gap_dot = gap_control_gain_gap_dot self.collision_avoidance_gain_gap = collision_avoidance_gain_gap self.collision_avoidance_gain_gap_dot = collision_avoidance_gain_gap_dot self.emergency_threshold = emergency_threshold self.headway_time_acc = headway_time_acc self.control_min_gap = speed_control_min_gap self.feedforward_gain = feedforward_gain self.observer_gain = observer_gain self.sliding_mode_gain = sliding_mode_gain self.spacing_err_queue = deque(maxlen=spacing_err_queue_size) self.speed_err_queue = deque(maxlen=speed_err_queue_size) self.ti = 0 def calc_speed(self, leader_v, leader_a, front_dis, front_v, front_a, ego_v, ego_a, leader_delay=0, front_delay=0, leader_tv=0, is_radar = False): # Feedforward control with nonlinear acceleration profile feedforward_acc = self.feedforward_gain * (leader_tv - ego_v) feedforward_acc *= math.tanh(leader_a * leader_delay) * (leader_tv - leader_v) leading_tv_err = leader_tv -ego_v spacing_err = front_dis - self.headway_time * ego_v - self.emergency_threshold speed_err = front_v - ego_v # Error observer with queue for spacing and speed errors self.spacing_err_queue.append(spacing_err) self.speed_err_queue.append(speed_err) observed_spacing_err = sum(self.spacing_err_queue) / len(self.spacing_err_queue) observed_speed_err = sum(self.speed_err_queue) / len(self.speed_err_queue) # Sliding mode control with adaptive gain adjustment sliding_mode_gain_v = math.tanh(abs(observed_speed_err) / self.control_min_gap) * self.sliding_mode_gain sliding_mode_gain_gap = math.tanh(abs(observed_spacing_err) / self.control_min_gap) * self.sliding_mode_gain # Dynamic gain adjustment gap_control_gain_gap = self.gap_control_gain_gap * sliding_mode_gain_gap gap_control_gain_gap_dot = self.gap_control_gain_gap_dot * sliding_mode_gain_gap speed_control_gain = self.speed_control_gain if abs(observed_spacing_err) > self.control_min_gap: gap_control_gain_gap *= (1 + sliding_mode_gain_v) gap_control_gain_gap_dot *= (1 + sliding_mode_gain_gap) else: speed_control_gain *= (sliding_mode_gain_gap) # Safety constraints (remains the same as before) if front_dis < self.emergency_threshold: feedforward_acc = -5.0 speed_control_gain = 0.0 gap_control_gain_gap_dot = 0.0 output = (feedforward_acc + speed_control_gain * leading_v_err - gap_control_gain_gap * observed_spacing_err + gap_control_gain_gap_dot * observed_speed_err)

The lower-level control of the vehicle is handled by a PID controller, which receives the target waypoint and target speed from the planner. The PID controller consists of two sub-controllers: lateral and longitudinal.

The longitudinal PID controller calculates the acceleration output based on the following equation:

a=KPe+KI0te(τ)dτ+KDdedta = K_P e + K_I \int_0^t e(\tau) d\tau + K_D \frac{de}{dt}

where aa is the acceleration output, ee is the error between the target speed vtv_t and the current speed vcv_c, i.e., e=vtvce = v_t - v_c, KPK_P is the proportional gain, KIK_I is the integral gain, KDK_D is the derivative gain, and dtdt is the time step. The integral term 0te(τ)dτ\int_0^t e(\tau) d\tau represents the accumulated error over time, which is calculated using the following approximation:

0te(τ)dτi=0ne(i)dt\int_0^t e(\tau) d\tau \approx \sum_{i=0}^{n} e(i) \cdot dt

where nn is the number of time steps elapsed since the start of the control process, and e(i)e(i) is the error at time step ii. This approximation is known as the trapezoidal rule for numerical integration.

The derivative term dedt\frac{de}{dt} represents the rate of change of the error, which is calculated using the finite difference approximation:

dedte(t)e(tdt)dt\frac{de}{dt} \approx \frac{e(t) - e(t - dt)}{dt}

where e(t)e(t) is the current error and e(tdt)e(t - dt)​ is the error at the previous time step.

To translate the given Python code into mathematical notation rendered in LaTeX, we first need to understand the variables and the operations being performed. The code snippet appears to manage vehicle control in a simulation, using acceleration and steering values to adjust throttle and brake levels.

Here are the necessary variables and their purpose:

  • (a): acceleration (computed by
    self._lon_controller.run_step(target_speed)
    ).
  • (s): current steering angle (computed by
    self._lat_controller.run_step(waypoint)
    , though it is not directly used in the throttle/brake logic).
  • (throttle): the throttle value to be applied to control the vehicle's acceleration.
  • (brake): the brake value to be applied to control the vehicle's deceleration.
  • (max_{throt}): the maximum throttle limit.
  • (max_{brake}): the maximum brake limit.

Given the code, we can define the control logic for throttle and brake as follows:

  1. Throttle and Brake Control:
\min(a, max_{throttle}) & \text{if } a \geq 0 \\ 0 & \text{otherwise} \end{cases}$$ $$brake = \begin{cases} 0 & \text{if } a \geq 0 \\ \min(|a|, max_{brake}) & \text{otherwise} \end{cases}$$ In this model: - When the acceleration $a$ is greater than or equal to 0, the throttle is applied based on the minimum of the acceleration or `max_throt`. The brake is set to 0. - If the acceleration $a$ is less than 0, indicating a need to decelerate, the throttle is set to 0. The brake value is determined by the minimum of the absolute value of the acceleration or `max_brake`. These equations succinctly capture the logic implemented in the Python code, translating it into a mathematical model that could be understood in a broader context such as vehicle dynamics or control systems analysis. The lateral PID controller calculates the steering angle output using the following equation: $$\delta = K_P \theta + K_I \int_0^t \theta(\tau) d\tau + K_D \frac{d\theta}{dt}$$ where $\delta$ is the steering angle output, $\theta$ is the error between the vehicle's heading $\psi$ and the target waypoint's direction $\psi_t$, i.e., $\theta = \psi_t - \psi$, $K_P$ is the proportional gain, $K_I$ is the integral gain, $K_D$ is the derivative gain, and $dt$ is the time step. The accumulated heading error over time $\int_0^t \theta(\tau) d\tau$ and the rate of change of the heading error $\frac{d\theta}{dt}$ are calculated using the same approximations as in the longitudinal controller. The variables and their default values for the PID controllers are summarized in the following table: | Variable | Longitudinal Default | Lateral Default | | -------- | -------------------- | --------------- | | $K_P$ | 1.0 | 1.45 | | $K_I$ | 0.05 | 0.05 | | $K_D$ | 0 | 0.2 | | $dt$ | 0.03 | 0.1 | Additional parameters used by the PID controller include: - $offset$: lateral offset from the center line (default: 0) - $max\_throttle$: maximum throttle value (default: 0.55) - $max\_brake$: maximum brake value (default: 0.9) - $max\_steering$: maximum steering angle (default: 0.5) The PID controller takes the target waypoint and target speed as inputs, calculates the appropriate throttle, brake, and steering angle based on the current vehicle state and the PID equations, and outputs the vehicle control commands to drive the vehicle towards the target waypoint at the desired speed. The calculated acceleration is converted to throttle and brake commands, while the steering angle is directly applied to the vehicle's steering control. The PID controller ensures smooth and stable vehicle control by continuously adjusting the control commands based on the observed errors, their accumulated values, and their rates of change. In this academic paper, we introduce an advanced cooperative adaptive cruise control (CACC) controller for platoon management. The controller aims to maintain a safe and efficient spacing between vehicles while considering various factors such as speed control, gap control, collision avoidance, and emergency situations. The mathematical formulation of the controller is as follows: $$a_{\text{output}} = a_{\text{feedforward}} + K_v (v_l - v_e) - K_s \hat{s} + K_{\dot{s}} \hat{\dot{s}}$$ where: | Variable | Description | | ------------------------ | ---------------------------------- | | $a_{\text{output}}$ | Output acceleration command | | $a_{\text{feedforward}}$ | Feedforward acceleration term | | $K_v$ | Speed control gain | | $v_l$ | Leader vehicle's target velocity | | $v_e$ | Ego vehicle's velocity | | $K_s$ | Gap control gain for spacing error | | $\hat{s}$ | Estimated spacing error | | $K_{\dot{s}}$ | Gap control gain for speed error | | $\hat{\dot{s}}$ | Estimated speed error | The `Advanced_CACCController` class implements an advanced cooperative adaptive cruise control system, which incorporates multiple control strategies for efficient platoon management. This includes feedforward control, Kalman filtering for state estimation, and sliding mode control for dynamic adaptation to varying conditions. ### Mathematical Model The feedforward control term is designed to anticipate the required acceleration based on the leader's behavior and the ego vehicle's current state:

a_{ff} = \kappa \cdot (v_{t} - v) \cdot \tanh(a_l \cdot \tau_l) \cdot (v_{t} - v_l),

where $\kappa$ represents the feedforward gain, $v_t$ is the target velocity of the leader, $v$ is the velocity of the ego vehicle, $a_l$ is the leader's acceleration, and $\tau_l$ is the leader's delay. This term adjusts the ego vehicle's acceleration to smoothly align with the leader's speed. For error estimation and correction, a Kalman filter is applied to both spacing and speed errors. The Kalman filter equations for the spacing error are:

\hat{s}^{(k)} = \hat{s}^{(k-1)} + K_s \cdot (s - \hat{s}^{(k-1)}),

\sigma_s^{(k)} = (1 - K_s) \cdot \sigma_s^{(k-1)} + \eta,

where $K_s$ is the Kalman gain for spacing error, $s$ is the observed spacing error, and $\eta$ represents the process noise. Similarly, the Kalman filter updates for speed error are:

\hat{v}^{(k)} = \hat{v}^{(k-1)} + K_v \cdot (v_e - \hat{v}^{(k-1)}),

\sigma_v^{(k)} = (1 - K_v) \cdot \sigma_v^{(k-1)} + \eta,

with $K_v$ as the Kalman gain for speed error, and $v_e$ representing the observed speed error. Sliding mode control is utilized to dynamically adjust control gains based on the estimated errors, enhancing the robustness:

g_{s} = g_{s0} \cdot \tanh\left(\frac{|\hat{s}|}{d_{min}}\right) \cdot g_m,

g_{v} = g_{v0} \cdot \tanh\left(\frac{|\hat{v}|}{d_{min}}\right) \cdot g_m,

where $g_{s0}$ and $g_{v0}$ are the static gains for spacing and speed control, respectively, and $d_{min}$ is the minimum control gap. ### Variables The following table lists the key variables used in the controller, along with their default values and descriptions: | Variable | Default Value | Description | | ------------- | ------------- | ------------------------------------------------------- | | $\tau_h$ | 0.5 | Desired headway time | | $\kappa$ | 0.25 | Feedforward control gain | | $g_{s0}$ | -0.45 | Static gain for spacing control | | $g_{v0}$ | 0.125 | Static gain for derivative of spacing control | | $g_{c_s}$ | 0.45 | Gain for collision avoidance based on spacing | | $g_{c_v}$ | 0.05 | Gain for collision avoidance based on change in spacing | | $\tau_{th}$ | 2.0 | Emergency threshold for collision avoidance | | $\tau_{acc}$ | 1.0 | Headway time for adaptive cruise control | | $d_{min}$ | 0.06 | Minimum control gap | | $\kappa_{ff}$ | 1.0 | Feedforward gain | | $g_{o}$ | 0.1 | Observer gain | | $g_{m}$ | 0.1 | Sliding mode control gain | | $N_s$ | 10 | Queue size for spacing error history | | $N_v$ | 10 | Queue size for speed error history | | Controller | RMS Gap Error | RMS Accel | MVE | ASE | AVE | | --------------------------- | ------------- | --------- | -------- | -------- | -------- | | PATH CACC Asynchronous | 0.227938 | 0.639396 | 1.033243 | 8.636486 | 0.225531 | | PATH CACC Synchronous | 0.243944 | 0.757594 | 1.413421 | 8.562194 | 0.211045 | | Our controller Asynchronous | 0.085340 | 0.641174 | 0.888157 | 8.396531 | 0.222399 | | Our controller Ssynchronous | 0.128463 | 0.816342 | 1.350444 | 8.403351 | 0.255138 | | Controller | RMS Gap Error | Max Absolute Gap Error | RMS Acceleration | Max Absolute Jerk | | --------------------------- | ------------- | ---------------------- | ---------------- | ----------------- | | PATH CACC Asynchronous | 0.227938 | 0.723647 | 0.639396 | 1.506721 | | PATH CACC Synchronous | 0.243944 | 0.907988 | 0.757594 | 1.906283 | | Our controller Asynchronous | 0.085340 | 0.383069 | 0.641174 | 1.536818 | | Our controller Ssynchronous | 0.128463 | 0.566009 | 0.816342 | 2.046922 | 1. **RMS Gap Error**: This metric represents the Root Mean Square (RMS) error between the desired gap and the actual gap between vehicles. 2. **Max Absolute Gap Error**: This metric represents the maximum absolute difference between the desired gap and the actual gap between vehicles over the entire simulation. 3. **RMS Acceleration**: This metric represents the Root Mean Square (RMS) acceleration of the vehicle. The formula for RMS Acceleration is: $RMS Acceleration = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (a_i)^2}$ where $n$ is the number of samples and $a_i$ is the acceleration at sample $i$. 4. **Max Absolute Acceleration**: This metric represents the maximum absolute acceleration of the vehicle over the entire simulation. These metrics are commonly used to evaluate the performance of adaptive cruise control (ACC) and cooperative adaptive cruise control (CACC) systems. They provide insights into the system's ability to maintain desired gaps, ensure smooth acceleration and deceleration, and maintain passenger comfort by minimizing jerk. # Advanced Cooperative Adaptive Cruise Control (CACC) with Nonlinear Feedforward, Kalman Filter, and Sliding Mode Control ## Introduction This paper presents an advanced cooperative adaptive cruise control (CACC) algorithm that incorporates nonlinear feedforward control, Kalman filtering for error estimation, and sliding mode control for dynamic gain adjustment. The proposed controller aims to enhance the performance and robustness of vehicle platooning by considering the leader's behavior, estimating and correcting spacing and speed errors, and adapting control gains based on the estimated errors. Thank you for your feedback. I understand that the superscript and subscript notation may be too complex for the paper. I will simplify the notation to make it more readable and suitable for an academic paper. Here's the updated description: ## Controller Design The advanced CACC controller calculates the desired velocity of the ego vehicle based on the states of the leader and the preceding vehicle. The control law is given by:

v_i = v_0 + a_{ff} + g_v \cdot (v_l - v_i) + g_s \cdot \hat{s} + g_{s_d} \cdot \hat{s}_d,

where $v_i$ is the target velocity of the ego vehicle, $v_0$ is the current velocity, $a_{ff}$ is the feedforward acceleration term, $g_v$ is the speed control gain, $v_l$ is the velocity of the leader, $v_i$ is the velocity of the ego vehicle, $g_s$ is the spacing control gain, $\hat{s}$ is the estimated spacing error, $g_{s_d}$ is the spacing derivative control gain, and $\hat{s}_d$ is the estimated derivative of spacing error. The feedforward control term is designed to anticipate the required acceleration based on the leader behavior and the current state of ego vehicle :

a_{ff} = \kappa_{ff} \cdot (v_t - v_i) \cdot \tanh(a_l \cdot \tau_l) \cdot (v_t - v_l),

where $\kappa_{ff}$ represents the feedforward gain, $v_t$ is the target velocity of the leader, $v_i$ is the velocity of the ego vehicle, $a_l$ is the leader's acceleration, $\tau_l$ is the leader delay estimated from timestamp, and $v_l$ is the velocity of the leader. This term adjusts the acceleration of ego to smoothly align with the leader speed. For error estimation and correction, a Kalman filter is applied to both spacing and speed errors. The Kalman filter equations for the spacing error are:

\hat{s}{k} = \hat{s}{k-1} + K_s \cdot (s_k - \hat{s}_{k-1}),

\sigma_{s,k} = (1 - K_s) \cdot \sigma_{s,k-1} + \eta,

where $K_s$ is the Kalman gain for spacing error, $s_k$ is the observed spacing error at time step $k$, $\hat{s}_k$ is the estimated spacing error at time step $k$, $\sigma_{s,k}$ is the covariance of the spacing error estimate at time step $k$, and $\eta$ represents the process noise. Similarly, the Kalman filter updates for the derivative of spacing error are:

\hat{s}{d,k} = \hat{s}{d,k-1} + K_{s_d} \cdot (s_{d,k} - \hat{s}_{d,k-1}),

\sigma_{s_d,k} = (1 - K_{s_d}) \cdot \sigma_{s_d,k-1} + \eta,

with $K_{s_d}$ as the Kalman gain for the derivative of spacing error, $s_{d,k}$ representing the observed derivative of spacing error at time step $k$, $\hat{s}_{d,k}$ as the estimated derivative of spacing error at time step $k$, and $\sigma_{s_d,k}$ as the covariance of the derivative of spacing error estimate at time step $k$. Sliding mode control is utilized to dynamically adjust control gains based on the estimated errors

g_s = g_{s,0} \cdot \tanh\left(\frac{|\hat{s}|}{d_{min}}\right) \cdot g_m,

g_{s_d} = g_{s_d,0} \cdot \tanh\left(\frac{|\hat{s}d|}{d{min}}\right) \cdot g_m,

where $g_{s,0}$ and $g_{s_d,0}$ are the static gains for spacing and derivative of spacing control, respectively, $d_{min}$ is the minimum control gap, and $g_m$ is the sliding mode control gain. ## Variables and Parameters The following table lists the key variables and parameters used in the controller, along with their default values and descriptions: | Variable/Parameter | Default Value | Description | | ------------------ | ------------- | ----------------------------------------------------------- | | $\tau_h$ | 0.5 | Desired headway time | | $g_v$ | 0.25 | Speed control gain | | $g_{s}$ | 0.45 | Static gain for spacing control | | $g_{s_d}$ | 0.125 | Static gain for derivative of spacing control | | $g_{c,s}$ | 0.45 | Gain for collision avoidance based on spacing | | $g_{c,s_d}$ | 0.05 | Gain for collision avoidance based on derivative of spacing | | $d_{min}$ | 0.06 | Minimum control gap | | $\kappa_{ff}$ | 0.1 | Feedforward gain | | $g_o$ | 0.1 | Observer gain | | $g_m$ | 0.2 | Sliding mode control gain | | $\eta$ | 0.1 | Process noise for Kalman filter | | $\nu$ | 0.5 | Measurement noise for Kalman filter | Potential for chattering in sliding mode control: Sliding mode control is known for its robustness properties, but it can also introduce chattering, which is high-frequency oscillations in the control signal. Chattering can lead to increased actuator wear and reduced passenger comfort. Techniques such as boundary layer smoothing or higher-order sliding mode control can be employed to mitigate chattering. ``` import torch torch.cuda.is_available() ``` Here are the two tables in Markdown format: | Vehicle | Median | IQR | Min | Max | | --------- | --------- | -------- | --------- | -------- | | Vehicle 1 | -0.017319 | 0.003443 | -0.061437 | 0.020299 | | Vehicle 2 | -0.017092 | 0.004237 | -0.049895 | 0.023851 | | Vehicle 3 | -0.017310 | 0.003887 | -0.041486 | 0.024071 | | Vehicle 4 | -0.017245 | 0.004092 | -0.049366 | 0.019779 | | Vehicle | Median | IQR | Min | Max | |------------|-----------|----------|-----------|----------| | Vehicle 1 | -0.017008 | 0.050372 | -0.144781 | 0.162570 | | Vehicle 2 | -0.016877 | 0.031408 | -0.126513 | 0.092350 | | Vehicle 3 | -0.016856 | 0.006120 | -0.052564 | 0.475441 | | Vehicle 4 | -0.017364 | 0.023030 | -0.681685 | 0.068530 | | Vehicle | Synchronous Mode | | | | Asynchronous Mode | | | | |-----------|------------------|----------|-----------|----------|-------------------|----------|-----------|----------| | | Median | IQR | Min | Max | Median | IQR | Min | Max | | Vehicle 1 | -0.017319 | 0.003443 | -0.061437 | 0.020299 | -0.017008 | 0.050372 | -0.144781 | 0.162570 | | Vehicle 2 | -0.017092 | 0.004237 | -0.049895 | 0.023851 | -0.016877 | 0.031408 | -0.126513 | 0.092350 | | Vehicle 3 | -0.017310 | 0.003887 | -0.041486 | 0.024071 | -0.016856 | 0.006120 | -0.052564 | 0.475441 | | Vehicle 4 | -0.017245 | 0.004092 | -0.049366 | 0.019779 | -0.017364 | 0.023030 | -0.681685 | 0.068530 | ``` Given the following Python code, rewrite it as an algorithm suitable for inclusion in the "Methods" or "Algorithm" chapter of a scientific research paper. Pay close attention to the following aspects: Mathematical Notation: Replace Python-specific syntax with mathematical expressions and notations commonly used in scientific literature. For example, use subscripts for indexing, summation symbols for loops, and mathematical operators. Variable Naming: Rename variables to follow conventions used in mathematical equations. Use single-letter variable names (e.g., i, j, k) for indices and descriptive names for important quantities or parameters. Equations: convert the code into algorithm involves mathematical equations, define them using proper mathematical notation. Ensure consistency between the equations and the code. do not use list! , use table to include all paramters with its desciptiona and init value. you should first give it a full part of equations v = (...) then explain each part of equations finally give a table contains all the parameters. here is the code class Advanced_CACCController: def __init__(self, kp=0.45, kd=0.25, s0=2, tc=0.5, alapa=1): """ Initialize the PATH CACC controller. :param kp: The proportional gain for the spacing error. :param kd: The derivative gain for the spacing error. :param s0: The desired minimum safety spacing. :param tc: The desired time headway. """ self.kp = kp self.kd = kd self.s0 = s0 self.headway = tc #slide control self.s_lambda = 0.05 self.alapa_s = 0.27 self.x = 0 self.P = 1 self.ki = 0.1 self.int_error = 0 self.int_error_max = 0 #acceleration control self.acc_int_error = 0 self.acc_filter_alapa = 0.01 self.pre_ego_v = 0 self.pre_front_v = 0 #leader control self.kl = 0.01 #smooth control def kalman_filter(self,z, x, P, m_error, p_error): """ z: measurement x: estimate """ x_pred = x P_pred = P + p_error K = P_pred / (P_pred + m_error) x = x_pred + K * (z - x_pred) P = (1 - K) * P_pred return x, P def calc_speed(self, leader_v, leader_a, front_dis, front_v, front_a, ego_v, ego_a, leader_delay=0, front_delay=0, leader_tv=0, dt=0.034): meas_dis = front_dis self.x, self.P = self.kalman_filter(meas_dis, self.x, self.P, 0.04, 0.02) # Calculate the desired spacing des_spacing = self.s0 + self.headway * ego_v # Calculate the spacing error spacing_error = self.x - des_spacing #Calculate the acc error ego_acc_est = (ego_v - self.pre_ego_v)/dt front_acc_est = (front_v - self.pre_front_v)/dt #filter acc filter_ego_acc_est = self.acc_filter_alapa*ego_acc_est + (1-self.acc_filter_alapa)*ego_a filter_front_acc_est = self.acc_filter_alapa*front_acc_est + (1-self.acc_filter_alapa)*front_a acc_error = filter_front_acc_est - filter_ego_acc_est self.acc_int_error = max(min(self.acc_int_error + acc_error*dt, 0.5), -0.5) self.pre_ego_v = ego_v self.pre_front_v = front_v #Calculate the int_error self.int_error += spacing_error self.int_error = max(min(self.int_error, self.int_error_max), -self.int_error_max) speed_error = front_v - ego_v # Calculate the control input leader_difference = leader_v - ego_v #leader control leader_control_input = self.kl * leader_difference s = spacing_error + self.alapa_s*(speed_error) s_control_input = self.s_lambda * np.sign(s) control_input = self.kp * spacing_error + self.kd * speed_error + self.ki*self.int_error totle_control_input = control_input + s_control_input + leader_control_input new_speed = ego_v + totle_control_input return new_speed ``` The proposed CACC algorithm utilizes a Kalman filter to estimate the distance to the front vehicle based on the measured distance and the previous estimate. The control input for the Advanced CACC is calculated using the following equation: $$v = v_e + K_p \cdot e_s + K_d \cdot e_v + K_i \cdot \int e_s dt + \lambda_s \cdot \text{sgn}(s) + K_l \cdot (v_l - v_e)$$ where $v$ is the new speed of the ego vehicle, $v_e$ is the current speed of the ego vehicle, $K_p$ is the proportional gain for the spacing error, $e_s$ is the spacing error, $K_d$ is the derivative gain for the speed error, $e_v$ is the speed error, $K_i$ is the integral gain for the accumulated spacing error, $\int e_s dt$ is the accumulated spacing error over time (limited to a maximum value), $\lambda_s$ is the sliding control gain, $\text{sgn}(s)$ is the sign function of the sliding variable $s$, $K_l$ is the leader control gain, and $v_l$ is the speed of the leader vehicle. The Kalman filter equations are: $$\begin{aligned} \hat{x}_{\text{pred}} &= \hat{x} \\ P_{\text{pred}} &= P + Q \\ K &= \frac{P_{\text{pred}}}{P_{\text{pred}} + R} \\ \hat{x} &= \hat{x}_{\text{pred}} + K \cdot (z - \hat{x}_{\text{pred}}) \\ P &= (1 - K) \cdot P_{\text{pred}} \end{aligned}$$ where $\hat{x}$ is the estimated distance, $\hat{x}_{\text{pred}}$ is the predicted estimate, $P$ is the estimate covariance, $P_{\text{pred}}$ is the predicted estimate covariance, $Q$ is the process noise covariance, $K$ is the Kalman gain, $R$ is the measurement noise covariance, and $z$ is the measured distance. The control input for the Advanced CACC incorporates sliding mode control to improve robustness. The sliding variable $s$ is defined as: $$s = e_s + \alpha_s \cdot e_v$$ where $e_s$ is the spacing error, $e_v$ is the speed error, and $\alpha_s$ is the sliding control parameter. Explanation: The Advanced CACC algorithm employs a Kalman filter to estimate the distance to the front vehicle based on the measured distance and the previous estimate. The Kalman filter helps to reduce the impact of measurement noise and improve the accuracy of the distance estimation. The control input for the Advanced CACC is calculated based on the spacing error, speed error, accumulated spacing error, sliding mode control, and leader control. The sliding mode control term, $\lambda_s \cdot \text{sgn}(s)$, enhances the robustness of the controller by driving the system towards the sliding surface defined by the sliding variable $s$. The leader control term, $K_l \cdot (v_l - v_e)$, adjusts the ego vehicle's speed based on the difference between the leader vehicle's speed and the ego vehicle's speed. Parameters: | Parameter | Description | Initial Value | | ----------- | ----------------------------------------------- | ------------- | | $K_p$ | Proportional gain for the spacing error | 0.45 | | $K_d$ | Derivative gain for the speed error | 0.25 | | $s_0$ | Desired minimum safety spacing | 2 | | $t_c$ | Desired time headway | 0.5 | | $K_i$ | Integral gain for the accumulated spacing error | 0.1 | | $\lambda_s$ | Sliding control gain | 0.05 | | $\alpha_s$ | Sliding control parameter | 0.27 | | $K_l$ | Leader control gain | 0.01 | | $Q$ | Process noise covariance for Kalman filter | 0.02 | | $R$ | Measurement noise covariance for Kalman filter | 0.04 |