XML

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 41:

Submission reference: IN1840

Does occam have a feature similar to C macros?

Answer 41:

No! C macros are the work of the devil. What is it that you are trying to do?


Question 42:

Submission reference: IN1842

I'm currently working on my occade animations in Q7, having done all of the basic stuff (I think!). The number of warnings I'm getting has gone up considerably, whilst the program still works fine. Some of them are probably quite trivial and easily solved, so I'm pretty sure I could reduce the number.

If I ignore my warnings and complete the animation, and run out of time to go back and address the warnings, will it affect my mark?

Answer 42:

Try to clear them up ... but we know that the compiler is over-cautious and issues many warnings on code that a deeper analysis would show is safe. But that's what warnings are for: to draw your attention to things that it (the compiler) is unsure about, leaving you to check their safety yourself. A lot of this happens, I'm afraid, when compiling some of our library codes! You can certainly ignore those warnings.

So, no. Warnings issued by the compiler on your code will not lose you marks – so long as the things it is warning about are really OK.

Keywords: q7


Question 43:

Submission reference: IN1843

How's the effect of moving the characters (philosophers, forks, ...) achieved with the co-ordinate arrays?

Answer 43:

See Question 68 (2000) and Question 104 (2004) (and other questions and answers under the cursor and animation keywords).

Keywords: q7 , cursor


Question 44:

Submission reference: IN1845

I've managed to do the dining philosophers but I'm worried about whenever I think about ? and ! it takes far longer than it should. It like takes around 20 secs per item. My thinking is if you have independent processes, you think about them from the view point of the process. However, then when you have processes within processes, I then get confused. Internal channels don't need direction specifiers because it is a pipe. But matching the process header with the call etc. Particularly, with external channels, what you would consider the writing end, is often the reading end etc...

Is this normal or do you know the answer instantly?

Answer 44:

As you said, processes should be considered from their own point of view – process orientation!

Let's assume here that by process we mean something defined by a PROC declaration.

External (i.e. parameter) channels to which the process outputs (!) messages often have names containing "out", "write", "to" or "send". External channels from which the process inputs (?) messages often have names containing "in", "read", "from" or "receive".

[Aside: it's safer to use the terms write and read, rather than out and in. From the point of view of either a process or a channel, the writing end of the channel means the same thing. However, the outputting end of a channel from the point of view of the process doing the output is the inputting end of a channel from the point of view of the channel! And vice-versa. Note that send and receive are safe names ... as are to and from. When in doubt, use names from the point of view of the process. Better is to use terms that are unambiguous (like write/read or send/receive).]

The writing (!) end of a channel remains the writing end whether you think about it from the point of view of the the process body (i.e. as a parameter) or the network builder (i.e. as an argument to plug into a process). So does the (?) end.

When building a network (e.g. for the implementation of a PROC body), full channels will be declared (i.e. not qualified by ! or ?). When plugging channels into processes, plug !-ends into !-parameters (i.e. writing or sending channel parameters) and ?-ends into ?-parameters (i.e. reading or receiving channel parameters).

Simple! :)

Keywords: q7


Question 45:

Submission reference: IN1846

I'm trying to get my fork process to FAIR ALT over its left and right input channels. I know how to do this with an array of channels, but I'm not sure how to do it with 2 channels not in an array. Can you give any hints?

Answer 45:

See Question 62 (2007).

Keywords: fair-alt


Question 46:

Submission reference: IN1844

Hello, I'm trying to animate my dining philosophers project with occade, and thus far it's going well (I've got a background showing!). However, I'm very curious as to how the sprites work. My understanding of sprite images are ones where the entire image is broken down into a grid of squares, and as you progress through the lines of squares the image in each changes slightly - and then the program reads these in showing them in rapid sequence, thus appearing to be animated.

I couldn't find any information about this in the occade documentation or on any other occade anon q/a's (there's only 2 =( ). The documentation describes the way to load in the image and show it, but nothing about controlling the animations within the image or what the grid size was in the image or anything, so I hope it would somehow automatically figure that all out itself, but upon trying it, it just plastered the entire image on top of my background where I positioned it.

I was wondering if I could get hold of any examples of sprites files, and the code of them being animated, so I can see how it is done? I can't find any information anywhere else! :(

Cheers.

Answer 46:

Adam Sampson (ats@kent.ac.uk) writes ...

Your understanding of sprite images is not right – a sprite is just a moveable image that can be displayed against a fixed background. Older machines had dedicated hardware to draw sprites; these days we do the same thing in software. You can use sprites to implement flipbook animation as you describe, but there's nothing that says sprites have to be animated, nor that the images have to be contiguous in memory.

There's a good Wikipedia article on sprites and what sorts of hardware support different machines had for them.

The machine I had in mind when designing Occade originally was the Atari 2600, which had hardware support for drawing sprites. On the 2600, if you wanted to animate a sprite in your game, you'd just upload each new frame of the animation to the graphics chip as the appropriate time was reached. To do animation in Occade, you can use exactly the same approach -- whenever you want to move to a new frame of animation, send the sprite a load request with the new frame you want it to display.

The easiest way is to save each frame of animation to a separate file. In the Parrot Attack example game, there are four frames of animation for the parrots (two facing left, and two facing right), and PROC alien calls PROC set.alien.shape to change to the next frame each time a timer expires; this just uses a CASE statement to pick which of several images to load.

But let's suppose you've drawn an animation with lots of frames, so you want to put them all in one big file, like you suggested. To do this, you need to use occam-pi's RASTER data type, which represents an image; the standard library rasterio.module, which lets you load images from files into RASTERs; and the sprite's load.raster request, which makes it set its image from a RASTER. Since RASTERs are really just (mobile) arrays of pixels, you can copy data around between them however you like -- so you can copy the frame of animation you want out of the big image into a frame-sized RASTER, and then use that frame to set the sprite's image.

Sound complicated? Well, sort of, but the code's not too bad -- although it needs to use some occam-pi facilities (notably mobile arrays) that you probably haven't seen yet in CO538. Here's a working example, that expects a 320x32 image called "images/numbers.png" containing ten 32x32 frames arranged in a horizontal row:

    #INCLUDE "occade.module"
    #INCLUDE "rasterio.module"
    
    -- The size of each frame.
    VAL INT FRAME.WIDTH IS 32:
    VAL INT FRAME.HEIGHT IS 32:
    
    PROC my.sprite (SHARED OCCADE! occade)
      OCCADE.SPRITE! sprite:
      RASTER image, frame:
      INT num.frames:
    
      SEQ
        -- Start the sprite.
        occade.start.sprite (occade, sprite, -1)
    
        -- Load the image into a RASTER.
        read.raster ("images/numbers.png", image)
    
        -- Work out how many frames we loaded.
        num.frames := (SIZE image[0]) / FRAME.WIDTH
    
        -- Create a new frame-sized RASTER. (A RASTER is really just a mobile 2D
        -- array, with the outer dimension being the Y axis.)
        frame := MOBILE [FRAME.HEIGHT][FRAME.WIDTH]INT
    
        INITIAL INT frame.num IS 0:
        WHILE TRUE
          SEQ
            -- Copy the appropriate frame out of the loaded image.
            VAL INT x.offset IS FRAME.WIDTH * frame.num:
            SEQ y = 0 FOR FRAME.HEIGHT
              SEQ x = 0 FOR FRAME.WIDTH
                frame[y][x] := image[y][x.offset + x]
    
            -- Set the sprite's image from the frame.
            sprite[req] ! load.raster; frame
            sprite[resp] ? CASE return.raster; frame
    
            -- Put the sprite in the middle of the screen and make it visible.
            sprite[req] ! move; 320; 240; TRUE
            sprite[req] ! visible; TRUE
    
            -- Move to the next frame number (wrapping round at num.frames).
            frame.num := (frame.num + 1) \ num.frames
    
            -- Wait for a bit.
            occade.delay (100000)
    :
    
    PROC main (CHAN BYTE keys?, scr!, err!)

      SHARED OCCADE! occade:
      INITIAL OCCADE.PARAMS params IS occade.default.params:

      SEQ

        params[width] := 640
        params[height] := 480
        occade.start (occade, params, "Flipbook animation demo")
    
        my.sprite (occade)

    :

This will not be in the exam!

It's only fair to warn you that there are some caveats with using rasterio.module instead of getting Occade to load your images for you: rasterio doesn't support BMP format images, only PNG, and it doesn't work on the Transterpreter at the moment.

The source code for Parrot Attack and the other examples, along with some example images including the one for the code above, are available online here.

Keywords: occade

Referrers: Question 35 (2011)


Question 47:

Submission reference: IN1847

I'm having a little difficulty understanding tag load.text in the Occade protocol SPRITE.REQ.

The doc says:

    load.text; MOBILE []BYTE; MOBILE []BYTE
    Set the sprite's image by rendering text.
    
    Parameters:
    MOBILE []BYTE	text	String to render
    MOBILE []BYTE	font	Font image filename

I have no problem sending text to this, but I don't know what to set as the second parameter - this mysterious Font Image filename. Is this something I should be creating, or should there already be some samples available? If it's something I am supposed to be creating, is there any more information on what I should actually put in the file?

I have seen the following line in another question:

    sprite[req] ! load.text; buf; "images/font10x20.png"

But this doesn't seem to work in the Transterpreter. I seem to remember reading somewhere that only BMP will work ... in which case the sample code in that question seems a little misleading.

Answer 47:

Adam Sampson (ats@kent.ac.uk) writes ...

Font image files are described rather briefly at the top of the Occade documentation page:

"Font image files, used for text rendering, must contain a 16x16 rectangular grid of characters. The font size will be computed automatically from the image size."

There's one (modules/occade/examples/images/font10x20.png) included in the KRoC distribution; it's used in several of the Occade demos. You can download it directly here, along with various other possibly-useful images.

As you say, if you're using the Transterpreter, then you won't be able to load PNG images, but BMP will work; you can use any image editor to convert it, or download a BMP version directly from here.

If you'd like to make your own font, the way I produced the image was to insert the characters I wanted in a terminal window (or text editor), and take a screenshot of it, being careful to crop it to exactly the right size. The characters are in ASCII code order, with 0 top left.

(I think PNG support for the Transterpreter has just become the most-requested feature in the KRoC libraries – we'll fix it!)

Keywords: occade


Question 48:

Submission reference: IN1848

I'm trying to move a string using but it keeps leaving a trail of the character behind:

    SEQ
      cursor.x.y (string[X], string[Y], screen!)
      SEQ i = 0 FOR 5
        SEQ
          out.string (":0", 0, screen!)
          screen ! FLUSH
          cursor.right (3, screen!)

Answer 48:

You have to erase the string-icon (by writing spaces where it used to be) just before you write it in the next position (and FLUSH).

You also need to leave a decent time interval between each move – say 1/20th of a second ... but experiment!

Keywords: q7

Referrers: Question 49 (2009) , Question 49 (2009)


Question 49:

Submission reference: IN1849

In Question 48 (2009), you answered:

"You have to erase the string-icon (by writing spaces where it used to be) just before you write it in the next position (and FLUSH)".

I'm sorry but I don't understand what you mean. Could you explain further? Sorry.

Answer 49:

For instance:

    VAL []BYTE icon IS ":0":                        -- 1-D (horizontal) icon

    SEQ
      cursor.x.y (string[X], string[Y], screen!)
      SEQ i = 0 FOR 5
        SEQ
          out.string (icon, 0, screen!)
          screen ! FLUSH
	  pause (50000)                             -- 1/20 second
	  cursor.left (SIZE icon, screen!)          -- move cursor back
	  out.ch (' ', SIZE icon, screen!)          -- erase icon
          cursor.right (1, screen!)                 -- next icon position
      screen ! FLUSH

Note: in the above, the icon moves right by 1 position in each cycle. In your code in Question 48 (2009), your icon moved right by 3 places each cycle (leaving a trail).

If you do this in the standard display process, only one icon will be animated at a time. For parallel icon animations, you will need parallel animation processes writing to a fairly dumb display process over a SHARED channel.

With the assessment due today, you probably don't have time to bother with parallel animation! For future work, take a look at the shared_screen module.

Keywords: q7 , animation

Referrers: Question 33 (2010) , Question 50 (2009)


Question 50:

Submission reference: IN1851

Hi there, I'm currently doing my animation for dining philosophers, and I'm trying to make the animations happen in parallel, but I can't figure out how to do this.

I have a case statement that reads in the reports on the report channel, then depending on what comes in, does the animation. But until the animation finishes, I can't finish the CASE to get the next command in to animate that.

Is there someway to get the CASE to loop round and start dealing with the next report while the body of one of the case commands is still running? Or if not, any other suggestions about how to deal with this problem? Thanks.

Answer 50:

As you say, you can't do this with a single display process. See the last two paragraphs of the answer to Question 49 (2009).

Keywords: q7 , animation


Question 51:

Submission reference: IN1850

For life on mars, I'm trying to work out if we need lots of headache-y non-determinism. It says, interplanetary internet is minutes/hours delay. So we could assume that turn 20 will complete. In fact, it says it should return move complete or hazard detected. However, somewhere further on it says commands override the previous - preventing arc turning. I would find it much easier if we made each command complete before any further, but I presume you may wish to overwrite a long command like find.blob with a turn on the spot (or possibly not because that would prevent the return of blob.not.found etc.).

Answer 51:

Carl Ritson (msl9@kent.ac.uk) writes ...

I assume this is a reference to: "each new motor command overrides the previous mode". That statement describes the behaviour of the motor command stream output by your robot.control process, not the commands sent to it from its operator (back in mission control).

Your robot.control process only needs to deal with one operator command at a time (turn, move, find.blob, etc). There is no need to deal with the present command being overridden; no further commands will be issued until the present command completes and returns its response to the operator.

Keywords: mars


Question 52:

Submission reference: IN1854

You've stated before in previous answers (Question 36 (2008)) the acceptable tolerance of turning (e.g. turning 91 instead of 90), but what tolerance would you accept for moving? Would this be the same?

Answer 52:

The numbers coming back on the motor.feedback represent either degrees turned (if your command was to turn) or millimeters moved (if your command was to move). The web page for this exercise says: "You can’t (and shouldn’t) rely on these ticks being a fixed value anywhere in your code." If you look at these numbers (e.g. by using the log channel), you will see that they are not just 1 or -1, though they do seem to be constant. However, you can rely neither on the particular values being reported nor their constancy – the robot is a long way away and in an alien environment and motors and sensors will wear down.

So, overshoot on both turning and moving is not preventable, but it must be kept to the minimum possible.

Keywords: mars

Referrers: Question 58 (2009) , Question 56 (2008)


Question 53:

Submission reference: IN1853

Is it possible for an implemented example to be made available for life on mars (like you did with dining philosophers), so we can see how the program is meant to work?

Answer 53:

OK – copy all the files on raptor from \courses\co538\answers\mars-transterpreter\. Read the README.txt file.

Keywords: mars


Question 54:

Submission reference: IN1852

What is this error meant to mean (or is it a buggy error)?

  Error-occ21-q7.occ(232)- expected "?", "??", "!" or ":=", found ":="

Answer 54:

Please send me (phw) the code that produces this!   Thanks.

Keywords: compiling


Question 55:

Submission reference: IN1855

Considering that the life on mars assignment is due in on tuesday, is there any possibility of knowing how to submit it yet?

Answer 55:

Submission directories will be set up in the usual place. This assignment is number 5 – hence, look on raptor (or swallow):

    \proj\co538\assess5\

They should appear some time tomorrow (Monday).

Keywords: mars


Question 56:

Submission reference: IN1856

My move command is not working, I'd appreciate it if you could hint/tell me why. Thanks.

    ....  code omitted

Answer 56:

Sorry! It says at the top of each of the Q&A pages: "When asking questions, please do not simply paste in your code and ask what is wrong with it ...".

Look at your code and ask: "Why should this code work?". Read through it line by line, noting everything that happens.

Two problems with your code are of general interest, so can be addressed here.

First: you only need to issue a motor.cmd (e.g. to move or turn) just once. That starts the robot moving (or turning) until you send a stop message.

Second: you do, of course, have to listen to the motor.feedback channel while it's moving or turning (i.e. in a loop) until you can deduce the move (or turn) is complete. However, if you haven't started to move (or turn), there will be nothing arriving down motor.feedback; so don't listen there before sending the move (or turn) command ... or you will wait forever!

Keywords: mars


Question 57:

Submission reference: IN1857

When looking at answers with key lifeonmars, the first one I saw was the one asking for an extension to thursday. I thought it was for us at first and was happy, but then I noticed this was a question from last year.

We all (or at least, all second year compsci students) had an assignment for co525 dynamic web due in today (which is worth 25% of the total marks for that module. 50% of the coursework marks).

Because of this it seems most people have prioritised that work since it was due in first and is worth a lot more in terms of marks, but has left us with less time for the final occam assessment. I, and most others I imagine, would be grateful for a little more time to do the occam to a standard we would be happy with.

If possible, could you give us the no-penalty re-submission extension to thursday? This is the last piece of coursework due in this term now so it won't interfere with any other deadlines (I speak for people on the same course as myself here, can't make assumptions).

Cheers.

Answer 57:

I have asked the coursework manager if this can be done. Watch this space for an answer ...

OK, an extension of 24 hours has been authorised (pushing it back further runs up aganist other deadlines). So, the submission directories will now remain open throughout Wednesday (16th. December, 2009).

Keyword Index: I've merged the keyword list lifeonmars into the mars list. Apologies for having two lists before!

Keywords: mars


Question 58:

Submission reference: IN1858

I notice for Question 56 (2008), you say that the person's code is probably wrong because ticks are expected to increment in single units.

However, I am having the exact same problem as the person that asked that question, where all my movement is 10mm at a time (and on the odd occasion, 20mm).

And for my turning, I always seem to turn 2 degrees at once (or occasionally 4).

I don't see where in my code there is any problem where I'm not taking the machine responses fast enough, and the fact it's dead on 10 or sometimes 20 suggests to me it's something else? otherwise I should expect to see values around say, 9-11 (however long it takes my computer to run the statements before I wait for a new tick again).

My code is like this (feel free to delete before response :) ):

    ...  code deleted, :)

Even if I comment out the debug print lines, I still move in chunks of 10 (tried moving 14, went 20).

Also, as a side question, what is the set tolerance for move distances? I'm aware for turning it's 5 degrees either way.

Answer 58:

The answer in Question 56 (2008) is, as someone once said about Watergate, non-operational.

The exercise does not specify what numbers (representing degrees of turn or millimetres of movement) are returned by the motor feedback channel. Please see Question 52 (2009) for an answer that is operational! This also answers your side question.

Keywords: mars

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:22 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.