BrickHacks

8-bit robotics and the official home of the Lego Chevy 454 V-8

In memory of Dan Roganti

About, Notes, YouTube, Instagram



Programming the 9750 in Lego TC (Technic Control) Logo

American computer geeks of a certain age — perhaps 40-50 — associate Logo with their childhood scholastic memories of turtle graphics. I’m one of them: I am 43 (as of today: August 24, 2018) and Logo turtle graphics were my first exposure to computer programming in the fifth grade (1984-1985) using a Commodore 64. However, turtle graphics are only a subset: Logo is a powerful language. Most of my peers and I never had an opportunity to learn it: we outgrew turtle graphics and went straight to BASIC. For a good primer on the power of full-fledged Logo, I recommend watching Peter Neubauer’s lecture, Logo: History and Programming from the 2011 Kansasfest conference.

Lego designed TC Logo to automatically initialize the interface card, so no special code is needed to start programming in this language, unlike with BASIC (Apple/IBM). However if you’re using an Apple II and you put the card in any slot other than #3, then you must inform TC Logo of this change the first time you use the program. To do this: 1. Hold down the open-Apple key while booting the TC Logo disk; 2. Use the up/down arrow keys to select your printer, then press Return (or select any printer and Return to move on to the slot menu); 3. Use the up/down arrow keys to select your slot and press Return. Then you’re in the normal TC Logo startup screen. Press the Return key again to start programming.

I cannot teach you the entirety of Logo programming. You should download and print out the TC Logo reference manual from section (2)(B) of Lukazi’s blog post. You also should download and print the Apple Logo II manual: many of the commands don’t apply to TC Logo, but it teaches you the syntax and orders-of-operations which are different than expected if, like me, you have a BASIC background. I learned that lesson the hard way! (Note: I believe the II in its name is simply a reference indicating it’s the Apple II version of Logo, vs. versions for other computers. It is not Logo II, which is entirely different, obscure, and I’m not covering it despite it being sanctioned by Lego.)

First you must learn the fundamentals of operating the TC Logo shell. When you start it up, you'll be in the (to be continued...)

Now you can write a program. Here is my TC Logo code for the forklift robot.

TO ROBOT
NAVIGATE
FORKLIFT
ROBOT
END

TO NAVIGATE
IF (AND (PADDLE 1)>75 (PADDLE 1)<175 (PADDLE 0)>75 (PADDLE 0)<175) [TTO [A B] OFF]
IF (PADDLE 1)<75 [GOFORWARD]
IF (PADDLE 1)>175 [GOBACK]
IF (PADDLE 0)<75 [TURNLEFT]
IF (PADDLE 1)>175 [TURNRIGHT]
END

TO FORKLIFT
LISTENTO 6
IFELSE SENSOR? [TTO 4 OFF] [LIFTDOWN]
LISTENTO 7
IFELSE SENSOR [TTO 5 OFF] [LIFTUP]
END

TO GOFORWARD
TTO [A B] SETEVEN ON
END

TO GOBACK
TONE 4000 10
TTO [A B] SETODD ON
END

TO TURNLEFT
TTO "A SETEVEN ON
TTO "B SETODD ON END

TO TURNRIGHT
TTO "A SETODD ON
TTO "B SETEVEN ON
END

TO LIFTDOWN
IF BUTTON? 0 [TTO 4 SETODD ON]
IF NOT BUTTON? 0 [TTO 4 OFF]
END

TO LIFTUP
IF BUTTON? 1 [TTO 5 SETEVEN ON]
IF NOT BUTTON? 1 [TTO 5 OFF]
END

Here is how it works.

TC Logo programs are based on an idea called “procedures” which are subroutines. All programs start by defining the main procedure with TO (main procedure name).

First we begin a procedure called NAVIGATE. Next we perform a procedure called FORKLIFT. Then we loop the program by typing its name again. END never happens, just as in the BASIC version, but unlike in BASIC the END in Logo is required or you get an error message.

Now we code the first procedure: TO NAVIGATE. In my BASIC code, the robot only moves when paddles 0 and 1 are moved beyond the defined limits (75/175 out of 255 along either axis). The motors automatically stop when the paddles are inward of the limits (when you move the joystick back to center). However in the Logo version the motors don’t automatically stop — I had to add a line to define this. (I do not know why it works differently. In the BASIC version we POKE a value to the motors, but we start with a value 0, so that’s why the motors stop. A similar design in Logo would begin the procedure with a straightforward line such as [TTO [A B] OFF], but this led to the motors stuttering in a quick on-off-on-off fashion.) My solution was to specify the circumstances. Notice that in Logo the operator goes before the operand. As such: if the combination of both paddles being between 75 and 175 is true, then talk to ports A and B and turn them off.

If that combination is not true, the the routine falls through to four options: if the present location of either paddle is less than 75 or greater than 175, then it jumps to the directional procedures. It performs those and then returns to the main program.

GOFORWARD is simple. You talk to ports A and B, set them both in the even direction, and turn them on.

GOBACK is the same as forward, except you change the direction to odd. But first I set an audio tone of 4000 pitch frequency (options are 37 through 9,999) for one second (measured in tenths). Every good forklift needs a backup alert!

TURNLEFT and TURNRIGHT activate the motors in opposite directions from each other.

After returning from the navigation routines, this code performs the forklift routine. The goal is to move the forklift motor one way to make it go up, the opposite way to make it go down, and to always stop if it activates the upper or lower touch sensors.

You always want to check the status of both sensors before activating the forklift motor. So we LISTENTO the bottom sensor via port 6. If it’s on, then we turn the accompanying motor direction off. If it’s not on, then we proceed to the move-down routine. In that routine, if joystick button 0 is currently pressed, then we turn on the motor to move the lift down. If the button is not being pressed, then that motor turns off. Either way we end the routine and loop back. Next we do the same thing to check the upper sensor, turn off the lift motor if necessary, turn it back on if the sensor isn’t active while button one is being pressed, and loop back to the main program — at which point the whole thing begins again from the navigation routine.



Home - History - Universal Buggy - Computers - Interface A - Connections - Peripherals - Code - Analog - Beyond - Lego Chevy V8

Copyright: Evan Koblentz, 2018-2024