大象传媒

Sensors and Control

Sensors

Sensors are often used as part of a feedback cycle. They collect data continuously and are typically linked to a control program that specifies acceptable levels, eg the minimum and maximum temperature in a greenhouse. The control program decides what to do next based on the data it's fed by the sensors.

Logo

Logo is a simple computer programming language which can be used to control devices. For example, a small robot known as a can be moved around the floor using logo. Logo is often used with a screen turtle, which is an object on the screen used to simulate how a turtle moves around the floor. There are many which can be used to control the turtle.

Logo commands

Here are some examples of the most common Logo commands:

Programming a screen turtle
CommandAction
FORWARD 50move forward 50 steps
BACK 50move backward 50 steps
LEFT 90turn 90掳 left
RIGHT 90turn 90掳 right
PENDOWNlower pen and begin drawing
PENUPraise pen and cease drawing
CommandFORWARD 50
Actionmove forward 50 steps
CommandBACK 50
Actionmove backward 50 steps
CommandLEFT 90
Actionturn 90掳 left
CommandRIGHT 90
Actionturn 90掳 right
CommandPENDOWN
Actionlower pen and begin drawing
CommandPENUP
Actionraise pen and cease drawing

These commands can be used to draw a square on the screen:

  1. FORWARD 100
  2. LEFT 90
  3. FORWARD 100
  4. LEFT 90
  5. FORWARD 100
  6. LEFT 90
  7. FORWARD 100
  8. LEFT 90

Repeating commands

The same commands can be written more quickly using the REPEAT command, for example:

REPEAT 4 [FORWARD 100 LEFT 90]

This single command would have the same effect as the eight individual commands above - it draws a square.

The REPEAT command can be used to create any number of patterns. For example, a shape similar to a spirograph was created with this command:

Spirograph with 30 corners

REPEAT 30 [FORWARD 100 RIGHT 156]

Storing a series of commands like this creates a simple program. The order of the commands in a program is vital. If it is in the wrong order, the program will not work as expected.

Computer programming languages are very fussy. Any errors, however small, will cause the program not to work. The computer won't like spelling mistakes or, for example, if you forget to put a space between FORWARD and 50.