Changes
Page history
Update Steering
authored
Mar 04, 2025
by
Adham Beshr
Show whitespace changes
Inline
Side-by-side
Steering.md
View page @
dd728d03
...
...
@@ -46,27 +46,4 @@ The **FlexTimer Module (FTM)** is used to generate the required PWM signals. Bel
The function
`setServoPosition()`
updates the
**PWM duty cycle**
to control the steering.
```
cpp
// Function to set the servo position based on the desired duty cycle
void
setServoPosition
(
float
duty_cycle
)
{
// Update PWM duty cycle for SERVO0 (FTM3 CH6)
FTM_UpdatePwmDutycycle
(
FTM3_PERIPHERAL
,
FTM3_FTM_SERVO_CHANNEL
,
kFTM_EdgeAlignedPwm
,
duty_cycle
);
FTM_SetSoftwareTrigger
(
FTM3_PERIPHERAL
,
true
);
// Apply the new duty cycle
}
// Function to turn the car left
void
turnLeft
()
{
float
duty_cycle
=
5.0
;
// 1ms pulse width -> 5% duty cycle
setServoPosition
(
duty_cycle
);
}
// Function to turn the car right
void
turnRight
()
{
float
duty_cycle
=
10.0
;
// 2ms pulse width -> 10% duty cycle
setServoPosition
(
duty_cycle
);
}
// Function to center the servo (straight position)
void
centerServo
()
{
float
duty_cycle
=
7.5
;
// 1.5ms pulse width -> 7.5% duty cycle
setServoPosition
(
duty_cycle
);
}
```
\ No newline at end of file

\ No newline at end of file