How to design a finite state machine (FSM) for a traffic light system using timers, vehicle detectors, and pedestrian priority?

Thread Starter

Gr10

Joined Feb 10, 2025
15
I am working on a traffic light control system for an intersection with a **main road (Vp)** and a **secondary road (Vs)**, using:
- **Vehicle detectors**:
- **Dp** (main road).
- **Ds** (secondary road).
- **Pedestrian buttons**:
- **Pp** (to cross the main road).
- **Ps** (to cross the secondary road).
Which can be expresed with the following diagram:

Screenshot_20250330-204410.png

- **Non-retriggerable monostable timers**:
- **5 seconds** (I₅, output T₅).
- **15 seconds** (I₁₅, output T₁₅).
Screenshot_20250330-204441.png

### **Specifications:**
1. **Main road (Vp):**
- **Green (Vp)** must stay on for **at least 30 seconds**, but can be extended if:
- A vehicle is detected on the secondary road (Ds triggered).
- A pedestrian presses **Pp**.
- Then, **Yellow (Ap)** for **5 seconds** (using T₅).
- During Vp and Ap, the secondary road must be **Red (Rs)**.

2. **Secondary road (Vs):**
- **Green (Vs)** must stay on for **at least 15 seconds**, but can be extended if:
- A vehicle is detected on the main road (Dp triggered).
- A pedestrian presses **Ps**.
- Then, **Yellow (As)** for **5 seconds** (using T₅).
- During Vs and As, the main road must be **Red (Rp)**.
3. The cycle repeats indefinitely.

### **Implementation Questions:**
1. **How many states should the finite state machine (FSM) have?**
- Considering **Vp (green) → Ap (yellow) → Vs (green) → As (yellow) → (cycle)**, would **4 base states** be sufficient?
- Or should I add more states to handle **extensions due to detectors (Dp/Ds) or pedestrians (Pp/Ps)**?

2. **How should state transitions be handled?**
- For example, how to prioritize a pedestrian signal (**Pp/Ps**) over the minimum green time?
- Should I use **combined conditions** (e.g., "Pp OR Ds") to exit the **Vp state** before 30s?

3. **How to generate the 30-second delay if I only have 5s and 15s timers? **

- No diagrams needed—just a brief textual explanation of the FSM structure.
- Prefer avoiding microcontrollers (only basic FSM and timers).
 

WBahn

Joined Mar 31, 2012
32,746
MOD NOTE: Moved to Homework Help.

How many states you need is addressed by asking how many different unique conditions the machine can be in. The idea is that if I tell you what state the machine is in, that tells you everything you need to know in order to act upon the inputs, whatever they happen to be.

For getting a 30 second delay when you only have 15 s timers, think about what you need to know to decide what to do when the timer expires. If it expires and you know that you are in the first 15 s of your 30 s interval, what do you do? If it expires and you know that you are in the second 15 s of your 30 s interval, what do you do? If you do different things, then that means that the first half of the 30 s must be associated with a different state than the second half.
 
Top