Você está na página 1de 6

ELE3307 Real-Time Systems Semester 2, 2013

Assignment 2
Multi-process Application Military Tank Control
Date Due: 18 October 2013
Marks: 200 (20% of total assessment marks)
Penalty for Late Submission: 10% per working day late

NOTE: This assignment looks very similar to Assignment 1, specifically note the changes and the
additional requirements (underlined) for the multi-process structure.

Outline of task
You are required to design, implement and document a multi-process program for a Military
Tank Control System to execute on a Windows based personal computer. The assignment does
not involve any hardware connections to the PC, as the operation of the tank is simulated by a
program provided for this purpose.

To complete this assessment you must submit a report documenting your system design, and
submit the source files and executables of the completed (or partially completed) program by the
due date. The report must include the following concise information:

Program Listing - Commented source file listing


System Model - A diagram representing the program and a brief
explanation of its operation (maximum 6 pages)

System specification
Design

The application to be designed must correctly control the steering and gun targeting of the tank
given user input from the keyboard. The tank configuration is detailed below. You are required to
write a multi-process implementation for a Real-Time control system to meet the following
requirements:

1. Control the tank based on key strokes F for forward, B for backward, R to turn right, L
to turn left, S for stop. You are to assume that the tank can only turn on the spot while
stopped, so your control is to ignore any command to turn while moving. The Tank uses a
typical 2 motor control, driving a track on each side. Assume the tank has only one
forward speed, one reverse speed and stop. Speed will be 1 unit/second and the turning
rate is +/-15 degrees/second

2. Track the location of the tank (X,Y co-ordinates) and the heading (H). A flat working
surface is to be assumed with an area of +/-20 units in each direction. Initial position will
be (0,0) with a heading of 0 degrees. (use Cartesian co-ordinate system) The position and
heading will also be monitored by the tank simulator program, run in conjunction with
your program to monitor the movement of the tank as commanded.

Page 1 of 6
ELE3307 Real-Time Systems Semester 2, 2013

3. Stop the tank and issue a warning when it reaches the limits of work area (+/-20, X or Y).

4. On receiving the A keystroke, aim the turret at the fixed target position (5,5). The
calculation for aiming the turret should be based on trigonometry between the tank
position and the fixed target location. Note the turret may be aimed while the tank is
moving, in which case the turret should track the target until the cannon is fired.

5. Control the gun turret (with respect to the forward facing direction of the tank) such that
the angle never exceeds +/- 135 degrees. Issue a warning when it reaches either of these
limits. Assume turret turning speed is +/-45degrees per second.

6 On receiving the X keystroke, fire the cannon if the turret is tracking the target. Note
the tank may be stopped or moving. The tank simulator program will determine how
close you came to hitting the target, which is assumed to be 0.1 units wide.

Tank detail Area


Y
(20,20)

+ left track

Target
(5,5)
- right track +
start Heading
Turret +/- 135
X

Area
(-20,-20)
Figure 1: Tank work area

Note the size of the tank is not significant, the figure above is not necessarily to scale.

Implementation

You are required to implement a multi-process real time control program in C to execute on a
Windows compatible PC, using the cygwin or windows programming environment. Stated-based
operation is recommended.

You will be provided with TankSim.exe, a separate program which you run at the same time as
your control program. This program will simulate the tanks movement, track its position, heading
and turret angle based on the commands you give and determine the accuracy of the cannon firing.

Page 2 of 6
ELE3307 Real-Time Systems Semester 2, 2013

As you will need to modify LiftSim.exe you will also be provided with LiftSim.Dev
(including tank.c, kbhit.c, kbhit.h and tank.h).

You will be provided with a copy of the header file tank.h and the source file tankint.c which
provides a set of subroutines that interface with the tank simulation program. Look for these files
on the USQ Study Desk. A summary of the function of each subroutine is provided below. You
should incorporate these files in your program compilation.

A sample solution program for Assignment 1 will be available once all the Assignment 1 reports
have been received (This allows students who couldnt manage a good solution to start
Assignment 2 on an equal footing). You can use your own solution program for Assignment 1 as a
basis for starting to develop your code for Assignment 2, But you must use the sample solution
program for Assignment 1 for your final submission.

Functions of subroutines

The first two subroutines control the connection to the tank simulator program.

int tankopen(void);
Call this routine once at the top of your program to initialize the link to the tank simulator
program and reset the tank position to its initial state: (0,0) heading 0. Returns 0 for
success and -1 for failure to open link.

int tankclose(void);
Call this routine once at the end of your program to close the link to the tank simulator
program. Returns 0 for success and -1 for failure to close link.

The next four subroutines control the tank track motors, the turret and the cannon.

void leftmotor(int onoff);


Call this routine with +1, 0 or -1 as a parameter to control the left track motor: Forward,
Stop and Backward respectively.

void rightmotor(int onoff);


Call this routine with +1, 0 or -1 as a parameter to control the right track motor: Forward,
Stop and Backward respectively.

int turret(int onoff);


Call this routine with +1, 0 or -1 as a parameter to control the turret motor:
Left (+ve Cartesian angle), Stop and Right (-ve Cartesian angle) respectively.
Returns 0 for success and -1 for if the turret is already at +/- 135 degrees..

double fire(void);
Call this routine to fire the canon. It returns a double precision float which gives the error
in targeting in units, positive numbers are to the left of target (+ve cartesian angle). Value
within +/- 0.05 indicates a hit.

Page 3 of 6
ELE3307 Real-Time Systems Semester 2, 2013

double angle(void);
This routine returns the angle of the turret with respect to the tank. This angle is changed
when the turret() routine is used to turn the turret.

Individual processes

NOTE: This section is an additional requirement covering the multi-process implementation.

You are required to structure your application as a multi-process implementation to perform the
following functions.

1. A process that sets up any common variables, the inter-process communications and starts
the other processes, including the TankSim.exe program. This process may also include
one of the remaining functions.
2. A process to control the movement of the tank.
3. A process to aim the turret and track the target.
4. A process to accept keystrokes from the keyboard.

Inter-process communications

NOTE: This section is an additional requirement covering the multi-process implementation.

You are required to establish inter-process communications using at least TWO different forms of
communications and ONE form of synchronization as described in the study materials.

The communications with the TankSim program is actually via shared memory. Typically a
semaphore or lock file would be used to protect accesses in the tank interface routines and on the
other side in the TankSim program. In order to correctly access the shared data area set up by
Tank.c, you will have to add semaphore protection to the Tank.c and TankInt.c programs to avoid
errors when two of your processes access this common data area. This protection should be placed
either side of the sleep system call in Tank.c and in each access to common data in the TankInt.c
subroutines.

Special Notes:

1. Cumulative errors will be expected in motion and angular calculations. Discrepancies will
also occur between your position tracking and that of the tank simulation. These discrepancies
can be minimized by using short loop intervals in your state machine. (=< 0.1 seconds)

2. Late assignments will not be accepted unless the examiner has been consulted 3 days prior
to the due date and advised of an expected date for submission. Programs submitted must be the
work of each individual student. Exchange of ideas on conceptual issues between students is
expected, but students must write their own programs and not share code.

3. Students are required to complete this assignment in the C language on a Windows


compatible personal computer. Students are required to submit both source codes and
executables on the StudyDesk (EASE), plus a design report.

Page 4 of 6
ELE3307 Real-Time Systems Semester 2, 2013

ELE3307 Assignment 2 marking criteria


Each attribute below relates to a key element of the assignment and is marked on a scale of 25, 50, 75 or 100% for that attribute. Zero marks will be awarded
for no attempt.

place copy of star to indicate


rating

Attribute Novice Apprentice Practitioner Master Mark


Source Files Program compiles with many Program compiles with some syntax errors, Program compiles without error, but testing Program compiles without error
syntax errors and cannot be tested. but with correction is testable. (4-6) reveals some execution errors. (7-9) and testing reveals no execution
(0-3) errors.(10-12)
/ 12
Functional The program incorrectly uses The program makes limited use of sensor The program adequately uses sensor The program consistently uses
requirements sensor information or information or accumulated data. (7-12) information and accumulated data.(13- sensor information and
accumulated data. (0-6) 18) accumulated data. (19-24)
/ 24
The program incorrectly controls The program partially controls the system The program adequately controls the The program reliably controls the
the system or fails to display or displays system conditions.(7-12) system and displays system system and displays system
system conditions.(0-6) conditions.(13-18) conditions.(19-24)
/ 24
Functional The program incorrectly uses The program makes limited use of timing The program adequately uses timing The program consistently uses
requirements timing elements.(0-3) elements.(4-6) elements.(7-9) timing elements.(10-12)
(Timing) / 12

Process Division The program incorrectly uses The program makes limited use of multiple The program adequately uses multiple The program makes good use of
and Operation multiple processes or does not processes with some division of tasks(9-16) processes but division of tasks could be multiple processes and divides
divide task into processes.(0-8) improved.(17-24) tasks appropriately.(25-30)
/ 30
Inter-Process Program incorrectly uses inter- Program makes limited use of inter-process Program makes adequate use of inter- Program makes good use of inter-
Communications/ process communications or communications, but without any process communications, with some process communications and
Synchronisation synchronisation.(0-8) synchronisation.(9-16) synchronisation.(17-24) synchronisation.(25-30)
/ 30
Program The program is implemented with The program is implemented with some use The program is implemented with adequate The program is implemented with
Implementation limited use of accepted of accepted programming techniques.(5-9) use of accepted programming good use of accepted
programming techniques.(0-4) techniques.(10-12) programming techniques.(13-16)
/ 16

Page 5 of 6
ELE3307 Real-Time Systems Semester 2, 2013

Documentation Documentation is poorly written Documentation is limited or explanation of Documentation is adequately written and Documentation is well written and
or does not explain program or program or inter-process comms is explains program operation & inter-process explains program & inter-process
inter-process communications. (0- incomplete.(6-10) comms.(11-15) comms operation clearly.(16-20)
5) / 20
System Model Diagram is inappropriate for task Diagram is limited or incomplete and does Diagram is adequately drawn and Diagram is well drawn and
or does not represent program not represent program structure well.(6-10) represents program structure.(11-15) represents program structure
(diagram) structure.(0-5) clearly.(16-20)
/ 20
Commented The program is poorly commented The program has limited comments, but do The program has adequate comments, The program has good comments
program or comments do not relate to the not describe the purpose of the describing some of the purpose of the that clearly describe the purpose
purpose of the program.(0-3) program.(4-6) program (7-9) of the program.(10-12)
/ 12

Marker's
Comments 0
TOTAL MARK / 200

Page 6 of 6

Você também pode gostar