Main Content

Schedule When Traffic Camera Takes Snapshot

You can use the Hit Scheduler block to schedule time hits for a variable-step solver during simulation based on the runtime behavior of a system. For example, some roads and highways have monitoring devices and systems to deter speeding and capture information about cars that speed.

At an intersection with a traffic light, such a monitoring system might consist of these components:

  • Sensors that detect an approaching car and measure its speed

  • A camera embedded in the traffic light that can capture an image of each speeding car

To ensure the camera captures a consistent image, the system needs to determine when the camera shutter activates based on the speed of each car.

This example shows how you can use the Hit Scheduler block to schedule when a traffic camera in this type of system captures an image.

Open and Explore Model

Open the model TrafficCam. The model implements the scheduling for a traffic camera on a two-lane road with a speed limit of 65 miles per hour using the Hit Scheduler block an a triggered subsystem.

mdl = "TrafficCam";
open_system(mdl)

The blocks Lane 1 and Lane 2 are masked subsystems that contain logic to generate signals that represent car detection and the speed of the detected car. The car detection signals are random. The car speeds vary randomly around a nominal value of 64 miles per hour.

The car detection blocks and a Constant block that indicates the speed limit for the road feed a subsystem with scheduling logic that determines whether a speeding car has been detected. If a speeding car is detected in both lanes at the same time, the logic schedules the camera shutter to capture an image of the faster car.

The Speeding Car Detected output of the Scheduling Logic subsystem drives the enable port for the Hit Scheduler block so that the block schedules a time step each time a speeding car is detected.

The Car Speed output of the Schedule Logic subsystem connects to another subsystem that uses the speed of the car and the distance of the car from the camera to calculate the delay between the current time and when the camera should capture an image of the speeding car.

The Hit Scheduler block produces a function-call event on each scheduled time step that drives the trigger port for the Camera Shutter subsystem.

Simulate Model and Analyze Results

Simulate the model. Then, open the Simulation Data Inspector and use the Simulink.sdi.loadView function to load the view file TrafficCamView.mldatx.

out = sim(mdl);
Simulink.sdi.view
Simulink.sdi.loadView("TrafficCamView.mldatx");

On the first time step, a speeding car is detected. From the speed of the car, the delay time for the camera to capture a picture of the car is calculated as 0.1822 seconds.

logsout = out.logsout;
dt = getElement(logsout,"dt");
dt0 = dt.Values.Data(1)
dt0 = 0.1822

The Hit Scheduler block schedules a time step to occur at 0.1822 seconds. On the scheduled time step, the block produces a function-call event that triggers the Camera Shutter subsystem.

The shutter activates for the first time on the third time step in the simulation, which is the time step the Hit Scheduler block scheduled at the start of the simulation.

yout = out.yout;
shutter = getElement(yout,"Shutter");
t3 = shutter.Values.Time(3)
t3 = 0.1822

Use the cursors in the Simulation Data Inspector to continue analyzing the Speeding Car Detected, dt, and Shutter signals and analyze how the Hit Scheduler block controls the action of the camera.

See Also

|

Related Topics