Home Solutions Links About



9 November 2008

fox and hound

This game was inspired by a game I found in LEGO's NXTLOG site. I decided to build a game for presentation on NXTLOG using only the parts found in one retail Mindstorms set (8527). Most of the games in NXTLOG are largely electronic in nature but I wanted to build a mechanical game to get the best of both worlds - construction and programming. From these requirements Fox and Hound was born.

Front view of the game.




CONSTRUCTION

Most of the construction is straightforward but there are a couple of places where it is a bit fiddly. You should be able to build it in 45-60 minutes. I have generated two different instruction sets.
An .lxf file for Lego Digital Designer (LDD) is here. If you don't have LDD then it can be downloaded for free from here. LDD does not handle diagonal bracing well so there are two socket pins that have to be pushed in further than LDD indicates (see photos).
I also created a set of photographic instructions that are much easier to follow and these are at the following links:
Steps 1-10
Steps 11-20
Steps 21-29

Do NOT look directly at the LED when it is on. It is very bright. I strongly advise taping a small piece of paper over the LED (see inset in fox detail photo below).
PROGRAMS

Because this project was designed for presentation at NXTLOG my intention was to write the programs in NXT-G. Alas NXT-G does not play well with large programs. At the point where I started to add blocks to a sequence beam for the music, NXT-G crashed every time I tried to compile the program. Another way had to be found and I turned to NXC. This allowed me to write a larger program that, amazingly, compiled to a far smaller file than the smaller NXT-G program.

You will need both of the NXT-G (.rbt) programs. If you want a better game program that includes music plus an extra menu to select the music volume then you will also need the NXC (.nxc) program. The programs can be imported from the following links:
FH-set.rbt(1.6MB) Setup program
FH-game-G.rbt(7.3MB) The game program
FH-game-C.nxc(10KB) The better game program

If you wish to use the NXC program you will need to import and install BricxCC from Sourceforge. My program runs with the standard Lego firmware so you won't need to install the enhanced firmware available from the site. You will use BricxCC to compile and load the NXC program onto the NXT brick. If you are more adventurous, you can learn to write your own NXC code. Although more difficult to learn than NXT-G the effort is well worth while as it will free you from some of the less desirable characteristics of NXT-G.

Some words of CAUTION! The FH-game programs use some of the graphic files from NXT-G. I have not worked out how to load them in BricxCC so you will have to load and run the NXT-G version of the game at least once to ensure the graphic files are on the brick.

The programs take up a lot of NXT memory. FH-set:11.2KB, FH-game-G:39.0KB, FH-game-C:10.4KB, total graphics:0.9KB. You may need to delete some files in order to fit the programs in. If you have the required free space but the load process tells you there is insufficient memory, then the NXT memory is probably fragmented. To defragment the memory, click the "NXT Window" button then the "Memory" tab and then the "Delete All" button.

If you are using the USB cable to export programs to the NXT brick be sure to remove the cable from the brick before you start the programs.
SETTING UP THE GAME

Before you start the game, both the fox and the hound must be set to their start positions. For both, the start position is to have the supporting arm horizontal on the left side (see photo at left). There are two ways to achieve this. The hard way is to manually rotate the motors using the knob gear on each. The easy way is to run the program FH-set. Follow the on screen instructions to firstly set the hound then the fox. The speed and direction of each motor is controlled by the distance an object is from the ultra-sonic sensor (USS). You can use your hand but a hard flat object such as a book is far more reliable.

Each motor stops when the object distance is in the range 19-21cm (7.5-8.3"). From the stop position, moving the object towards the USS rotates the arm anti-clockwise with increasing speed. From the stop position, moving the object away from the USS rotates the arm clockwise with increasing speed out to a distance of 40cm (15.7") at which point the motor abruptly stops. At any distance greater than 40cm the motor is stopped. This prevents nearby objects that are in the USS range from unintentionally driving the motor at full speed. It also ensures that the motors remain off when no object is being held in front of the USS. CAUTION! Before starting the program ensure that no objects are closer to the USS than 50cm (19.7").
PLAYING THE GAME

Make sure that the fox and hound are both in their correct starting positions (see above).

Start the program FH-game-G or FH-game-C.

You will need to wait a few seconds while the program calibrates the motors. Each motor will run for a few seconds to determine the power required for the game. This allows for more consistent performance across a range of battery levels. During calibration the screen will display information as shown in the photo. When the calibration is complete the fox and hound will both return to the start position.
If you are playing the NXC version you will firstly need to select the music volume level from a menu (see photo). Move the pointer with the grey NXT arrow buttons and select the required level by pressing the square orange NXT button.

You will now need to select a difficulty level from a menu (see photo). I suggest you start with the easy level as the game is harder than it looks. Move the pointer with the grey NXT arrow buttons and select the required level by pressing the square orange NXT button.

The game starts by giving the fox a 5 second head start. When the LED starts to flash (and the music starts in the NXC version) you can move the hound by pressing the touch sensor. But BEWARE! The hound can only chase the fox when there is a scent (the LED is on). Any time the touch sensor is pressed when the LED is off the hound will move backwards!

The game ends in one of two ways. Either the fox gets home (the arm is horizontal on the right side) without getting caught or you catch the fox. The fox and hound then both return to the start position ready for a new game.

To stop the game you can press the dark grey rectangular NXT button at any time. A better method is to select the "Quit" option from one of the menus because this will park the fox and hound in the prefered parking position (arms vertical - see photo) before the program terminates. The vertical position places the least stress on the gears and axles. If you have aborted the game, you can move the arms to the vertical position using the FH-set program.
ABOUT THE DIFFICULTY LEVELS

The selected difficulty level may be used to affect any one of the following parameters: LED on time, LED off time, fox head start time, fox speed and hound speed. All but the hound speed are influenced by the difficulty in the game as presented. You can customise these parameters if you wish. The levels are defined as follows:

EASY
LED off: 1s
LED on: 2.5s
Fox headstart: 5s
Fox speed: as calibrated.

MODERATE
LED off: random 0.4-1.6s
LED on: 1.8s
Fox headstart: 5s
Fox speed: as calibrated.

HARD
LED off: random 0.4-1.6s
LED on: random 1.5-2.5s
Fox headstart: 6s
Fox speed: as calibrated + 3.

QUESTIONS & COMMENTS

If you wish to contact me in regards to this project my email address is on the "About" page.

PS
While testing the game, I experienced considerable difficulty in having the game terminate when the hound was level with the fox. I spent a lot of time checking the motor tachometers and my maths on the gear ratios but to no avail. Eventually I discovered the problem was the amount by which the hound axle twists while in the start position. This results in the motor rotation count having an error relative to the position of the hound arm. The fox did not have the problem because it's arm is not supported by an axle. How to solve the problem? A counter weight would do nicely but is not possible with the available parts and space. The other solution was to compensate in the program. If you look at the section where the position of the hound arm is compared to that of the fox, you will see that I have used a divisor of 63 for the fox (the drive train ratio is 1:63) but a divisor of 41 for the hound even though its drive train gear ratio is 1:45. The difference makes a reasonable approximation to deal with the axle twist error.