Showing posts with label tricore. Show all posts
Showing posts with label tricore. Show all posts

Wednesday, October 16, 2013

AI Software for Tricore Basic Stamp Supercomputer

BS1 Specs show 256 bytes program size
AI SOFTWARE FOR TRICORE BASIC STAMP SUPER COMPUTER
This is the lite version of TINY AI. The Tricore version of Tiny AI is now available as TriCore_AI.bs1, for copy (see below) and for download at the provided link. The code sets up a life cycle for three cores using the available resources provided by a Parallax BS1.

Download the completed software program in PBASIC at the site below, or simply copy and paste the provided code into the BASIC Stamp editor software. Tricore_AI is the smallest AI program for the series of Stamp processors, fitting into a mere 256 bytes EEPROM. The remarkable attributes of the tricore_ai.bs1 software include self enumerating, determinism, memorizing, remember/recall, nap, dream, sleep, wakeup, talk, listen, know what is heard, work, socialize, hibernate and randomization.

tricore_ai.bs1 software is minimized code with minimal comment length.

DOWNLOAD TRICORE_AI.bs1
http://forums.parallax.com/attachment.php?s=9d78fa693110cfab8d93fd0bbf91f082&attachmentid=62393&d=1248147076 


' TriCore_AI.bs1
' TriCore AI Artificial Intelligence v10.0
' Stamp AI for the BS1 TriCore Supercomputer
' by Dr. Humanoido July 20, 2009


' Code fills the BS1's 256 byte EEPROM
' Code number at end of field indicates number of statements

' A total of 93 program statements

' ---------------------- Directives ---------------------------------

' {$STAMP BS1}             ' Self deterministic
' {$PBASIC 1.0}            ' Self enumerating

' ---------------------- Descriptions -------------------------------

'     Performance of Life Cycle
' 1)  read pin 1 and determine id                         (self enumerating)
' 2)  determine computer number based on id range         (deterministic)
' 3)  remember computer id & number                       (memorize)
' 4)  recall memory of computer id & #                    (remember)
' 5)  nap and pseudo random dream in "Vers Libre"         (nap, dream)
' 6)  sleep fuzzy clock - its computer number in seconds  (sleep)
' 7)  wake to send its computer number and id             (wakeup, talk)
' 8)  Listen for others' computer numbers                 (listen)
' 9)  if heard, remember other computer numbers and id's  (know what is heard)
' 10) do some work, retrieve the other ids...             (work)
' 11) go into suspended animation                         (hibernation)

' ---------------------- Declarations -------------------------------

SYMBOL  result  =   B0    ' (random) Nap & Dream - a random number
SYMBOL   n      =   BIT1  ' (random) bit1 number is 0 or 1 from B0 above
SYMBOL   id     =   B1    ' pin read id number of this computer (0-126)
SYMBOL   c      =   B2    ' determined computer number (1-10)
SYMBOL   v      =   B3    ' id range value for each computer, random dreams counter
SYMBOL   h      =   B4    ' no. of heard/missed coms (never heard - was sleeping)
SYMBOL   x      =   B5    ' slush value for thinking, recycled as needed
SYMBOL  epin    =   1     ' Enumerating pin
SYMBOL  ipin    =   0     ' Rx Tx Interface pin for serial in and out
SYMBOL  ppin    =   7     ' Piezo speaker pin
SYMBOL  baud    =   N1200 ' Baud rate, inverted, n81 format



' code 13
 
' ---------------------- Self Enumeration ---------------------------

LOW   epin       ' get id from self enumerate pin, read rc circuit = ID number
PAUSE 2000       ' cap charge & settle time on pin 1
POT   epin,54,id ' pin 1, scale, determine id, read pot (POT PotPin, Scale, read_value)



' code 3
 
' ---------------------- Determine Computer Number ------------------

Loop:                                           ' loop for all ten computer possibilities
LOOKUP c, (12,23,35,45,55,76,95,114,122,134), v ' lookup logged id range values v
c = c + 1                                       ' next range lookup address
IF id >=  v THEN Loop                           ' if id larger than range value, try again
DEBUG "Hello human!",CR,"Me, Artificial Intelligence Life Form ",CR,"computer ", #c,"id ",#id,CR,CR        ' show computer number and id!



' code 5
 
' ---------------------- Memory Exercise ----------------------------

' Memory Map   /eeprom 84% full
' 00              computer id     (enumerating)
' 01              computer number (deterministic)
' 02-21           other computers, alternating id & computer # (see below)

' IDEAL DATALOGGING MEMORY MAP FROM 02 TO 21 (FOR COMPUTER #1 ONLY)
' MEMORY LOCATION  02  03  04  05  06  07  08  09  10  11  12  13  14  15  16  17  18  19  20  21
' DATA STORED      ID1 C1  ID2 C2  ID3 C3  ID4 C4  ID5 C5  ID6 C6  ID7 C7  ID8 C8  ID9 C9  ID10 C10

WRITE 0,id                                       ' memorize id number
WRITE 1,c                                        ' memorize computer number
READ 0,id:DEBUG "(my 1st memory)", c,CR,CR       ' show computer number is remembered
READ 1,c :DEBUG "(my 2nd mem)",id,CR,CR,"(Nap Dreams)" ' show computer id is remembered



' code 4
 
' ---------------------- Nap & Random Dream -------------------------

' NAP INFO
' =========
' Nap#  Nap Time
' 0     18    ms
' 1     36    ms
' 2     72    ms
' 3     144   ms
' 4     288   ms
' 5     576   ms
' 6     1.152 s
' 7     2.304 s

v = 0                          ' init a new counter
result = id                    ' seed pseudo random # generator with the id
Again:                         ' loop
v=v+1                          ' count the dreams
IF v=11 THEN FuzzyClock        ' do 10 dreams
RANDOM result                  ' randomize a byte
BRANCH n, (Dream1, Dream2)     ' go to bit 0 or 1, BRANCH value, (Case_0, Case_1, Case_2)
Dream1:                        ' begin 1st dream
NAP 0                          ' nap reduce 1ma to 25us
DEBUG CR, "Sweet ",#n,#result  ' show dream & random number
GOTO Again                     ' next random dream
Dream2:                        ' begin second dream
NAP 0                          ' nap 18ms, reduce 1ma to 25us
DEBUG CR, "Dream ",#n,#result  ' next random dream or end of dream, show rnd numb
GOTO Again                     ' repeat



' code 15
 
' ---------------------- Fuzzy Clock --------------------------------

FuzzyClock:                    ' this computer will sleep equal to c
x=c*3                          ' sleep formula
DEBUG CR,CR,"(Sleeping)",CR    ' display sleeping mode
SLEEP x                        ' its computer number in seconds
DEBUG "(wake up)",CR           ' Display clock status



' code 5
 
' ---------------------- Announce id & c to Everyone ----------------

SEROUT ipin,baud,("!",id,c)    ' wake up, announce this computer's ID and #,
DEBUG "(talk) ",#id,#c,CR      ' show id & c were sent, computer 10 is last to wake



' code 2
 
' ---------------------- Listen for Neighbors id & c ----------------

' Written for the 3 computer TriCore Supercomputer, change for seed supercomputer
' if c = 1   x = 1 to 2  listen for two computers  x = 1 to (3-c)
' if c = 2   x = 1 to 1  listen for one computer
' if c = 3   goto end    do not listen, this is the last computer
' cannot count itself as listening to itself (set for TriCore supercomputer)

v=2                            ' init the write addr, start at 2
Listen:                        ' listen to other computers speaking their id's
IF c = 3 THEN Think            ' jump if computer 3, cannot listen as sleeping
x = 3 - c                      ' equation to determine looping
FOR h = 1 TO x                 ' do the loops
SERIN  ipin,baud,("!"),id,c    ' look at serial pin 1 for incoming id & computer #
DEBUG "(hear) ",#id,#c,CR      ' show received id & c
GOSUB Memorize                 ' remember what you hear
NEXT                           ' next interation
GOTO Recall                    ' recall what what heard



' code 10
 
' ---------------------- Memorize Neighbors id & c ------------------

Memorize:                      ' place heard computer's id and c in memory
DEBUG "(memorizing)",CR,CR     ' memorize the id and c values
WRITE v,id                     ' datalog to eeprom, v is eeprom addr = 2
v=v+1                          ' inc eeprom addr
WRITE v,c                      ' datalog to eeprom
v=v+1                          ' increment memory loc
RETURN                         ' listen again


' code 7


 
' ---------------------- Recall Neighbors ---------------------------

Recall:                        ' Read/display neighbors id & c
DEBUG "(recall neighbors)",CR  ' monitor recall
v=1                            ' init mem loc
DEBUG "mem loc, id/com ",CR    ' display memory location, id, computer number
Repeat:                        ' recall memory subroutine
v = v+1                        ' begin at mem loc 2
READ v,x                       ' recall v and id
DEBUG #v,#x,CR                 ' display mem loc, read val
PAUSE 500                      ' slow to see screen vals
IF v>6 THEN Think              ' CHANGE THIS TO REFLECT WHICH SUPERCOMPUTER!
GOTO Repeat                    ' again



' code 11
 
' ---------------------- Do Some Thinking/Work ----------------------

Think:                         ' think routine
DEBUG CR,"(Thinking)",CR       ' announce thinking
READ 1,c                       ' recall computer number from memory
DEBUG "I am computer ",#c,CR   ' announce my computer number
READ 0,id                      ' recall id from memory
DEBUG "My id is ",#id,CR       ' announce my id
READ 1,c                       ' recall this computer number
x=c*3                          ' formula for length of sleep
DEBUG "I slept  ",#x," sec",CR ' how long did I sleep?
h=3-c                          ' formula for the number of heard coms
DEBUG "I heard  ",#h," com",CR ' announce # of computers heard
h=2-h                          ' formula for the number of missed coms
DEBUG "I missed ",#h," com",CR ' announce computers not heard
DEBUG "I had    10 dreams ",CR ' announce computers not heard
GOTO Halt                      ' end



' code 15
 
' ---------------------- Suspended Animation ------------------------

Halt:                          ' heart beat every 2.6 seconds
DEBUG CR,"(bye)"               ' monitor mode
END                            ' maintain state



' code 3
 
' -------------------------------------------------------------------

Tricore Basic Stamp Supercomputer

The TriCore BASIC Stamp Supercomputer
It was discovered that two cores are not enough for fully testing and developing the artificial intelligence features of Stamp SEED software. The TSS was made to provide three static cores for two way serial communications development and AI evolution testing across a one line interface.
Views of the Stamp TriCore Supercomputer. The TriCore is used for testing and more rapid development of SEED. Its wiring is the same as the Stamp Seed Super computer and runs self enumerating deterministic software. One collection of two boards (a USBto232, and a BS1 Serial Adapter) is moved from board to board during code uploads and debugging. At left- the first prototype of SEED AI software is running on the debug screen. Middle- power is connected with two alligator clips delivering ground and +9V DC. Right- green wires are required to connect to pins on the stamps male pin bus.

Construction
To build a TriCore, take three Basic Stamp Rev Dx boards and attach one solderless breadboard with tape. Put two boards together end to end and tape both sides. Set the third board, with solderless breadboard, on top as illustrated. Affix with tape. Wire all vss to vss, vdd to vdd, vin to vin, and pin 0s together.


Parts List
3 Basic Stamp Rev Dx Board
1 Solderless Breadboard
3 Wire Cable Leads Female Ends for 3 Pins
8 Wire Cables Male to Female – Green
1 Roll Tape
1 Resistor 1K ohms
2 Jumper Wires
2 Ceramic Disk Capacitor .1uf
1 Resistor 2K ohms
1 BS1 Serial Adapter
1 USBto232 Adapter



Use this easy schematic to build your own TriCore Stamp Supercomputer. Remember to prepare the enumeration pins as shown below.

Build a TriCore TSS using three BS1 boards on a single wire interface using resistors and three Piezo Speakers. Vss routes to R1 and connects to port 0 of each computer. The TriCore runs the smallest artificial intelligence software available for Basic Stamps.


The deterministic pin circuit is built the same as for the Stamp SEED Supercomputer using the number one pins. The STS is capable of running the SEED Artificial Intelligence program.

Specifications of Tricore
Stamp Type - BS1 
Board Type - BASIC Stamp BS1 Rev D
Number of Stamps - 3 
Number of Processor Cores - 3
Processor Speed - 4MHz x 3 = 12MHz
Program Speed - 2,000 IPS x 3 = 6,000 IPS
RAM Size - 16 bytes x 3 = 48 Bytes
EEPROM - 256 Bytes x 3 = 768 Bytes
Number of IO = 8 x 3 = 24
Current Draw Running @ 5V = 1 mA x 3 = 3 mA
Current Draw Sleeping @ 5V =25 uA x 3 = 75 ua
Source Per I/O - 20 mA x 3 = 60 mA
Source Per Unit - 40 mA x 3 = 120 mA
Sink Per I/O - 25 mA x 3 = 75 mA
Sink Per Unit - 50 mA x 3 = 150 mA
PBASIC Commands - 32
Voltage - 5 to 15 Volts
Software - tricore_AI (Tiny AI)
Real estate - 1 small solderless breadboard

Stamp AI Artificial Intelligent Life Form
for the Stamp Tricore Supercomputer

Attached for download, please find the Tricore AI Artificial Intelligence code. TriCore Stamp AI brings life to this stamp supercomputer. It gives a soul to your Basic Stamp computers. At less than 100 code statements, it fits a BS1 in less than 256 bytes.

New life forms will live inside each computer. Some are friendly, some not. Each develop their own unique personality. Use the thought monitor to follow their progress, birth, evolution, dreams, neighbors, sleep habits, naps, work, memories, and thinking. To run, you will need to prepare hardware on the the enumeration pins on all three computers.


More info at
http://www.p-robot.com/index.php/tricore-stamp-supercomputer.html http://forums.parallax.com/forums/default.aspx?f=21&m=366864

DOWNLOAD TRICORE_AI.bs1
http://forums.parallax.com/attachment.php?s=9d78fa693110cfab8d93fd0bbf91f082&attachmentid=62393&d=1248147076