Control is the process of using a computer to operate a machine of some kind. Control technology is used in a wide variety of applications. Many domestic appliances have small (dedicated) computers to control them. Many stills cameras have a computer which will have inputs from a light sensor and a distance measurement system, it will use this information to calculate the best exposure time and then control the shutter and iris opening. Many washing machines have computers which will control the speed of the drum motors, the water heaters and pumps. They follow a sequence of instructions depending on the wash cycle selected but adjust the cycle according to information from sensors about water temperature and levels. The Docklands Light Railway in London has all of its trains controlled by a series of computers. One controls the entire system telling trains when to start and monitoring their progress. Each train has its own computer responsible for adjusting the speed to keep to schedule, opening doors and giving passengers on board announcements. The computers communicate to keep each other informed of their current state. Modern aircraft are not flown directly by a pilot, instead the pilot gives instruction to the computer, the computer then controls the plane. The computer will not allow the pilot to make manoeuvres which might stress the plane too much. This enables planes to be lighter which increases their range.
There are many areas where control technology has not yet been perfected, areas such as driverless cars, automatic vacuum machines, robotic arms and video recorders which record the program you want!
In order for a computer to control a machine it must be connected to it. The information may flow from the computer to the machine, this is known as the Output. It may also have inputs, these are sensors which send information to the computer. The information may be about the position of an object, such as a robotic arm, or it may be from a sensor, such as a temperature or light sensor. The final part is the program. This is a series of instructions which tell the computer what to do in any particular situation.
The program is usually used in a language which looks a little like English. This makes it easier for humans, such as the programmer to follow. Although the language may look like English usually it is very restrictive. It is usually limited to a few hundred words each of which has a very precise meaning. The way in which the words can be used also has very strict rules, this is called the grammar (or syntax) of the language.
The normal English language is not used since it has too many words (there are around 70á000 in the Oxford dictionary) and not all words have a precise meaning eg tear.
This course uses a very simple language called COGS (COntrol language for G.C.S.E.). Programs in CLOGS (and in many, but not all, other computer languages) consist of a series of commands. These commands are carried out in order. One command is completed before the next is started. Sometimes decisions need to be made, to allow this to happen commands can be made to be conditional. An example of a conditional command is IF temperature < 40 THEN turn on heater. Sometimes the same set of commands need to be repeated a number of times. This can be achieved by using a loop. An example of this might be REPEAT go forward UNTIL wall is reached.
All of the control part of this course will be run as a simulation. This means that when a set of traffic lights are to be controlled you will not be connecting the computer to a real set of traffic lights, instead the computer will model, or simulate, the behaviour of a set of traffic lights. The same program which operates correctly as a simulation will work correctly when connected to a real output device. This method is often used when testing programs, it avoids damaging expensive devices if things go wrong.
Using COGS
Programs are written using a text editor called !Edit. A text editor is like a simple wordprocessor. Each command is placed on a separate line, blank lines can be included if required, no action will take place but they may make the program clearer to read.
Lines which start with a / will be ignored. This allows comments to be included, this is useful for explaining at the start of the program what the program does and within the program what is happening at specific points.
Programs are executed by dropping them onto !Control. This has two windows, one allows you to control what is happening. GO makes the program start, STOP makes the program stop executing, STEP allows just the next instruction to be executed and RESET makes the program go back to the first instruction. Also shown are the three current lines of the program. The top line is the previous instruction to be executed, the middle line is the instruction currently being executed whilst the bottom line shows the next instruction to be executed.
The second window shows the output from the program. It will not appear until the program starts to execute.
If the program contains a fault, such as a command which is not understood then the program will stop executing and an error message will be shown. The line number will also be shown. Moving back to !Edit and pressing f5 enables you to go directly to a particular line. The corrected version must then be 'saved' to !Control.
COGS understands the following words:
This section of commands informs !Control what output device is to be simulated. It opens the output window and draws the appropriate device.
traffic Traffic lights are to be used, two sets of lights are shown.
segment A 7 segment light is to be used, this is similar to a watch digit.
maze A Maze is to be used. The maze is always the same and a 'vehicle' is positioned at the starting position.
farm The farm plan is to be used . The farm is always a different shape and size. A 'vehicle' is placed at the starting position.
beacon The beacon is to be used. A beacon and a vehicle are placed at random positions.
This section of instructions indicate actions to take place.
left This turns the vehicle to the left by 90░
right This turns the vehicle to the left by 90░
forward This moves the vehicle forward one unit. forward can also be followed by a number (or a calculation) for example
forward 5 will cause the vehicle to move forward by 5 units
forward 4*3 will cause the vehicle to move forward by 12 units
lighton 3 This will cause light or segment number 3 to be turned on. lighton must be followed by a number from 1 and 8
lightoff 3 This will cause light or segment number 3 to be turned off. lightoff must be followed by a number from 1 and 8
wait 6 This will cause the program to pause for 6 seconds before going on to the next instruction. Wait must be followed by a number.
This section of instructions allow the order of statements to be changed.
repeat
command
command
until condition
if condition
then
command
command
else
command
command
endif
These are variables, they are not statements in their own right but can be used with the if and until statement
distance This gives the distance between the buggy and the beacon.
lefteye This gives a value depending on the light from the beacon reaching the left eye of the buggy.
righteye This gives a value depending on the light from the beacon reaching the right eye of the buggy.
beenthere This is TRUE if the vehicle has previously been to this part of the maze.
barrier This is TRUE if the vehicle has reached a wall of the maze.
forever This is always FALSE so can be used to loop for ever.
=, <>, <, > These can be used to compare two values.
Printouts
Loading the printer driver allows the program to be printed. Once loaded drag your final version onto the printer driver, it will then be printed.
Records of progress
The course work is assessed through written reports. These should be written as you perform the practical work, you should not write them up afterwards, contents is more important than presentation! The report should be divided into a number of sections, marks are awarded for each section. To achieve full marks you must complete each section. For control the following sections are required.
Description of the problem. Is control a suitable tool to help solve the problem? Can the task be broken down into a sequence of instructions. Sketch what is involved in the problem.
Planning. What is the basic strategy behind the way in which the problem will be solved?
Implementation. Give the listing of the program and explain the way in which it operates. Have you had to modify your first attempt and if so why?
Testing. Is it correct, if not do you know why not? How well is the problem solved? Does the solution always work? How efficient is the solution (in particular in the beacon problem how rapidly does the buggy home in on the beacon)?
Security. What steps need to be taken to ensure the data is not lost accidentally?
Evaluation. Has the problem been solved. Is it economically worth while using a computer and how would the problem be solved without a computer?
Implications. Are there any implications of using the computer as opposed to manual methods? You are only running a simulation, but how do you feel about driverless cars or aircraft without pilots? Traffic lights often use a computer to monitor the flow of traffic and to adjust the timing of the lights to meet traffic levels. Is this a good idea?
Maze
The purpose of this problem is to get you familiar with the system. You must issue commands to steer the vehicle through the maze. The first command in the program should be maze, this will draw the maze. You will then need to plot a path through the maze. The units are quite large, approximately the size of the vehicle. Other commands you will need are forward, left and right. The vehicle needs to be steered to the bottom right hand corner. The maze is always the same.
Farm
The aim is to produce a program to control a tractor which will plough a field. To do this it must go back and forwards across the field until the whole field has been covered. To be efficient the same part of the field should not be covered twice. The field is always the same shape but it is not always the same size so you will not be able to work out the route in advance as you could with Maze. The tractor has a sensor which allows it to detect when it is approaching a barrier and also when it has gone over a piece of land that it has previously covered. You will need to make use of the repeat until loop in order to solve this problem. The first command must be the word farm.
Traffic lights
With this problem you have a pair of traffic lights which you need to control. The lights need to be turned on and off in the correct sequence and should wait for a reasonable time. You will need to make use of lighton and lightoff together with wait. The first command should be traffic.
There are two sets of traffic lights. One pair, labelled A control the flow of traffic North/South whilst the other pair, B, control the flow East/West.
Both lights labelled A show the same at the same time, both lights labelled B also show the same thing at the same time.
You need to write instructions to control A and B. The lamp numbers are shown in the diagram to the right.
Segment
Many calculator and digital watch displays are built from seven segment displays. With these each digit is made up of seven bars. Each bar can be on or off. This allows the any digit to be displayed by turning on the correct combination.
The purpose of this problem is to get the display to count from 0 to 9 at one second intervals. Start the program with the command segment.
Each segment can be turned on or off by using lighton or lightoff followed by the segment number. Although they are referred to as seven segment in practice they usually include a possible decimal point. What letters of the alphabet can be shown on a seven segment display?
Beacon
The purpose of this problem is to make a buggy home in on a beacon. The beacon gives off light. The buggy is equipped with two light detectors. The closer the light detector is to the beacon the greater the value of its output. When the program is run the beacon and the buggy will be placed at random positions so you will need to write a program which is 'intelligent', that is it can find the beacon from wherever it starts. The first command should be beacon. This problem uses a different system of measurement to the farm problem. The units are much smaller. There are around 1000 units across the entire screen. There is a variable called arrived which is true when the buggy has reached the beacon. This can be used as part of a loop so you could say repeat..do something..until arrived. You will also need to make use of the output from the eyes so you can say things such as if lefteye > righteye then do something else do something else endif. You can also make use of distance which works out the distance the buggy is from the beacon. The aim is to get the buggy to reach the beacon as quickly as possible. This is quite tricky!