Desklib offers a Safe-Driving Practice Simulator for students to experience safe-driving. The simulator includes a racing board, UML diagram, flow chart, model view, and source code for the AcceleratorMonitor event handler. The simulator also includes 3D graphics for rotating geometry and graphics operation.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Safe-Driving Practice Simulator Screenshot Related to the Scenarios: Display of the race, and a separate control program Racing board where race competitors meet
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Model Source Code: The sample application is structured as a number of event handlers. Each event handler is a thread that waits for a periodic release, executes the event handling code, and then suspends itself until the next periodic release. The traction monitoring system comprises the following event handlers: •Four different WheelSensor event handlers, one per wheel, with a period of 8 ms •A BrakeMonitor event handler, with a period of 16 ms •A SteeringMonitor event handler with a period of 24 ms •An AcceleratorMonitor event handler with a period of 32 ms The following additional threads participate as part of the underlying infrastructure: •An overseeing main thread, which periodically checks and reports on the status of vehicle traction, with a period of 100 ms •A dispatcher thread, which manages the scheduling of the other real-time threads, with a period of 4 ms •A PeriodicDelay thread, which provides interconnection between the dispatcher thread and the main thread, with a period of 100 ms Code for the AcceleratorMonitor event handler is shown in Listing 1. [1]package traction; [2] [3]import com.atego.srt.EventHandler; [4]import simulation.IOServer; [5] [6]public class AcceleratorMonitor extends EventHandler { [7] [8]private double acceleration; [9]private final IOServer io; [10]public AcceleratorMonitor(IOServer io, int priority) { [11]super(priority); [12]this.io = io; [13]acceleration = 0.0; [14]} [15]public synchronized void handleAsyncEvent() { [16]acceleration = io.getAcceleration(); [17]} [18]public synchronized double getAcceleratorLevel() { [19]return acceleration; [20]} [21]} Implementation ofAccelerator Monitor TheAcceleratorMonitorclass extends the abstractcom.atego.srt.EventHandlerclass, which is from an open-source library that provides capabilities similar to the services discussed inReal-Time Specification for Java(Addison Wesley Longman, 2000). The concrete implementation overrides thehandleAsyncEventmethod, providing user code that is to be executed every time the event handler is fired. TheAcceleratorMonitorobject is instantiated withinMain.javaand assigned to the localaccelerator_monitorvariable. To arrange for periodic execution of theAcceleratorMonitor, it is passed as an argument to aPeriodicEventconstructor, as shown in the following excerpt fromMain.java: PeriodicEventaccelerator_event= newPeriodicEvent(dispatcher,ACCELERATOR_SENSOR_PERIOD,accelerator_monitor); [1]longnum_samples,least_squares_tag; [2] [3]publicsynchronizedvoidhandleAsyncEvent(){ [4]doublerotation=io.getWheelRotation(wheel_id); [5]doubleadjusted_rotation=(rotation<previous_angle)?( [6]rotation+360:rotation); [7]doublerotational_delta=adjusted_rotation-previous_angle; [8]doublethis_distance=( [9](rotational_delta/360.0)*WHEEL_CIRCUMFERENCE); [10]previous_angle=rotation; [11]doubleoverwritten_distance=y_values[oldest_distance_index]; [12]y_values[oldest_distance_index]=this_distance; [13]oldest_distance_index++; [14]if(oldest_distance_index>=NUM_SAMPLES){ [15]oldest_distance_index=0; [16]} [17]sum_xy=0.0; [18]inty_index=oldest_distance_index;