The GoGo Board extension lets you connect NetLogo to the physical world, using sensors, motors, light bulbs, LEDs, relays and other devices. The GoGo Extension for NetLogo 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.
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 web site 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.
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).
In order to access the serial ports, the user you are logged in as
needs to have permission to write to /var/spool/uucp
.
You can run the script gogo/lib/Mac OS
X/fix-permissions.command
to set up the permission
appropriately. It will make that directory writable by the group
uucp
and then add your current login to that group.
Double-click that file to run it.
You will need to be able to write the the serial devices, normally
/dev/ttyS*
. In most Linux distributions this can be set
up thru the User Manager. Using the GoGo Extension
The GoGo Extensions comes preinstalled. To use the extension in your model, add a line to the top of your procedures tab:
extension [gogo]
If your model already uses other extensions, then it already has an extensions line in it, so just add gogo to the list.
After loading the extension, see what ports are available by typing the following into the command center:
print 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" print gogo:ping
On Linux:
gogo:open "/dev/ttyS01" print gogo:ping
For more information on NetLogo extensions, see the Extensions Guide.
Models saved as applets (using "Save as Applet" on NetLogo's File menu) cannot use the Gogo extension, since applets can't use extensions that require additional extra jars. (Also, unsigned applets aren't allowed to access external devices anyway.) For examples that use the GoGo extension, see the GoGo section under Code Examples in NetLogo's Models Library.
gogo:close gogo:open gogo:open? gogo:ports gogo:output-port-coast gogo:output-port-off gogo:output-port-reverse gogo:output-port-[that|this]way gogo:ping gogo:sensor gogo:set-output-port-power gogo:talk-to-output-ports
Close the connection to the GoGo Board.
See also gogo:open and gogo:open?.
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.
Reports true if there is a connection to a GoGo board open. Reports false otherwise.
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.
Turns off the power of the active ports. When attached to motors, does not apply a braking force as gogo:output-port-off does. Therefore, the motor will gradually slow down before stopping completely. This will have the same effect as gogo:output-port-off on most output devices other than motors. The output-ports effected by this command are determined by the gogo:talk-to-output-ports command.
The following code will will turn on output port a for 1 second, and then stop the motor gradually:
gogo:talk-to-output-ports ["a"] gogo:output-port-on wait 1 gogo:output-port-coast
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 gogo:talk-to-output-ports command.
Reverses the direction of the output ports. The output ports effected by this command are determined by the gogo:talk-to-output-ports command.
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 gogo:talk-to-output-ports command. Note that this is different from gogo:output-port-reverse because thisway and thatway will always be the same direction provided the connector's polarity is the same.
This command will set the corresponding output ports as active. They will be the ones affected by the commands such as gogo:output-port-on and gogo: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 gogo:talk-to-output-ports [ "a" "b" "c" "d" ] ;; will give power to all output-ports gogo:output-port-on ;; talk to output-ports A and D gogo:talk-to-output-ports [ "a" "d" ] ;; will turn off output-ports A and D. ;; The other output-ports will keep ;; their current state gogo:output-port-off gogo:talk-to-output-ports [ "c" "b" ] ;; turn off remaining output-ports gogo:output-port-off
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:
print gogo:ping
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:
print gogo:sensor 1 ;; prints the value of sensor 1 foreach [ 1 2 3 4 5 6 7 8 ] [print (word "Sensor " ? " = " gogo:sensor ?)] ;; prints the value of all sensors if gogo:sensor 1 < 500 [ ask turtles [ fd 10 ]]
;; will move all turtles 10 steps forward if sensor 1's value is less than 500. loop [if gogo: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.
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 gogo: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:
gogo:talk-to-motors ["a" "b" "c" "d"] gogo:set-motor-power 4 ;; will lower the power of all output ports by half of the full power .