GoGo Extension

What is the GoGo Board?

The GoGo Board extension lets you connect NetLogo to the physical world, using sensors, motors, light bulbs, LEDs, relays and other devices. The NetLogo GoGo Extension provides primitives to communicate with a GoGo board via a serial interface.

A GoGo Board is an open source, easy-to-build, low cost, general purpose board especially designed to be used in educational projects. It was created by Arnan Sipitakiat at the MIT Media Lab. A GoGo Board has 8 sensor ports and 4 output ports, and also a connector for add-on boards (such as a display or a wireless communication module). Using the GoGo Board extension, NetLogo models can interact with the physical world in two ways. First, it can gather data from the environment, such as temperature, ambient light, or user input. This information can be used by the model to change or calibrate its behavior. Secondly, it can control output devices - NetLogo could control motors, toys, remote controlled cars, electrical appliances, light bulbs, and automated laboratory equipment.

How to get a GoGo Board?

The GoGo Board is not a commercial product, and thus cannot be bought at stores. To get a GoGo Board, you have to build one yourself or ask someone to do it for you. The board was especially designed to be easy and cheap to build, even if you don't have electronics skills. The main resource about the GoGo Board is the website www.gogoboard.org, where you will find step-by-step instructions on how to buy components, design the printed circuit board, and assemble it. The GoGo Board mailing list is gogoboard@yahoogroups.com.

Installing the GoGo Extension

The GoGo Board needs to communicate with the computer in some way, and to do so it uses the serial port. The choice of this port instead of a USB port was motivated by the board's low cost principle: the components needed to build a USB compatible board would be more expensive. If your computer does not have a serial port, you need to purchase a USB-to-Serial adapter, which can be easily found in computer stores with prices ranging from US$ 15 to US$ 30 (if you have a Mac or Linux machine, make sure the adapter is compatible with your platform). To communicate with the GoGo Board through the serial port, the GoGo Extension uses Sun Microsystem's Java Communications API. In each platform (PC, Mac, Linux), the procedures for installing the software needed to enable serial communication are slighly different.

Mac OS X

There is no official implementation of the Java Communications API for OS X, but the RXTX project provides an open-source implementation. You can download the RXTX installer for OS X from SourceForge. Be sure to follow all the directions in the installer to create lock file directories and make sure your user is in the appropriate groups to use the lock files.

There are several commercial implementations of the Java Communications API for OS X which have not been tested with the GoGo extension, but, in theory, should work. Please contact us if you succesfully use them, or run into problems trying.

Windows

Sun provides an implementation of the Java Communications API for Windows, which you can download.

Once downloaded, extract the files into a temporary directory. Several files need to be copied into your Java Runtime Environment, or JRE, installation. If you are using the version of NetLogo which comes with its own Java VM, then your JRE installation is in the jre subdirectory of the NetLogo folder. Otherwise, it is in a directory like c:\j2sdk1.4. The files comm.jar and javax.comm.properties must be copied into the lib folder of the JRE installation. The files win32comm.dll must be copied to the bin folder of the JRE installation. The file PlatformSpecific has more detailed instructions.

Linux and others

There is no official implementation of the Java Communications API for Linux. You can use the RXTX implementation. Kevin Hester has written some installation instructions.

Using the GoGo Extension

The GoGo Extensions comes pre-installed. To use the extension in your model, add a line to the top of your procedures tab:

__extensions [ "gogo.jar" ]

After loading the extension, see what ports are available by typing the following into the command center:

show gogo-ports

You can open the serial port the GoGo Board is connected to with the gogo-open command, and see if the board is responding with the ping reporter.

On Windows:

gogo-open "COM1"
show ping

On Linux:

gogo-open "/dev/ttyS01"
show ping

For more information on NetLogo extensions, see the Extensions Guide.

Please note that the NetLogo extensions facility is under development and is still considered experimental, so the syntax is likely to change in a future version of NetLogo. Models saved as applets (using "Save as Applet" on NetLogo's File menu) cannot make use of extensions. (We plan to fix this in a future release.)

For examples that use the GoGo extension, see the GoGo section under Code Examples in NetLogo's Models Library.

Primitives

gogo-open gogo-open gogo-open? gogo-ports output-port-coast output-port-off output-port-reverse output-port-[that|this]way ping sensor set-output-port-power talk-to-output-ports

gogo-close

gogo-close

Close the connection to the GoGo Board.

See also gogo-open and gogo-open?.

gogo-open

gogo-open port-name

Open a connection to the GoGo Board connected to serial port named port-name. See gogo-ports for more information about port names.

If the GoGo Board is not responding, or you attempt to open a port without a GoGo Board connected to it, an error will be generated.

Example:

gogo-open "COM1"

See also gogo-open and gogo-close.

gogo-open?

gogo-open?

Reports true if there is a connection to a GoGo board open. Reports false otherwise.

gogo-ports

gogo-ports

Reports a list of serial port names which a GoGo Board may be connected to. On certain computers, you might get a list of two or three different serial ports. In that case, try to open each of them until the connection is successful.

output-port-coast

output-port-coast

Turns off the power of the active ports. When attached to motors, does not apply a braking force as output-port-off does. Therefore, the motor will gradually slow down before stopping completely. This will have the same effect as output-port-off on most output devices other than motors. The output-ports effected by this command are determined by the talk-to-output-ports command.

The following code will will turn on output port a for 1 second, and then stop the motor gradually:

talk-to-output-ports ["a"]
output-port-on
wait 1
output-port-coast

output-port-off

output-port-off

Turns off power to the output ports. If using motors, a braking force is applied. The output ports effected by this command are determined by the talk-to-output-ports command.

output-port-reverse

output-port-reverse

Reverses the direction of the output ports. The output ports effected by this command are determined by the talk-to-output-ports command.

output-port-[that/this]way

output-port-thatway

output-port-thisway

Apply power to the output port in a given direction. Output ports can be powered in two directions, arbitrarily called thisway and thatway. The output-ports effected by the command are determined by the talk-to-output-ports command. Note that this is different from output-port-reverse because thisway and thatway will always be the same direction provided the connector's polarity is the same.

talk-to-output-ports

talk-to-output-ports output-portlist

This command will set the corresponding output ports as active. They will be the ones affected by the commands such as output-port-on and output-port-off. The user can “talk” to one or multiple ports at the same time. Output ports are typically connected to motors, but you could also use bulbs, LEDs and relays. Output ports are identified by one letter names: "a", "b", "c", and "d".

Examples:

;; talk to all output-ports
talk-to-output-ports [ "a" "b" "c" "d" ]
;; will give power to all output-ports
output-port-on

;; talk to output-ports A and D
talk-to-output-ports [ "a" "d" ]
;; will turn off output-ports A and D.
;; The other output-ports will keep
;; their current state
output-port-off

talk-to-output-ports [ "c" "b" ]
;; turn off remaining output-ports
output-port-off

ping

ping

Checks the status of GoGo board. This is mostly used to make sure the board is connected to the correct serial port. It reports true if the GoGo Board responds to a diagnostic message, and false otherwise.

Example:
show ping

sensor

sensor sensor

Reports the value of the sensor named sensor as a number. Sensors are named by numbers 1 to 8. Value ranges between 0-1023. 1023 is returned when there is no sensor attached to the port (highest resistance), or when the sensor is an “open” state. Zero is returned when the sensor is short circuited (no resistance).

Examples:

show sensor 1
;; will show the value of sensor 1


foreach [ 1 2 3 4 5 6 7 8 ]
  [show (word "Sensor " ? " = " sensor ?)]
;; will show the value of all sensors in the Command Center

if sensor 1 < 500 [ ask turtles [ fd 10 ]]
;; will move all turtles 10 steps forward if sensor 1's value is less than 500. forever [if sensor 1 < 500 [ ask turtles [ fd 10 ] ] ]
;; will continuously check sensor 1's value and ;; move all turtles 10 steps forward every time ;; that the sensor value is less than 500.

set-output-port-power

set-output-port-power power-level

Sets the power level of the active output ports. power-level is a number between 0 (off) and 7 (full-power). The output-ports effected by those command are determined by the talk-to-output-ports command. Note that for many practical applications it is more efficient to use mechanical devices, such as gears and pulleys, to control the torque of motors.

Example:

talk-to-motors ["a" "b" "c" "d"]
set-motor-power 4
;; will lower the power of all output ports by half of the full power .