## 3 Implementation of Vehicular VLC System
### Adaptive LED Beam Alignment Mechanism  
For seamless VLC between consecutive vehicles, the proposed vehicular VLC system incorporates an adaptive LED beam alignment mechanism, which is developed in this study. A key component of this mechanism is the servo-motor integrated with the transmitting vehicle's LED module. Specifically, we utilized the SG-90 model of servo-motor, manufactured by OEM, which can be easily controlled via pulse-width modulation through the main board. The servo-motor adjusts the orientation of the LED module on the transmitting vehicle to align with the PD of the following vehicle.  
In the proposed beam alignment mechanism, the acceleration and yaw rotation angle are computed using data from the IMU sensor. Let \(\left[A_{\mathrm{x}}(t),A_{\mathrm{y}}(t),A_{\mathrm{z}}(t)\right]\in\mathbf{A} (t)\) be the acceleration (in m/s\({}^{2}\)), \(\left[G_{\mathrm{x}}(t),G_{\mathrm{y}}(t),G_{\mathrm{z}}(t)\right]\in\mathbf{ G}(t)\) be the angular velocity (in rad/s), and  
Figure 4: Illustration of a detailed packet design for the proposed vehicular VLC system.  
Figure 3: Brief circuits of transmitter and receiver in the proposed vehicular VLC system.  
\(\big{[}M_{\rm x}(t),M_{\rm y}(t),M_{\rm z}(t)\big{]}\in\mathbf{M}(t)\) be the magnetic flux density (in Tesla) at time \(t\), respectively. These quantities are computed from the nine-axis raw data of the IMU sensor (i.e., \(\mathbf{A}_{\rm raw}(t)\), \(\mathbf{G}_{\rm raw}(t)\), and \(\mathbf{M}_{\rm raw}(t)\)) as follows:  
\[\mathbf{A}(t)=\frac{g}{S_{A}}\mathbf{A}_{\rm raw}(t),\ \mathbf{G}(t)=\frac{1}{S_{G}} \mathbf{G}_{\rm raw}(t),\ \mathbf{M}(t)=\mathbf{M}_{\rm raw}(t)K, \tag{1}\]  
where \(S_{A}\) and \(S_{G}\) are the sensitivities of the accelerometer and gyroscope, respectively, \(g\) is the gravitational acceleration, and \(K\) is the coefficient of the magnetometer. The \(z\)-axis angular velocity, denoted as \(G_{z}(t)\), is typically obtained from the IMU sensor. However, due to the potential for ambient noise during data acquisition, a more robust estimation of \(G_{z}(t)\) is achieved by incorporating both the angular velocity \(\mathbf{G}(t)\) and the magnetic flux \(\mathbf{M}(t)\). This approach leverages a complementary filter, which combines the advantages of both data sources to provide a more accurate and noise-resistant estimation of the \(z\)-axis angular velocity. More specifically, the \(z\)-axis angular velocity computed using \(\mathbf{M}(t)\), denoted as \(G_{z,\mathbf{M}}(t)\), is derived from the rate of change in \(\rm{yaw}_{\mathbf{M}}(t)\), as given by  
\[G_{z,\mathbf{M}}(t)=\frac{\rm{yaw}_{\mathbf{M}}(t)-\rm{yaw}_{\mathbf{M}}(t-1) }{\Delta t}, \tag{2}\]  
where \(\rm{yaw}_{\mathbf{M}}(t)=-\rm{atan2}\big{(}M_{x}(t),M_{y}(t)\big{)}\), and \(\Delta t\) is time interval. Finally, the \(z\)-axis angular velocity after filtering, denoted as \(G_{z,\rm{flt}}(t)\), can be represented as follows:  
\[G_{z,\rm{flt}}(t)=\alpha G_{z}(t)+(1-\alpha)\cdot G_{z,\mathbf{M}}(t), \tag{3}\]  
where \(\alpha\) is the coefficient of the complementary filter. Consequently, to align the LED beam between consecutive vehicles, particularly when navigating curves, the regulated \(G_{z,\rm{flt}}(t)\) is used as an input to control the servo-motor. This allows for precise adjustments in the LED module's orientation, ensuring a stable communication link between vehicles. The proposed LED beam alignment mechanism is outlined in Algorithm 1.  
```
1: Perform initial setup and offset calibration.
2:while Initial offset calibration is carried out. do
3: Receive raw data from each axis and convert units.
4: Integrate acceleration, gyroscope, and magnetic data.
5: Apply complementary filter.
6: Adjust servo-motor angle based on the angular velocity.
7: Transmit current vehicle's data to main board.
8:endwhile
```  
**Algorithm 1** Adaptive LED beam alignment mechanism.