Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1665 pj 1
----------------------------------
2
Pong demo
3
 
4
by
5
 
6
Spencer Hoke
7
James Kim
8
Tao Luo
9
 
10
for
11
 
12
CS 324 Real-Time Systems
13
at The University of Illinois at Urbana-Champaign
14
with Marco Caccamo
15
 
16
May 5, 2004
17
----------------------------------
18
 
19
FILES:
20
  MAKEFILE     The makefile used to compile the application;
21
  PONG.H       Header file containing constants used by both pong and JET
22
  PONG.C       Main code
23
  JETCTRL.C    Tasks for the JET monitors
24
               (This file is based on the jetctrl.c file from other Shark demos)
25
  INITFILE.C   Initializes EDF/CBS scheduling and mutexes
26
  README.TXT   This file
27
 
28
USAGE:
29
- Copy the source files into a folder within the shark/demos and use 'make' to
30
  compile.
31
- Run by typing 'x pong' at the A:\> prompt if using the standard boot disk.
32
 
33
PROGRAM OPERATION:
34
- The purpose of each player is to control the paddle so that the balls bounce
35
  off the paddle and past the other player's paddle.
36
- Adding new balls is done by pressing the space bar.
37
- The number of balls can be kept constant by pressing the L key. "Locked"
38
  will be displayed under the number of balls indicating that the number of
39
  balls will be held constant at this number. The countMonitor task adds new
40
  balls whenever one leaves. When L is pressed again, balls that exit will not
41
  be reintroduced.
42
- The scores for each player are shown in the upper left corner and are
43
  updated whenever a ball reaches the top or bottom of the play area. At this
44
  time, that ball is removed.
45
- The difficulty of the computer's paddle can be changed by adjusting the
46
  length of each paddle, and constants controlled by keys 0-9.
47
- You can adjust the length of the paddles or constants at any time.
48
 
49
GRAPHICS:
50
- It works at 640x480 8 bit colors using the grx interface
51
- On the left is the main playing area. On the right are the commands and the
52
  JET information. Adjustable parameters are shown above and below the play
53
  area.
54
 
55
TASKS:
56
- Ball - each ball is a separate task. There can be as many of these as can be
57
  scheduled. Each one stores a position and angle, and updates with a new
58
  position each task cycle, drawing a black circle over its old position and
59
  drawing its new position. The balls also check to make sure that their new
60
  position is not outside the play area or inside of a paddle, in which case
61
  balls will bounce and change angles. If a ball goes past the paddle, it
62
  is removed and the task ends. Ball bounces are done elastically.
63
- Paddle1 - this is the user-controlled paddle. It uses the keys entered by
64
  the user to update its position during each cycle.
65
- Paddle2 - this is the computer-controlled paddle. It uses a position
66
  generated by task p2ai and moves toward a new position by applying both
67
  proportional and derivative forces. The paddle's mass and constants kp and
68
  kd are all adjustable at run-time.
69
- P2ai - this task reads all the current balls in the system that are within
70
  the AI viewing window (adjustable at run-time) and determines the position
71
  that paddle2 should move to in order to hit the next ball. The first ball to
72
  hit is calculated based on the position and angles of the balls, and also
73
  accounts for bouncing
74
- CountMonitor - if the number of balls is locked, this task checks to see if
75
  the number of balls in the system is at least equal to the min_balls
76
  variable and adds ball tasks if not.
77
- JetCtrl - updates the table of tasks with their mean/max execution times
78
- JetDummy - draws the system utilization graph
79
- JetSlide - draws the utilization bars beside each task listed in the JET
80
  task list.
81
- Main - after initialization, main reads the keyboard. Reads are blocking,
82
  and the appropriate action is taken after a key is pressed.
83
 
84
TASK SCHEDULING:
85
- Tasks are scheduled using EDF with a CBS. JET tasks are soft and follow
86
  CBS, while all other tasks are hard and follow EDF scheduling. Parameters for
87
  the tasks are (in ms):
88
 
89
    JetCtrl   7.5  met   100 period
90
    JetDummy  0.2  met   100 period
91
    JetSlide  2.1  met   100 period
92
    Balls     0.75 wcet   40 period
93
    CountMon  0.75 wcet   40 period
94
    Paddles   0.25 wcet   40 period
95
    P2ai      0.25 wcet   40 period
96
 
97
- Feel free to change any of the wcet and periods to make it better for
98
  different CPU's. The mean and max execution time of each task can be seen in
99
  the JET display of the program. These numbers were tested on a P3 866 MHz
100
  machine.
101
 
102
- The system will not overload with 145 hard balls, which reaches the
103
  maximum number of processes that shark is able to handle. In order to test
104
  overload, the periods of balls, or the radius of the balls could be increased
105
  to increase their utilization.
106
 
107
- The ball and paddle tasks were given the same periods because to ensure that
108
  our speeds were constant across both tasks and to avoid discrepencies between
109
  the positions of the objects. The ai task was also given a period of 40 ms
110
  because it is pointless for it to update the target position of paddle2 more
111
  than once during a paddle2 cycle.
112
 
113
- Decreasing the periods of the paddles would make the movement of the user
114
  paddle more responsive, if desired, because updates are only drawn to the
115
  screen currently every 40 ms.
116
 
117
PADDLE 2 CONTROL:
118
- We used the proportional and derivative control model, so the force applied
119
  to the paddle at a given point is:
120
    F = kp(distance to target position) - kd(velocity)
121
  Force is divided by mass to give the paddle acceleration.
122
- The default values shown give some oscillation around the target position.
123
  Increasing kd will decrease the oscillations. Increasing both will make the
124
  computer harder.
125
- Kp and Kd are limited to values >= 0, mass is limited to values > 0.
126
 
127
SYNCHRONIZATION:
128
- One mutex was used around all calls to the grx functions that write to the
129
  screen.
130
- Another mutex was used for all accesses to the linked list of ball positions
131
  that was used for the p2ai task to determine which ball will hit next.
132
- Both mutexes use priority inheritance to minimize blocking time of higher
133
  priority tasks.
134
 
135
POSSIBLE NEXT STEPS:
136
- Balls currently bounce from their current position once they determine that
137
  their next position will be out of bounds. This could be changed so that the
138
  balls determine the distance to the wall, subtract that distance from their
139
  speed, reflect the path around the wall, and end up at the new position.
140
- Updating of positions for the balls and the paddles is done based cycles
141
  (once per cycle, the ball moves BALL_SPEED pixels). In a large time
142
  interval, the average speed is equal to this, but the speed in a small
143
  period of a ball might be greater or smaller than BALL_SPEED. This could be
144
  changed so that the exact time is used and during each cycle, the ball might
145
  move slightly more or less than BALL_SPEED pixels. In the current demo, the
146
  updates happen to fast for the user to notice the difference.
147
- If balls move too fast, they may skip over a paddle and score a point even though the
148
  paddle is in the way, but at this point, the balls are too fast for the user
149
  to respond to them, so the game is not playable.
150
- Main does keyboard reading in the current program. This could be changed to
151
  using keyboard hooks and having a seperate function for each key. I tried
152
  this implementation, but the numeric keys did not function properly, so I
153
  restored all key reading to main. I do not know if there would be a
154
  performance increase by changing them, but the switch statement would be
155
  removed, which would make it at least slightly more responsive.
156