kent logo

CO538 Anonymous Questions and Answers

This page lists the various questions and answers. To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.

When asking questions, please do not simply paste in your code and ask what is wrong with it, as these types of question are hard to answer in a public forum (resulting in either no answer, or an answer which will only be of use to the person asking the question). In many cases, a question about code can be formulated in general terms. For example, if you have an `IF' block that results in an `incorrect indentation' error, you might ask, ``what is the correct syntax for an occam `if' statement ?''. Questions of this form are easier to answer, and are meaningful to all.

Questions that are not suitable for these public pages (i.e. those that contain assignment-specific code), should be mailed to your seminar-leader.

Question 61:

Submission reference: IN1058

Would I be right in saying that the only way to identify which philosopher is doing what is to do the reporting after this line:

  philosopher (left[i]!, right[i]!, down[i]!, up[i]!) 

in secure.college? My rationale being that this is the only way to identify each channel as we have access to the 'i' variable.

Answer 61:

No. It doesn't make much sense to try and do reporting in SEQ with the philosopher instance (which is part of a network of parallel processes). The philosopher process has a WHILE TRUE loop, so it won't terminate – nothing following in SEQ after it will ever run. Changing that loop into one that terminates means placing another loop around the philosopher invocation and your reporting process. Your philosopher then comes into existence and terminates repeatedly. This is not a nice way – it makes the code hard to understand (and is the sort of thing you normally end up programming C/C++/Java/etc.).

The only process which knows what a philosopher is doing currently is the philosopher process. Keep the philospher reports there. If you want each philosopher to be able to identify themselves, simply pass its index, i, as a VAL INT parameter to the philosopher procedure. You'll probably need to add some other things too – like a report channel! There is no way for the philosopher to report its actions at present (and deducing it from interactions with security and the forks alone would be complex – and probably wrong).

Keywords: coursework , q7

Referrers: Question 55 (2007)

Question 62:

Submission reference: IN1037

Hi, I've just got started on the assessment but I've come to a problem. Some of my code in my display process is:

    [11] CHAN INT x:
      ALT i = 0 FOR 11
        in[i] ? x[i]
	  print.stream(0, x[i]?, scr!)

As you can probably tell, I'm just trying to get the outputs working first before I make the animation. So, I'm printing using print.stream for now to debug.

However, the fourth line above is causing this error:

    Error-occ21-q7.occ(145)- I/O list item 1 does not match protocol

I can't work it out!

Answer 62:

The array 'in' is presumably a channel array from the display process header. You should input INTs from CHAN INTs — your code is currently attempting to input into another channel (x[i]), which doesn't make sense; hence the error regarding protocol mismatch. You probably meant for x to be an array of INTs – not CHAN INTs!

However, your use of print.stream is very wrong. That process runs forever, consuming numbers and printing them. So, after receiving its first input from channel in[i], it runs print.stream forever taking numbers from that same channel – assuming you plugged in that channel and not x[i], which is either a channel (as in your code, but which is wrong as there is no process outputting to it!) or an integer (which it should be, but is illegal here!). No data from any other channel would ever be taken.

I've no idea what numbers are arriving on your in[i] channels ... but if you just want to print them, just print them:

   ALT i = 0 FOR 11
     INT value:
     in[i] ? value
         out.int (value, 0, scr!)       -- print the number
         out.string ("*c*n", 0, scr!)   -- carriage-return and line-feed

Note that the above sequence prints one number (see out.int). Using print.stream would lock this process in to the channel and print the whole infinite series of integers that arrive.

Note further that it only makes sense to use an array of values (e.g. [11]INT x:) if you have some need to keep the last reported state from each channel. If you intend to handle them on an individual basis, just use a single locally declared variable (like value in my snippet).

I also question the use of the magic number 11 all over the place — name this as a VAL INT constant at the top-level somewhere.

Keywords: coursework , q7 , out.int

Question 63:

Submission reference: IN1051

Dear Sir, I've been trying to introduce a pause into my program but I'm getting an incorrect indentation error. I know I must have made simple mistake somewhere, but i can't understand why and where this error is. I'm just wondering if you could give a hand in getting rid of this error.

  PROC philosopher (CHAN BOOL left!, right!, down!, up!)
    ...  local variable declarations
      ...  local variable initialisation
        --{{{  think
          ...  random delay code
        --{{{  get permission to sit down
          down ! TRUE
        --{{{  pick up the forks
        PAR	    <----------- Error-occ21-q7Edited.occ(53)- incorrect indentation
          left ! TRUE
          right ! TRUE
        ...  more stuff

Answer 63:

Somehow you've managed to damage the existing contents of the WHILE loop. Removing the opened fold comments from your loop body leaves:

        WHILE TRUE
            ...  random delay code
	    down ! TRUE
	    left ! TRUE
	    right ! TRUE
          ...  more stuff

The error on the PAR is because you don't say whether this should run in parallel or in sequence with the SEQ above it. The problem is broken re-indenting of code, e.g. that PAR should be part of (indented inside) the SEQ, not alongside it.

Look again at the starter file code for philosopher (with all the folds open) and compare it with your code – there's no reason for code inside a fold to start at an indentation level different from the fold markers (which is what's happened in your code).

Keywords: q7 , coursework

Question 64:

Submission reference: IN1054

Hi, I'm working on the dining philosophers assessment but I'm not doing too well. I have attended the classes, seminars and most of the lectures but am still struggling. I understand what we are supposed to do and have a rough idea of how to do it, but i just don't know where to start. Can you give a rough outline of how to go about it, so i know what to do and in what order?

Also can you explain the following PROC? I understand the others given in the q7 starter file, but this one confuses me:

  PROC secure.college ()
    [5]CHAN BOOL left, right, up, down:
      security (down?, up?)
      PAR i = 0 FOR 5
          philosopher (left[i]!, right[i]!, down[i]!, up[i]!)
          fork (left[i]?, right[(i+1)\5]?)

Answer 64:

Starting with your second question, the secure.college process sets up a network of parallel sub-processes. If you look at the relevant lecture slides (available from the module directory on raptor, slides 36-39 of applying.ppt/pdf), you'll see a picture of the process network which this creates. It creates a PAR network containing one security and five each of philosopher and fork. Each philosopher has two channels connecting it to the security process, and two channels connecting to the forks on either side. The modulo operator (\) is used to wrap-around the channel connections -- e.g. the last fork (where i+1 is five), needs to connect to the first philosopher (the modulo 5 sets it to zero, which is the same index as the 0th philosopher's 'right[i]' channel (because i is zero).

With regards to starting the assessment, I'd begin by creating an outline for a display process which will take input from the various philosophers, forks and security (via an array of channels), and generating output to the screen. I would suggest having the display process outside of secure.college — and running in parallel with it, so there will be some channels connecting secure.college to display.

The next step would involve allowing the various philosopher, fork and security processes to output to the display. If you have modified secure.college to have a channel-array parameter, this means distributing those channels to the various processes — i.e. adding single-channel parameters to the processes which will generate output to display. From there, get those processes to generate outputs, which the display process receives. It might be sensible to start with simple INTs being reported to display, but to do any serious level of reporting you'll proably want to use a tagged-protocol.

Before coding, it's wise to start with a process-network diagram of what you're trying to code — design first, then implement! The wealth of q7 related questions from previous years will also be helpful.

Note: you say you have attended seminars and lectures. All the above has been presented – in detail – in the seminars and lectures.

Keywords: q7 , coursework

Question 65:

Submission reference: IN1059

Does the display process only need to take one array of channels from all of the the process that are reporting to it? If so then I assume this channel will be shared among the philosopher, fork and security procs?

Answer 65:

Yep, that's pretty much correct. But your second sentence is inconsistent with your first. Your "this channel" suggests splitting a single channel up amongst the various processes; whereas you talk about an array of channels in the previous sentence.

What you should do is give each of the philosopher, fork and security processes a single channel from within an array of channels – see slide 60 from applying.ppt. As described in the lectures, you can do it with a single channel – and it's much easier (especially for the display process, which then only has one channel to deal with). But that means using a SHARED channel and CLAIM blocks, as presented in slides 3-26 of shared-etc.ppt.

Note: there is some stuff relating to shared-channels in previous anon Q+A, but these use the old-style which involves SEMAPHOREs and explicit claim and releases (not particularly nice, but these were before the days of mainstream occam-pi).

Keywords: coursework , q7 , shared-channel

Referrers: Question 68 (2006)

Question 66:

Submission reference: IN1060

I'm just trying to work out the shared channel business and I have come up with a shared channel array of 26 'CHAN INT's. 15 for the philosophers: 1 for thinking, 1 for sitting and 1 for eating therefore 3 states * 5 philosophers = 15. 10 for the forks as two states (left, right) * 5 philospohers = 10. Finally 1 for the security to report on. Which ever channel I get an input on I then know what has happened and who by, is this a good way of doing it?

Answer 66:

It works, but I wouldn't say it's a good way. There are two pieces of information you're trying to communicate here: who is doing it, and what it is they're doing. Probably best to keep these separate. Having a single channel for each of the philosopher, fork and security processes (11 in total) makes sense — that tells you who is doing it. As for what they're doing, using a tagged-protocol would make sense — this makes that information explicit, and definitely makes it easier to modify — without having to rewire other bits of the network.

By the way, the forks have 3 states (on-the-table, picked-up-by-left-hand, picked-up-by-right-hand) – not 2.

Keywords: q7 , coursework

Question 67:

Submission reference: IN1040

Where do we submit the dining philosophers and robots?

Answer 67:

For the dining philosophers, submit your solution by placing it on raptor in the directory: /usr/local/proj/co631/dining/login/, where login is your login. If you have a network diagram, etc. submit these on paper via CAS.

For the robots assessment, you should submit your report on paper to CAS. Submission directories for your code will appear presently.

Keywords: coursework

Question 68:

Submission reference: IN1061

With reference to answer 66, I take it the 11 channels and the tagged protocol are combined in some way? Otherwise the 11 identifying channels would be useless? What would the syntax be for something like this. You may have noticed I'm finding this extremely difficult!

Answer 68:

Each channel in the array of 11 (= 2*nPhils + 1) channels has to carry the same protocol. That could simply be a BYTE code, but better would be a variant (also known as tagged or CASE) protocol – as explained in the seminar groups and the lecture on variant protocols (slides 63-71 of protocol.ppt).

As mentioned in Question 65 (2006), an even better and simpler solution is to use a single SHARED channel carrying a variant protocol (same as for above, but enhanced to carry the philosopher and fork id so that the display process knows who is sending – previously, the display could work that out from the channel index of the arriving message). This also was explained in the lecture on shared channels.

A slightly alarming observation is that it is very rare to see students taking notes during lectures. In the lectures mentioned above, how to use the introduced mechanisms for this assignment was discussed. That information is certainly not in the course slides! So, those students present and not taking notes will have had to remember or work it out again for themselves – so much extra work, :(.

Of course, those students not present at the lectures or seminars will have all the design and implementation mechanisms to create. Please come along to lectures and seminars and terminal sessions – it does make sense ...

Question 69:

Submission reference: IN1062

Hi, I asked the Question 57 (2006). Do mean you that I must have a SHARED CHAN MESSAGE report! parameter within the header of the SECURE.COLLEGE process? Currently, I have the SECURE.COLLEGE process like this:

    PROC secure.college (CHAN BYTE out!)
      ...  declare report channels plus the rest
      ...  run the phils, forks, security guard and display processes in parallel

I think it is right, but I am not sure there is a wiring problem within this process or not.

Answer 69:

Ah – you included the display process within the college. That's not what was recommended in the seminar groups or the lecture (see slide 60 of applying.ppt). To do that, the college needs the report channel as its parameter, not the screen channel.

The system is much better engineered by keeping the display process separate from the college. Then, to change the look-and-feel of the model, we just have to change the display process and we can leave the college process alone. We can even bring user interaction into the model by contolling the display. This brings all the benefits (software engineering, reuse, high cohesion and low coupling) sometimes claimed for object orientation (e.g. the model-view-controller pattern) without any need for inheritance – it's easy and it actually works!

Your secure.college looks good. Are you getting screen output yet? If not, check that you connected your secure.college to the top-level screen! channel ...

Question 70:

Submission reference: IN1043

For the wall following assessment, what files are we meant to include? Currently I just have vehicles.inc, but I'm guessing there might be others ... ?

Answer 70:

For programming the wall follower, you'll probably need the processes introduced in your early exercises with the robodeb material – for example, those for gathering the laser range finder data, finding the min or max of these, etc. To get those processes, include the files you used then. You may find the following URLs useful (of course, you do already know about them!):


    (look for the link: "All You Need Is Love")

Maybe you are asking about the files to submit for assessment? The handout for the robotics assignment is at:

    (look for the link: "Experimental Wall Following")

This indicates that the majority of your course marks will come from your lab writeup. While this may seem "different" or "uncommon," we are more interested in your writing and reflection on your code than just the code itself. (However, you will need to submit your code along with your report.)

You were encouraged to keep notes as you explored the problem of wall following, and collect data on your robot's ability to follow a variety of wall types. You should have analyzed this data (which may mean you charted it, or perhaps you counted events in the data, or performed some other kind of defensible analysis) and then made changes to your robot's wall following algorithm based on your analysis of that data.

Your lab report would (ideally) include code for your initial solution, your data, your analysis, and your improved code based on your analysis. It might close with some reflection on the process, and potential improvements you could make to both the data collection/analysis process and/or the algorithm itself.

This shouldn't be too surprising, we hope, as it was discussed in the lab as well as in the lab handout.

Keywords: coursework , robodeb

Question 71:

Submission reference: IN1086

I'm having some difficulty outputting what's going on, I've tried using the below code to output what the philosopher is doing and what philosopher is doing it. However, currently nothing is coming out.

I have three constant which are thinking, eating and waiting of int values 1, 2 and 3, these ints are set in the philosopher PROC then output to print.stream along with which philosopher it is (i). Can u give me any help with this please?? :(

    PROC secure.college ()
      [5]CHAN BOOL left, right, up, down:
      [5]CHAN INT status:
      [5]CHAN BYTE screen:
        security (down?, up?)
        PAR i = 0 FOR 5
	    philosopher (left[i]!, right[i]!, down[i]!, up[i]!, status[i]!)
	    fork (left[i]?, right[(i+1)\5]?)
	    print.stream (10000, status[i]?, screen[i]!, i)

Answer 71:

Stop, stop, stop, stop using print.stream ... that prints a single stream of integers to a single screen channel ... it was only ever of use in questions 1 and 2 ... it has absolutely no use for this assignment!

Your secure.college process above has no (channel) parameters – so there is no way it can get any results out anywhere, let alone to the screen.

You have attached status channels carrying integer codes: one from each philosopher – that's reasonable (though a variant protocol would be better). But each of these status channels is then connected to its own print.stream process which outputs to its own screen[i]! channel. That tries to send ASCII text down that channel – but none of those channels are connected to anything! Thus, each print.stream blocks which means that each philosopher blocks ... which means the whole system deadlocks (the forks and security are waiting to hear from philosophers).

As shown in slide 60 from applying.ppt and discussed in the lecture and in seminar groups, those status channels should be external output channels (i.e. parameters) from your college and there should be a display process, running in parallel with the college, that multiplexes in all the status channels and generates (animation) text to the screen. You also need 5 more status channels from the forks in the college, plus one more from the security guard.

Keywords: q7 , coursework

Referrers: Question 75 (2006)

Question 72:

Submission reference: IN1071

In question 70 I was asking more about #INCLUDE files. I currently have "player.inc" and "pioneerutils.occ" included, but wondered if there were any others I should be using, or whether I should use these in the first place?

Answer 72:

You may use them. They are documented more fully at:


Follow the links to the documentation on that page. We do not believe your solution requires these libraries, but there is ample documented code if you wish to make use of them.

Keywords: robodeb , coursework

Question 73:

Submission reference: IN1072

With the wall follower, is it meant to follow a wall on just one side? If not, how do we make the robot decided which to follow if there are walls on both sides that it can detect?

Answer 73:

This is a good question. (Actually, almost all questions are good questions, if you've thought about it before asking it. But I digress already.)

Were this an assignment that was primarily focused on your ability to control robots in the wild, we would obviously want your robot to be robust to these kinds of things. That is, we would expect to be able to put it in a hallway, set it running, and have it "figure out" what to do.

In this case, we gave you several environments where the robot is always to the left of the wall – or, if you prefer, the wall is always on the right. You may, for this assignment, make that assumption. In fact, I think we explicitly encouraged this in lab.

The point of the exercise is to go through a process – in this case, an experimental process where you implement an algorithm, collect data on its behavior, analyze and reflect on that data, and then based on your reflections, update your algorithm appropriately. We are not concerned with whether it is the worlds most elegant wall-follower – we're more concerned that you've gone through a critical aspect of the software engineering process, which is the ability to design, implement, analyze, reflect, and repeat.

Hopefully, that helps somewhat. If not, please feel free to ask more questions or make an appointment / mail us directly as necessary.

Keywords: robodeb , coursework

Question 74:

Submission reference: IN1074

I've researched the robotics assessment and I found it would be a good idea to know (by experimentation or other means) the distance between the wheels (or tracks) on the robot, to work out the rate of turn. However, after talking to one of the supervisors I thought I was maybe going down the wrong path?

Answer 74:

Wow! That's impressive; yes, you might want to know that ... but perhaps you're working too hard?

The model is accurate, so that means the wheelbase is roughly 0.3m. You can look at the specs for the ActivRobots Pioneer3 on the WWW:


I don't want to discourage you from good investigations, but I'm not 100% positive you need to go down this path to address the question. That said, if you'd like to, you are welcome either to:

  1. find the information on the website; or
  2. make your best educated guess (note that the robot is to scale in the simulator)

So I hope that helps; it certainly isn't a question we anticipated.

Keywords: robodeb , coursework

Question 75:

Submission reference: IN1092

I asked Question 71 (2006) a few minutes ago, it was very helpful. I've altered my program and now I have an output, I'm using one shared channel. So far the security guard and the phils are sending information down it. Phils 0 and 1 seem to be getting all the attention of the security guard now though.

I can't see how my display proc would cause this discrimination but thats the only proc I've added, and I haven't even altered anything else that much yet!

Sorry to include so much code, but I can't see how else to show you what's going on ...

    ...  PROTOCOL status

    ...  PROC display (CHAN status in?, CHAN BYTE out!)

    ...  PROC q7 (CHAN BYTE keyboard?, screen!, error!)

where q7 runs the college in parallel with a display process connected by a single channel carrying the status protocol, shared by all the college processes at the writing end.

Answer 75:

Sorry, I've edited out most of your code in your question. Your system now has a good structure. I don't know why you aren't seeing phils 2 through 4 getting past security – you didn't submit all their codes. But we couldn't answer it even if you had. I'm afriad this is not a debugging line ...

Keywords: q7 , coursework

Question 76:

Submission reference: IN1089

For the wall follower, can we assume that the robot will be placed in laser and/or sensor range of the wall? And will it be orientated any particular way, or does it need to orientate itself?

Answer 76:

Yes. Initially the worlds created for the assignment (Straight Wall, Circular Wall, Ninety Wall) starts the robot in sensor range of a wall and with the wall to its right (*I think*). You can assume that the robot will always start up in this position. When you run the robot yourself you might have to move the robot back to this position inbetween runs, either by moving the robot with your mouse or by quitting and restarting the simulator.

You are of course welcome to implement (as a challenge) an algorithm for your robot which can find a wall, when none are in sensor range. For example, just move in a straight line till you see something, assume it's a wall and follow it.

In case you missed the relevant terminal class, to get the worlds for this assignment, change to your home directory (on the Robodeb VM) and do:

    curl -O http://www.cs.kent.ac.uk/people/rpg/mcj4/20070222-co631.tar
    tar xvf 20070222-co631.tar

Now, under... (mercy, I don't have the environment to hand, because I'm in another country)... There's a "BeanCommander" or ... ah! "Commando". It adds some options to launch Stage worlds. (Make sure Stage, the simulator, is not running before doing this.) The worlds "Ninety Wall", "Circular Wall", and "Straight Wall" are the choices for this exercise.

Keywords: robodeb , coursework

Question 77:

Submission reference: IN1090

I want to use the sonars to detect walls, but I don't get how we access one individually, even after reading:


Is there some easy way to say get the two right sonars, and the numbers that they generate? Thanks.

Answer 77:

You need to use the CHAN SONAR channels from the (various kinds of) brain.stem process and procs like get.min.S. To access these, we just need to have:

    #INCLUDE "player.inc"

at the start of our source code.

Having received a SONAR value from one of those channels (in.sonar below), you can access individual elements by subscripts (e.g. stuff[3]). For example:

    INT special:
    SONAR stuff:
      in.sonar ? stuff
      special := stuff[3]
      ...  etc.

This works as the SONAR type is actually a renaming of an array of integers type. To get the left and right sonar values, we can write:

    INT sonar.left, sonar.right:
    SONAR stuff:
      in.sonar ? stuff
      sonar.left := stuff[0]
      sonar.right := stuff[7]
      ...  etc.

Keywords: robodeb , coursework

Question 78:

Submission reference: IN1107

How do I get square root in occam?

Answer 78:

Something like this:

  REAL64 x:
    x := DSQRT (64.0)
    out.real64 (x, 0, 0, scr!)

or, if you're using 32-bit floats:

  REAL32 x:
    x := SQRT (64.0)
    out.real32 (x, 0, 0, scr!)

The two integers (0 and 0 here) specify the number of integer places and number of decimal places — 0 means "as many as required".

Keywords: coursework , libraries

Question 79:

Submission reference: IN1106

How far apart are sonars 7 and 8? Thanks

Answer 79:

The dimensions of the simulated pioneer robot and the configuration of its sensors is defined in the pioneer.inc file (provided by the Stage simulator). On RoboDeb, the file is located here: /robodeb/local/share/stage/worlds/pioneer.inc.

Following is the relevant extract from the file:

  # define the pose of each transducer [xpos ypos heading]
  spose[0] [ 0.075 0.130 90 ]
  spose[1] [ 0.115 0.115 50 ]
  spose[7] [ 0.075 -0.130 -90 ]
  spose[8] [ -0.155 -0.130 -90 ]

I believe that the unit of xpos and ypos is meters (presumably offset from the centre of the robot). The rest of the dimensions of the robot can also be found in pioneer.inc.

The laser rangefinder is not defined in this file, but rather in: /robodeb/local/share/stage/worlds/sick.inc.

Keywords: coursework , robodeb

Question 80:

Submission reference: IN1111

Is inverse tan anywhere in the libraries?

Answer 80:


    REAL32 FUNCTION TAN (VAL REAL32 v)     -- tangent (single precision)
    REAL64 FUNCTION DTAN (VAL REAL64 v)    -- tangent (double precision)

    REAL32 FUNCTION ATAN (VAL REAL32 v)    -- anti-tangent (single precision)
    REAL64 FUNCTION DATAN (VAL REAL64 v)   -- anti-tangent (double precision)

To use them, you'll need to import and link the relevant math library:

    #USE "dblmath.lib"
    #USE "snglmath.lib"

By the way, you can quickly find these functions by grepping the Inmos math-library sources, which are in KRoC distributions. There's not much documentation unfortunately. All the trig functions work in radians, of course, not in degrees. For example, ATAN(1) is pi/4 radians (i.e. 45 degrees).

To link in the above libraries, you must extend the occPlug "Libraries:" option – currently you're probably using "course". To do this:

Here's one I wrote:

    #USE "dblmath.lib"
    #USE "snglmath.lib"

    #INCLUDE "consts.inc"
    #USE "course.lib"

    PROC atan (CHAN BYTE keyboard?, screen!, error!)
        REAL32 x, y:
          x := 1.0
          y := ATAN (x)
          VAL INT pi.1000 IS INT ROUND (4000.0 * y):
            out.string ("pi**1000 = ", 0, screen!)
            out.int (pi.1000, 0, screen!)
            out.string ("*c*n", 0, screen!)
        REAL64 x, y:
          x := 1.0
          y := DATAN (x)
          VAL INT pi.1000 IS INT ROUND (4000.0 * y):
            out.string ("pi**1000 = ", 0, screen!)
            out.int (pi.1000, 0, screen!)
            out.string ("*c*n", 0, screen!)

which produces:

    pi*1000 = 3142
    pi*1000 = 3142

which are the correct answers, :).

Keywords: libraries

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:23 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.