Update Steering authored by Adham Beshr's avatar Adham Beshr
# 🏎️ **Steering System – Servo Motor Control** # :race_car: **Steering System – Servo Motor Control**
![Steering System](INSERT_IMAGE_LOCATION_HERE) ![Steering System](https://mygit.th-deg.de/ab11885/autonomous-line-following-car-with-camera-based-navigation/-/raw/main/Images/servo_motor.jpg)
## 📌 **Overview** ## :pushpin: **Overview**
The **steering system** of our autonomous car is controlled using a **servo motor**. The servo adjusts the front wheels' angle by modifying its **PWM (Pulse Width Modulation) duty cycle**, allowing for **precise directional control**. The **steering system** of our autonomous car is controlled using a **servo motor**. The servo adjusts the front wheels' angle by modifying its **PWM (Pulse Width Modulation) duty cycle**, allowing for **precise directional control**.
This page explains: This page explains:\
How the servo motor is used for steering. :heavy_check_mark: How the servo motor is used for steering.\
The implementation using **FTM (FlexTimer Module)** for PWM control. :heavy_check_mark: The implementation using **FTM (FlexTimer Module)** for PWM control.\
Code snippets for setting steering angles. :heavy_check_mark: Code snippets for setting steering angles.
--- ---
## ⚙️ **How the Servo Motor Works** ## :gear: **How the Servo Motor Works**
A **servo motor** operates by receiving a **PWM signal**, where: A **servo motor** operates by receiving a **PWM signal**, where:
- A **1ms pulse width (~5% duty cycle)** steers **left**.
- A **1.5ms pulse width (~7.5% duty cycle)** keeps the wheels **centered**.
- A **2ms pulse width (~10% duty cycle)** steers **right**.
### **PWM Signal Representation**
- A **1ms pulse width (\~5% duty cycle)** steers **left**.
- A **1.5ms pulse width (\~7.5% duty cycle)** keeps the wheels **centered**.
- A **2ms pulse width (\~10% duty cycle)** steers **right**.
📌 _These signals are generated using **FTM3 Channel 6**._ ### **PWM Signal Representation**
![PWM Signal Explanation](INSERT_IMAGE_LOCATION_HERE) :pushpin: _These signals are generated using **FTM3 Channel 6**._
--- Duty Cycle = ( Pulse Width / Period Length ) x 100
![PWM Signal Explanation](https://mygit.th-deg.de/ab11885/autonomous-line-following-car-with-camera-based-navigation/-/raw/main/Images/Screenshot_2025-03-02_125710.png)
## 🔩 **Implementation – Controlling the Servo Motor** ## :nut_and_bolt: **Implementation – Controlling the Servo Motor**
The **FlexTimer Module (FTM)** is used to generate the required PWM signals. Below is an overview of how the servo control is implemented. The **FlexTimer Module (FTM)** is used to generate the required PWM signals. Below is an overview of how the servo control is implemented.
### **Pin Configuration** ### **Pin Configuration**
| **Peripheral** | **Pin** | **Function** | | **Peripheral** | **Pin** | **Function** |
|--------------|--------|------------| |----------------|---------|--------------|
| **Servo Motor** | PTB12 | FTM3_CH6 (PWM) | | **Servo Motor** | PTB12 | FTM3_CH6 (PWM) |
--- ---
## 🛠️ **Code Implementation** ## :tools: **Code Implementation**
### **:one: Setting the Servo Position**
### **1️⃣ Setting the Servo Position**
The function `setServoPosition()` updates the **PWM duty cycle** to control the steering. The function `setServoPosition()` updates the **PWM duty cycle** to control the steering.
```cpp ```cpp
...@@ -68,3 +69,4 @@ void centerServo() { ...@@ -68,3 +69,4 @@ void centerServo() {
float duty_cycle = 7.5; // 1.5ms pulse width -> 7.5% duty cycle float duty_cycle = 7.5; // 1.5ms pulse width -> 7.5% duty cycle
setServoPosition(duty_cycle); setServoPosition(duty_cycle);
} }
```
\ No newline at end of file