## 3 Methodology
### Control Design  
Our proposed controller in this work is a fine-tuned version of the fuzzy controller using particle swarm optimization (PSO). More specifically, our approach merges fuzzy logic and PSO, optimizing both the expectation and standard deviation of the fuzzy controller's membership functions. The fuzzy controller incorporates four inputs: bus voltage error, integral of bus voltage error, battery state of charge (SoC), and supercapacitor state of charge (SoC). From these inputs, the fuzzy controller generates current references for the battery, supercapacitor, and overvoltage discharge (OVD). Three low-level PI controllers process reference values and generate duty cycles for stabilizer components based on actual component currents. The controller generates the duty cycle to change the switching rates of the EV's battery, supercapacitor, and OVD in the following manner. * Duty cycle signals initiate battery or supercapacitor discharge into the DC microgrid when production is lower than consumption, providing additional electrical energy. * When the battery and supercapacitor are fully charged and the production exceeds consumption, these signals discharge overvoltage on the OVD component to prevent overcharging, ensuring safety. * Alternatively, these duty cycles can be applied to the boost converters of the battery or supercapacitor to charge them when their charge is below the full amount. Figure 5 illustrates the overall architecture of the proposed fuzzy controller. Similar to [35; 36], the primary fuzzy controller's membership functions are initially untrained. However, in the trained version, they undergo fine-tuning via PSO to achieve the objectives of ripple minimization and battery lifetime expansion. Figure 6 shows the membership function of the bus voltage error and the membership function of the integrated bus voltage error. Two membership functions, negative (NEG) and positive (POS), are considered for each input. The NEG is designed to manage negative voltage ripple, whereas the POS is employed to address positive voltage ripple. It is worth mentioning that the currents and voltages are normalized before feeding into the fuzzy inference system. The fuzzy controller functions effectively by taking two parameters as inputs: the integral of voltage error and the voltage error itself. This enables the algorithm to discern alterations that could influence the bus voltage, aiding in the preservation of the nominal voltage level. The input associated with the voltage error promptly reacts to rapid fluctuations, whereas the integral term identifies prolonged changes. Consequently, the fuzzy controller initiates responses to counteract and rectify any deviations in the bus voltage. This dual-response mechanism empowers the DC microgrid to address both swift and gradual alterations, thereby widening its bandwidth and enhancing its ability to promptly adapt to varying conditions. Moreover, Figure 7 shows the membership functions associated with the state of charge (SOC) of the battery and supercapacitor, respectively. The SOC of the battery and  
Figure 5: Configuration of fuzzy controller, where \(I_{B}\) is battery current, \(I_{UC}\) is supercapacitor current, \(I_{OVD}\) is OVD current, \(I_{RB}\) is battery reference current, and \(I_{RUC}\) is supercapacitor reference current. ultracapacitor are treated differently since they have two distinct objectives: \"low\" and \"high\". Although it may seem that these functions do not cover certain sections of the axis, it is essential to note that the \"NOT\" operation of each membership function is considered in the rule base so it can cover the entire range between 0 and 1. To minimize the usage of the EV battery, a low charge condition is defined as 0.3, while a high charge condition is set to 0.7. These conditions are strategically established to reduce the overall engagement of the EV battery. Figure 7 clearly illustrates the distinction between high and low battery charge levels.