'Loki_8-0.bas 40x2 Firmware v3
'Loki_7-0.bas 40x2 Firmware v3
'Ullr_6-0.bas 40x2 Firmware v3
#picaxe 40x2
'terminal 19200 baud
#slot 0
#no_data
'#no_table 'directive cannot be used when program occupies that area
#define keybip 'for ReadSerCmnd:
DISCONNECT 'the Serrxd pin is connected to the Hserin pin
'without DISCONNECT the system activity upsets
'the data received into the Hserin buffer.
SETFREQ m16 'SERTXD @19200 - see Init:
'HSERSETUP B19200_16,%00101
'pulsout 4MHz 10us units
'pulsout 16MHz 2.5us units
'#0 Memory used = 3844 bytes out of 4096 Commander
'#1 Memory used = 3722 bytes out of 4096 Movement
'#2 Memory used = 3382 bytes out of 4096 ?Report,EEPROM,Execute,?help
'#3 Memory used = 4038 bytes out of 4096 ?help2, @Setup
'==================================================
'Reactions Table:
SYMBOL USaware =0 TABLE USaware, ("vtta.")
SYMBOL USnear =16 TABLE USnear, ("vss-Btatm.")
SYMBOL OLR =32 TABLE OLR, ("s-BBtatm.")
SYMBOL OL_ =48 TABLE OL_, ("s-BRR.") '2023-01-03
SYMBOL O_R =64 TABLE O_R, ("s-BLL.") '2023-01-03
SYMBOL HLR =80 TABLE HLR, ("s-BBBBtatm.") '2023-01-03
SYMBOL HL_ =96 TABLE HL_, ("s-BRRR.") '2023-01-03
SYMBOL H_R =112 TABLE H_R, ("s-BLLL.") '2023-01-03
SYMBOL ReactEnd =127 TABLE ReactEnd,(".")
'Mind Table
SYMBOL mindstart =128
'Random takes 9 tries to get going beyond 0 so Z is at 0
'only one and two character mind commands
'one char
SYMBOL Mind128 =128 TABLE Mind128,("ZH4FRFFLFH1FB1F3F2RFRLVLFHVVFV><")'32
'two chars
SYMBOL Mind160 =160 TABLE Mind160,("subLbNbNbVw1w3w5w7w9vvvvvvvevevevevovovo")'40
SYMBOL Mind200 =200 TABLE Mind200,("vovss+s+s+s+s-s-eReReLeEeEereleetatttmtm")'40
SYMBOL Mind240 =240 TABLE Mind240,("totrtlaSsususuar")'16
SYMBOL Mindend =255
#rem
=11234FFFFFFFFFBRRRLLLFHHHVVVVZ><
=ZH4FRFFLFH1FB1F3F2RFRLVLKHVVFV><
11
2
3
4
FFFFFFFFFF
B
RRR
LLL
;K
HHH
VVVV
Z
>
<
=subLbNbNbVw1w3w5w7w9vvvvvvvevevevevovovo
=vovss+s+s+s+s-s-eReReLeEeEereleetatttmtm
=totrtlaSaKaar
'b0 kills b$a,b$1
su
bL
bNbN
bV
w1
w3
w5
w7
w9
vvvvvv
veveveve
vovovo vo
vs
s+s+s+s+
s-s-
eReR
eL
eEeE
er
el
ee
ta
tt
tmtm
to
tr
tl
aS
su 'aK picks up bl=9 from < >
susu 'a kick L kick R
ar roll roll
#endrem
'==================================================
'BUGS
'==================================================
'ToDo
'#1 Qfell,
'==================================================
'Program Memory
'--------------
'4x4K slots
'
'DATA Memory
'-----------
'256
'
'Variables - General
'-------------------
'Bytes Bit Byte Word
'56 bit0-31 b0-55 w0-27
'
'Variables - Storage - peek and poke
'-------------------
'200 56 to 255 ($38 to $FF)
'
'Variables - Scratchpad
'- GET byte, PUT byte, @ptr, @ptrinc (post +1), @ptrdec (post -1) .
'----------------------
'1024 scratchpad bytes (0-1023) HS buffer
'==================================================
#rem
History:
-------
09Aug23 Commander: was inside the DoLoop, added DoCommands:
10Jan23 added PrintReactions, PrintMind
09Jan23 replaced right outer toe LED which had failed
03Jan23 ?W.?F now read Whiskers and Feelers and show map, names in reaction table changed
06Sep22 corrected record ; overwriting next slot
moved eyes: to prog2
29Aug22 finished Pose cmnd
11Mar22 4022 added HIGH VoiceLED to TalkAli
29Jan22 changed vnl from 2 to 3
03Nov21 changed W27 random use to W22, W27 used on prog1
22Sep21 fitted Whisker sensors
18Sep21 added code for GetUpF,GetUpB
SRAin increased by 5 to 225 so Loki can get up from on back
added P
16Sep21 added Reactions and Mind Table, brought all Aesir into line,
added shin feelers.
30Aug21 added cmnd =255 at start and lastcmnd and test in QIR to avoid keyrepeats
NoIR timeout increased from 50 to 100
bg removed, b$-,b$+,b$0 added
13Aug21 added bL,bN,bV as two char cmnds for bvl,bvn,bvh in mind
12Aug21 added SYMBOLs vlk,vnk,vhk,vxk; kickcmnd to [9]{[4][5][6] and bv
<.> set FootLift depending on FLcmnd to 6,7,8
30Jul21 sdded "T" Transmit-IR - not yet finished
Jul21 added mind to Reactions table
Loki8 ************
08Aug21 ^bip,^whee,^whoa,^beep100 now jump from #1 to #2, whee,whoa tempo altered
added bv and IR speed and vitality const are now in a SYMBOL table
25Jul21 removed stackcmnd from #1Getcmnd and altered #2LoadBehaviour to GOTO Run1
ready prompt ">" only printed if not recording or playing
18Jul21 changed prog0 to hold Reaction Table and Prog1 to set ptr ReactAt
rather then use a sequence of GoSubs.
Table based on Bamduino Reaction slot.
11Jul21 added 4pin 0v,5v,C.6/hserout,Serin header for Alitalk etc
27Jun21 ported from Ullr
Loki7 ************
'==================================================
21may21 corrected Tt and Ta, needed <=,>= not <,>
' added tr,tl - turn R,L on spot
27Jan21 changed f_fdL to test RPat, moved bS to #2, modified #0initEEPROM, test and init in #2
18Jan21 added QRecRUN1 etc
added at end behaves IF f_Bmodified =1 THEN : cmnd ="M" : GOTO RUN1 : ENDIF
so print prints updated cmnd values
added TOO
moved things around and saved a lot of bytes
16Jun20 added [9][0] ="E" so can turn on LEDS from IR to photograph
16Jun20 0-load, IF cmnd="0" THEN f_page0 =1
16Jun20 1-Qground, anti bounce code rem'd - Ullr has IR ground sensing.
17May20 added test in prog1 Halt for crawl so doesn't stand up if crawling
added f_crawl=0 after S
23Apr20 added Sspeed /2 in SLR to make move less jerky
13Apr20 introduced bT, be Tall and bC be Crawl, when crawl=1 FBRL do crawl
13Apr20 added "p" poses split from "a"
12Apr20 introduced SYMBOL RAM_Sspeed =78, SYMBOL RAM_leglLift =79
10Apr20 changed CASE "s" to update Sspeed directly and commented f_Bmodified =1
Ullr 6
06Apr20 cloned from Baldur6 *********************
28may19 added Do
28may19 limited recording to one slot at a time
20May19 revised auto hole test.
02May19 changed LoadBehaviour to CASE "b0" in line with Bamduino,
added EEPROM initialisation "bI" and changed behaviour save to "bS"
08Mar18 Feeler and Whisker LEDs on for avoid duration, Tip sensors added
27Sep17 added LoadBehaviour - CASE "D"
07Jul17 ReadSerCmnd: added test of last serbyte received, if Q or ESC then Quit
02Mar17 P0 deleted saving f8_Cmnder0
22Feb16 rewrote Qground
21Feb16 f_allSerial @@@commented and bit 6 reused for f_b_React
22Sep15 changed slot length to 16 from 32, now have slots 1-8 and 01-08
f_page0 =bit22 '1=Acts/Slots 01-08, 0(default) =1-8
1-8 in 0-127, 01-08 in 128-255
slots flow into next slot if no '.', ';' continue in next slot
Baldur 6
26Aug15 changed \@ to b@
05Jul15 added feet bulges - now gets up from upside down by front and back
02Jul15 optosensors now work
23Jun15 added "@" for Autorun, changed @ adjust to \@, revised Whisker code to Bamduino
14Jun15 brought Freya, Baldur cmnds into line
Baldur 5
26May15 added "K",changed P_whiskerLLED-C.1,P_whiskerRLED-C.2 to A.6,A.7
25May15 added D - reset to Default behaviour,changed D,#,? to ?D,?#,??
23May15 added bb, af,ab,au,aF,aB
22May15 Got Baldur walking, but can't get it to turn, works from manual pots! added "bD"
20Mar15 ported from Freya_4a, new - servo positions
01Mar15 auto SLR in MOVE: now controlled by f_bg_Qtoes=1
26Jan15 added auto SLR if falling over in MOVE:
24Jan15 added standOnLR in SLR,SR,SL and test at end of Move:
07Jan15 moved u to bu, added bg, T
06Jan15 wired toe sensors
4a-0
23Sep14 corrected w0 so it works for serial as well as IR, and ignores the command
20Sep14 added cmnd I to Commander, already there in prog1 for initialisation
07Sep14 Added BEHAVIOUR section to 4.1, and f_Bmodified
only cmnd values in 4.0
07Sep14 4.0
20Jul14 corrected w so it calls Move
06Jul14 corrected mp so it works
05Jul14 Added #, amended Print-Act
11Jun14 moved Adjust to Prog1
11Jun14 got hserin working hrserptr gets set to 0 on slot RUN !!!!
10Jun14 now in 3 slots
Freya3
05Jun14 2927 Load working
04Jun14 2805 recording and playing working
22May14 Now working from Terminal "F,B,R,L,U,S,s,cr,' ',-,+,X,x"
11May14
'==================================================
'Note there are ">>" between Acts, one > to get the Act, and one > to get the move
'==================================================
'Commands - see Loki_commands.bas
'==================================================
'Pinout:
'==================================================
PICAXE-40X2
18F45K22 ______
RESET |1 40| B.7 IN OUT
COMP1- TOUCH ADC0 IN OUT A.0 |2 39| B.6 IN OUT
COMP2- TOUCH ADC1 IN OUT A.1 |3 38| B.5 IN OUT ADC13 TOUCH
DAC VREF- COMP2+ TOUCH ADC2 IN OUT A.2 |4 37| B.4 IN OUT ADC11 TOUCH
VREF+ COMP1+ TOUCH ADC3 IN OUT A.3 |5 36| B.3 IN OUT ADC9 TOUCH
SI |6 35| B.2 IN OUT ADC8 TOUCH HINT2
SRNQ OUT SO A.4 |7 34| B.1 IN OUT ADC10 TOUCH HINT1
TOUCH ADC5 IN OUT A.5 |8 33| B.0 IN OUT ADC12 TOUCH HINT0 SRI
TOUCH ADC6 IN OUT A.6 |9 32| V+
TOUCH ADC7 IN OUT A.7 |10 31| 0V
V+ |11 30| D.7 IN OUT ADC27 TOUCH KBD HPWMD
0V |12 29| D.6 IN OUT ADC26 TOUCH KBC HPWMC
XO |13 28| D.5 IN OUT ADC25 TOUCH HPWMB
XI |14 27| D.4 IN OUT ADC24 TOUCH
TIMER IN OUT C.0 |15 26| C.7 IN OUT ADC19 TOUCH HSERIN
PWM IN OUT C.1 |16 24| C.6 IN OUT ADC18 TOUCH HSEROUT
PWM HPWMA TOUCH ADC14 IN OUT C.2 |17 24| C.5 IN OUT ADC17 TOUCH SDO
SCK SCL TOUCH ADC4 IN OUT C.3 |18 23| C.4 IN OUT ADC16 TOUCH SDI SDA
TOUCH ADC20 IN OUT D.0 |19 22| D.3 IN OUT ADC23 TOUCH
TOUCH ADC21 IN OUT D.1 |20__21| D.2 IN OUT ADC22 TOUCH
Pins:
-----------------------
C.7 hserin
C.6 hserout
C.4 hi2c sda
C.3 hi2c sck
-----------------------
[Pot ]
touch,Analog,Input,Output,Serial out in,Timer clk,DAC,Compare
-----------------------
1 Reset_
2 O_servoLhip A.0 (tAIOC1-)
3 O_servoLknee A.1 (tAIOC2-)
4 I_ToeL A.2 (tAIOC2+D)
5 IRin A.3 (tAIOC1+)
6 SERIN
7 SEROUT/O_LCD A.4 (SoO){SRNQ}
8 A_whiskerLeye A.5 (tAIO)
9 P_whiskerLLED A.6 (tAIO)
10 P_whiskerRLED A.7 (tAIO)
11 +v
12 0v
13 (Resonator)
14 (Resonator)
15 Ping C.0 (IOT)
16 EyeRLED C.1 (IO pwm)
17 EyeLLED C.2 (tAIO hPwm pwm)
18 [hi2c sck] C.3 (tAIO IICscl SPIsck)
19 A_whiskerReye D.0 (tAIO)
20 I_ToeR D.1 (tAIO)
40 B.7 (IO)
39 B.6 (IO)
38 B.5 (TAIO)
37 B.4 (TAIO)
36 B.3 (TAIO)
35 B.2 (TAIOi2)
34 B.1 (TAIOi1)
33 B.0 (TAIOi0)
32 +v
31 0v
30 O_toeLLED D.7 (tAIO hPwm KBdata)
29 A_toeLfeeler D.6 (tAIO hPwm KBclk) tipB
28 A_toeRfeeler D.5 (tAIO hPwm) tipF
27 O_toeRLED D.4 (tAIO)
26 [hserin ] C.7 (tAIOSi)
25 [hserout ] C.6 (tAIOSo)
24 O_voice/O_vLED C.5 (tAIO SPIsdo)
23 [hi2c sda] C.4 (tAIO ICsda SPIsdi)
22 O_servoRknee D.3 (tAIO)
21 O_servoRhip D.2 (tAIO)
-----------------------
1 Reset_ 40 B.7
2 O_servoLhip A.0 39 B.6
3 O_servoLknee A.1 38 B.5
4 I_toeL A.2 37 B.4
5 IRin A.3 36 B.3
6 SERIN 35 B.2
7 SEROUT/[O_LCD] A.4 34 B.1
8 A_whiskerLeye A.5 33 B.0
9 P_whiskerLLED A.6 32 +v
10 P_whiskerRLED A.7 31 0v
11 +v 30 O_footLLED D.7
12 0v 29 A_footLfeeler D.6 tipB
13 (Resonator) 28 A_footRfeeler D.5 tipF
14 (Resonator) 27 O_footRLED D.4
15 Ping C.0 26 [hserin ]cmnds C.7
16 EyeRLED C.1 25 [hserout] C.6
17 EyeLLED C.2 24 O_voice/O_vLED C.5
18 [hi2c sck] C.3 23 [hi2c sda] C.4
19 A_whiskerReye D.0 22 O_servoRknee D.3
20 I_RToe D.1 21 O_servoRhip D.2
-----------------------
o servo o tip
o 5v o 5v
o 0v o 0v
o toe
o 5v
o 0v
o WhiskerFeelerIn
o WhiskerFeelerLED
o 0v
-----------------------
'==================================================
Connectors
______________________________________
|Power Aux Program Servos|
| |
Pace servo | 0v 6v D2 A0 6v 0v | Pace servo
Roll servo | 0v 6v D3 A1 6v 0v | Roll servo
toe switch | 0v D1 A2 0v | toe switch
whisker | 0v A7 D0 C0 6v 0v | Pingpin
ShinFeeler | 0v D4 D5 A5 A6 0v | whisker
Eyes | 0v C1 C2 D6 D7 0v | ShinFeeler
\____________________________________/
front
Aux - [0v] [5v] [C.6/Hserout] [Serin] Serin is with usual 10k to 0v and 22k to Serin
whisker/feeler - [0v] [LEDsupply] [photoA/D]
eyes - [0v] [left] [right]
ping - [0v] [6v] [signal]
servo - [0v] [6v] [signal]
#endrem
'==================================================
Pins:
'==========================
SYMBOL servoLA =A.1
SYMBOL servoLH =A.0
SYMBOL servoRA =D.3
SYMBOL servoRH =D.2
SYMBOL whiskerLLED =A.6 '1=on
SYMBOL whiskerRLED =A.7 '1=on
SYMBOL whiskerL =A.5 'READADC needs port.pin not a symbol
SYMBOL whiskerR =D.0 'READADC needs port.pin not a symbol
SYMBOL EyeLLED =C.2 '1=on
SYMBOL EyeRLED =C.1 '1=on
SYMBOL feelerLLED =D.7 '1=on
SYMBOL Lfeeler =pinD.6 'READADC needs port.pin not a symbol
SYMBOL Rfeeler =pinD.5 'READADC needs port.pin not a symbol
SYMBOL tipB =pinD.6
SYMBOL tipF =pinD.5
SYMBOL pin_tipB =D.6
SYMBOL pin_tipF =D.5
SYMBOL feelerRLED =D.4 '1=on
SYMBOL pingpin =C.0
SYMBOL voiceLED =C.5 '1=on
SYMBOL voice =C.5
SYMBOL senseLtoe =pinA.2
SYMBOL senseRtoe =pinD.1
SYMBOL inIR =A.3
SYMBOL inIRpin =pinA.3
'SYMBOL O_LCD =A.4
'bus B.7 - B.0
'==================================================
VarsCons:
'==================================================
'Speed - for IR [9]{[1],[2],[3]
SYMBOL sslow ="1" 'speed slow
SYMBOL snormal ="3" 'speed normal
SYMBOL sfast ="6" 'speed fast
'==================================================
'Vitality - for IR [9]{[4],[5],[6]
'SYMBOL vls ="1" 'slow speed - not enough room to process this
'SYMBOL vns ="3" 'normal speed - not enough room to process this
'SYMBOL vhs ="6" 'fast speed - not enough room to process this
'SYMBOL vxs ="9" 'extreme speed - not enough room to process this
SYMBOL vll ="1" 'low lift
SYMBOL vnl ="3" 'normal lift
SYMBOL vhl ="4" 'high lift
SYMBOL vxl ="7" 'extreme lift 8 ok Fd but falls over Bk, 7 Bk 5be Tall, 1=>Crawl Ullr
'W1
SYMBOL f8_Cmnder0 =b2
SYMBOL f_warm =bit16 '!---
SYMBOL f_play =bit17 '!---
SYMBOL f_record =bit18 '!---
SYMBOL f_recordC =bit19 '!---
SYMBOL f_waitcmnd =bit20 '!--- just wait for an IRkey or Serin
SYMBOL f_IRcmnd =bit21 '!r-- 1=>IRcmnd 0=>Serial/Play cmnd
SYMBOL f_page0 =bit22 'w-!- 1=Acts/Slots 01-07, 0(default) =1-8
'SYMBOL f_ =bit23 '
SYMBOL f8_doServos =b3 'ww--
SYMBOL f_RAdo =bit24 '-!-! do servo
SYMBOL f_RHdo =bit25 '-!-! do servo
SYMBOL f_LAdo =bit26 '-!-! do servo
SYMBOL f_LHdo =bit27 '-!-! do servo
SYMBOL f_RApulse =bit28 'r!-r pulse servos
SYMBOL f_RHpulse =bit29 'r!-r pulse servos
SYMBOL f_LApulse =bit30 'r!-r pulse servos
SYMBOL f_LHpulse =bit31 'r!-r pulse servos
'W2
SYMBOL W2pulse =w2
SYMBOL W2pulselo =b4
SYMBOL W2pulsehi =b5
SYMBOL W2temp =w2 'Interpage jumps for hserptr
SYMBOL W2templo =b4
SYMBOL W2temphi =b5
'SYMBOL W2temp0 =b4
'SYMBOL W2temp1 =b5
'W3
SYMBOL cmnd =b6
SYMBOL RootCmnd =b7
'SYMBOL servonum =b7 'SETUP
'W4
SYMBOL RHC =b8 'Right Hip Pace Centre for current posture
SYMBOL LHC =b9 'Left Hip Pace Centre for current posture
'W5
SYMBOL RAC =b10 'Right Hip Roll Centre for current posture
SYMBOL LAC =b11 'Left Hip Roll Centre for current posture
'W6
SYMBOL RHat =b12 'Servo Right Hip Pace At
SYMBOL RHto =b13 'Servo Right Hip Pace To
'W7
SYMBOL LHat =b14 'Servo Left Hip Pace At
SYMBOL LHto =b15 'Servo Left Hip Pace To
'W8
SYMBOL RAat =b16 'Servo Right Hip Roll At
SYMBOL RAto =b17 'Servo Right Hip Roll To
'W9
SYMBOL LAat =b18 'Servo Left Hip Roll At
SYMBOL LAto =b19 'Servo Left Hip Roll To
'W10
SYMBOL Sspeed =b20 '1-9
SYMBOL Sframe =b21 'Servo frame pause in ms
'W11
SYMBOL FL =b22 'Foot Lift UpDown movement
SYMBOL FP =b23 'Foot Pace ForwardBack movement
'W12
SYMBOL FT =b24 'Foot Turn
SYMBOL FLcmnd =b25 'Foot Lift UpDown movement 0-9
'W13
SYMBOL FPcmnd =b26 'Foot Pace ForwardBack movement 0-9
SYMBOL FTcmnd =b27 'Foot Turn movement 0-9
'W14
SYMBOL Scmnd =b28 'Speed 1-9
SYMBOL IRcmnd =b29
'W15
SYMBOL Actptr =b30
SYMBOL ActEnd =b31
'W16
SYMBOL slot =b32 'Acts 1-8 occupy Slots 0-7
SYMBOL hframes =b33 'halt frames
'W17
SYMBOL kickcmnd =b34
SYMBOL Speedmax =b35 '1-9
'W18
SYMBOL ReactAt =b36 'React Table pointer
SYMBOL TOD =b37 'Toes Offset Down 0-9
'W19
SYMBOL yawn =b38
'SYMBOL standOnLR =b39 '#1 %LR 1=down moving test toes if if <>%11
'W20
''SYMBOL topple =b40 'Thor
SYMBOL usdist =b41 'prog2
'W21
''SYMBOL Bo =b42 'lean back offset for backwards
''SYMBOL FLTmin =b42 'min Lift in Turns, Thor
SYMBOL TOO =b43 'Toes Offset Out (Front 'Freya, Thor)
'W22
SYMBOL W22random =w22 'b44,b45
SYMBOL W22random0 =b44
SYMBOL W22random1 =b45
'W23
SYMBOL DoAt =b46 'Pointer in Do
SYMBOL InDo =b47 'flag for In a Do
'W24
SYMBOL mindAt =b48 '
SYMBOL mindSub =b49 '
'W25
'W26
SYMBOL lastcmnd =b53 'only used at QIR: to stop repeat keys
'W27
'SYMBOL W27temp =w27 'prog1
'SYMBOL W27temp0 =b54 'prog1
'SYMBOL W27temp1 =b55 'prog1
'SYMBOL temp54 =b54 '
'SYMBOL temp55 =b55 'prog1
'---------
'Variables - Storage - peek and poke
'-------------------
'200 56 to 255 ($38 to $FF)
SYMBOL RAM_temp0 =56 'first non variable RAM location
'SYMBOL RAM_P1_f8_flags =57 'Prog1 flags
'turned Left bit 0 '1=last turned Left, 0=Right
''SYMBOL RAM_holedetectR =58 '
''SYMBOL RAM_holedetectL =59 '
SYMBOL RAM_obstaclesR =60 'map
SYMBOL RAM_obstaclesL =61 'map
SYMBOL RAM_lightR =62 'whisker ambient light level Right
SYMBOL RAM_lightL =63 'whisker ambient light level Left
SYMBOL RAM_UStoonear =64
SYMBOL RAM_USawareAt =65
SYMBOL RAM_USunits_cm_ =66
SYMBOL RAM_USlast =67
SYMBOL RAM_WhiskerR =68
SYMBOL RAM_WhiskerL =69
SYMBOL RAM_WhiskerRlit =70
SYMBOL RAM_WhiskerLlit =71
SYMBOL RAM_FeelerR =72
SYMBOL RAM_FeelerL =73
SYMBOL RAM_FeelerRlit =74
SYMBOL RAM_FeelerLlit =75
SYMBOL RAM_Wthresh =76
SYMBOL RAM_Fthresh =77
SYMBOL RAM_Sspeed =78
SYMBOL RAM_leglLift =79
'SYMBOL RAM_randvarLo =68
'SYMBOL RAM_randvarHi =69
'SYMBOL RAM_randseedlo =70
'SYMBOL RAM_randseedhi =71
SYMBOL RAM_LHpose =80
SYMBOL RAM_LApose =81
SYMBOL RAM_RHpose =82
SYMBOL RAM_RApose =83
SYMBOL EEPROM_LHC =255 'logical value
SYMBOL EEPROM_LAC =254 'logical value
SYMBOL EEPROM_RHC =253 'logical value
SYMBOL EEPROM_RAC =252 'logical value
SYMBOL EEPROM_TOO =251 'Toes Offset Out
SYMBOL EEPROM_FLcmnd =250 'Foot Lift movement 1-9
SYMBOL EEPROM_FPcmnd =249 'Pace ForwardBack movement 1-9
SYMBOL EEPROM_FTcmnd =248 'Foot Turn movement 1-9
SYMBOL EEPROM_Speeds =247 'HiNib=speedmax(9), LoNib=speed(1)
SYMBOL EEPROM_TOD =246 'Toes Offset Down
'SYMBOL EEPROM_Bo =245 'Back lean back
SYMBOL EEPROM_kickcmnd =244
SYMBOL EEPROM_f8_behaves =243
SYMBOL EEPROM_Wthresh =242
SYMBOL EEPROM_Fthresh =241
SYMBOL EEPROM_USawarenear =240 'start of last 16 byte slot
SYMBOL EEPROM_ActsEnd =239 'end of slot 06
'************************* Machine Dependent *****************************
'#rem
'==================================================
'SERVOS - ACTUAL values from .bpe - values are in 10us units
'Hips S03/2BB Ankles S06/2BB
'==================================================
SYMBOL SLHout = 60 ' 90 '55 servo stop
SYMBOL SLHmid =150 ' 0
SYMBOL SLHin =230 ' 80 '234 pot electronics max
SYMBOL SLAout =220 ' 89 '226 out hit
SYMBOL SLAstand =131 ' 0
SYMBOL SLAin = 55 ' 76 '49 hit
SYMBOL SRHout =245 ' 93
SYMBOL SRHmid =152 ' 0
SYMBOL SRHin = 60 ' 92
SYMBOL SRAout =65 ' 79 '55 parts hit out 50 servo stop S06
SYMBOL SRAstand =144 ' 0
SYMBOL SRAin =225 ' 81 '226 servostop S06
'Left hip out is -ve
'Left ankle out is +ve
'Right hip out is +ve
'Right ankle out is -ve
'==================================================
'LOGICAL
'foot toe in is ve - if Lfd,Rbk > left foot is in front on the ground
'ankle out is +ve
SYMBOL LHout =256 -SLHout '196
SYMBOL LHmid =256 -SLHmid '106
SYMBOL LHin =256 -SLHin ' 26
SYMBOL LAout =SLAout '220
SYMBOL LAstand =SLAstand '131
SYMBOL LAin =SLAin ' 55
SYMBOL RHout =SRHout '245
SYMBOL RHmid =SRHmid '152
SYMBOL RHin =SRHin ' 60
SYMBOL RAout =256 -SRAout '191
SYMBOL RAstand =256 -SRAstand '112
SYMBOL RAin =256 -SRAin ' 31
'for servo numbering in CaseAdjust:
SYMBOL LH =3
SYMBOL LA =2
SYMBOL RH =1
SYMBOL RA =0
'#endrem
'--------------------------------------------------------------
SYMBOL DSframe =15 'default SFrame, LOOPs at ~40Hz/25ms
'SYMBOL Fclear =19 'minimum for toes to miss when walking
SYMBOL TSO =5 'Toe Stand Offset - so toes clear each other
'************************* END Machine Dependent *************************
'=================================================================
TVR010_PicAxe_IR_controller:
'---------------------------
'Before use, the transmitter must be programmed with the 'Sony' transmit code.
'1. Insert 2 AAA size batteries, preferably alkaline.
'2. Press 'S' and 'B' at the same time. S is in the centre of the arrows.
' The top left red LED should light.
'3. Press '0'. The LED should flash.
'4. Press '1'. The LED should flash.
'5. Press '3'. The LED should go out.
'6. Press the red power button (top right).
'-------------------------------------------
'IRin cmnds PicAxe controller
'DO NOT PRESS OTHER KEYS
'ie [A] [B] [C] [D] [E] [F] [G]
'They change the Mode and [B] has to be pressed to change back.
'[square] [triangle] [()] [L] [X] [backwards F] have no effect
'{} original Bambino commands
SYMBOL KEY_POWER = 21 'Sleep
SYMBOL KEY_UP = 16 '[Fd] Step Forward {[9][Fd]=set vitality Behaviour to faster}
SYMBOL KEY_DOWN = 17 '[Bk] Step Backward {[9][Bk]=set vitality Behaviour to slower}
SYMBOL KEY_RIGHT = 18 '[Rt] Step Right
SYMBOL KEY_LEFT = 19 '[Lt] Step Left
SYMBOL KEY_BAR = 96 '[f|] learn an Act, next [key] selects an Act
SYMBOL KEY_TENT = 54 '[f^] next [key] selects a Subroutine-Act
SYMBOL KEY_VERT_CROSS = 37 'use synonym for easier coding
SYMBOL KEY_VCROSS = 37 '[f+] "z"
' { Modify Mode {when routine included}
' { [+] set USAwareAt in DUSawareAt}
' { [-] set UStoonear in DUStoonear}
' {[Fd] alter PaceCentre in DpaceC}
' {[Bk] alter PaceCentre in DpaceC}
' {[Rt] alter RollCentre in DrollC}
' {[Lt] alter RollCentre in DrollC}
' { [-][+] to adjust }
' [Key_POWER] to quit
SYMBOL KEY_DIAG_CROSS = 20 'use synonym for easier coding
SYMBOL KEY_XCROSS = 20 '[fX] " " '{transfer EEPROM to PC for including in programs}
' -- Subroutine-Act and Commands --
SYMBOL KEY_1 = 0 '[1] [f^][1]=>{RockADo} [9][1]=set speed slow
SYMBOL KEY_2 = 1 '[2] [9][2]=set speed medium
SYMBOL KEY_3 = 2 '[3] [9][3]=set speed fast
SYMBOL KEY_4 = 3 '[4] [9][4]=set vitality to Low {US behaviour to timid}
SYMBOL KEY_5 = 4 '[5] [9][5]=set vitality to Normal {US behaviour to normal}
SYMBOL KEY_6 = 5 '[6] [9][6]=set vitality to High {US behaviour to bold}
SYMBOL KEY_7 = 6 '[7] [9][7]=disable Whiskers test
SYMBOL KEY_8 = 7 '[8] [9][8]=disable Ultrasonic test
SYMBOL KEY_9 = 8 '[9] (set Behaviour modes) [9][9]= {set US behaviour to User}
SYMBOL KEY_MINUS = 98 '[-] enable & test Whisker sensors and re-act, R_Whiskers:
SYMBOL KEY_0 = 9 '[0] {WANDER} [9][0]=set vitality Behaviour to normal
SYMBOL KEY_PLUS = 11 '[+] enable & test Ping sensor and re-act, R_Ping:
'=================================================================
' INITIALISATION
'=================================================================
hserptr =W2temp 'get back pointer
SERTXD("{0") 'prognum
cmnd =255 'command done
IF f_warm=1 THEN Commander
'Init:
SERTXD(CR,"Loki8 9Aug23")
'adcsetup = %0000000011100000 not needed for new PIC18F45K22
HSERSETUP B19200_16,%01101 'don't need to redo this
' bit0 - background receive serial data
' bit1 - invert serial output data (0 = 'T', 1 = 'N')
' bit2 - invert serial input data (0 = 'T', 1 = 'N')
' bit3 - disable hserout (1 = hserout pin normal i/o)
' bit4 - disable hserin (1 = hserin pin normal i/o)
hserinflag =0
hserptr =0
ptr =0
'LoadBehaviour:
sertxd(CR,"LHC=",#LHC,CR) '=0 on powerup => not initialised
IF LHC=0 THEN :cmnd ="0" GOTO RUN2 ENDIF 'as "b0" Load behaviour
'Behaviour:
yawn ="0" 'not bored
Sframe =DSframe 'Servo Frame Pause
'Posture:
RHat =RHC +TSO 'Servo Right Pace At '+ Toe Stand Offset
LHat =LHC -TSO 'Servo Left Pace At '- Toe Stand Offset
RAat =RAC 'Servo Right Roll At
LAat =LAC 'Servo Left Roll At
RHto =RHat 'Servo Right Pace To
LHto =LHat 'Servo Left Pace To
RAto =RAat 'Servo Right Roll To
LAto =LAat 'Servo Left Roll To
f_b_F =1 'default going forwards
SERTXD(CR,"Start")
f_warm =1
f_page0 =0
ReactAt =ReactEnd 'otherwise does USaware@0
FOR temp0 =0 to 7
Actptr =temp0 *16 'Acts 1-8
READ Actptr,cmnd
IF cmnd="@" THEN :cmnd ="1" +temp0 :GOTO DoCmnd :ENDIF 'do autorun Act
NEXT
FOR temp0 =0 to 6
Actptr =temp0 *16 +128 'Acts 01-07
READ Actptr,cmnd
IF cmnd="@" THEN :f_page0 =1:cmnd ="1" +temp0 :GOTO DoCmnd :ENDIF 'do autorun Act
NEXT
cmnd ="I" rootcmnd =" " GOTO RUN1 'Init Legs, next entry will be warm->Commander
'====================================================
' LEAVES
'====================================================
ReProgram:
RECONNECT
pause 50
GOSUB bip
SERTXD("ReProgram")
END 'wait for new download
QRecRUN1: 'from 'CaseSubroutine: "a","^"
GOSUB QRecord
RUN1:
W2temp =hserptr 'preserve pointer
RUN 1
QRecRUN2:
GOSUB QRecord
RUN2:
W2temp =hserptr 'preserve pointer
RUN 2
RUN3:
W2temp =hserptr 'preserve pointer
RUN 3
'====================================================
' COMMANDER
'====================================================
Commander:
'SERTXD("Commander")
DO
DoCommands:
'sendF: 'test IR out
'low PingPin
'irout pingpin,1,16 :pause 30
'irout pingpin,1,16 :pause 30
'irout pingpin,1,16 :pause 30
'pause 1000
'goto sendF
IF f_record=1 THEN
HIGH voiceLED 'LED on
f_recordC =1
ELSE
LOW voiceLED 'LED off
ENDIF
IF f_record=0 AND f_play=0 THEN :sertxd(">") ENDIF
PWMOUT EyeLLED,255,10 'active high Dutycycle for dim
PWMOUT EyeRLED,255,10 'active high Dutycycle for dim
IF ReactAt=ReactEnd THEN 'leave on if reacting
LOW whiskerLLED 'turned on by NewMap
LOW whiskerRLED 'turned on by NewMap
LOW feelerLLED 'turned on by NewMap
LOW feelerRLED 'turned on by NewMap
ENDIF
lastcmnd =cmnd
GOSUB GetCmnd 'and update servos while waiting
Rootcmnd =" "
'-----------------------------
'TranslateIR:
IF f_IRcmnd=0 THEN DoCmnd
'translate some Bambino IR cmnds
SELECT cmnd
CASE "."
hserinflag =0 'Flush Serial buffer
ptr =hserptr -1
CASE "^"
cmnd ="a" GOSUB QRecord : GOSUB GetSubCmndIR 'and update servos while waiting
RootCmnd="a" :GOTO QRecRUN1
CASE "$"
GOSUB GetSubCmndIR :RootCmnd="$" :GOTO QRecRUN1
CASE "9" 'sertxd("case9")
GOSUB GetSubCmndIR
SELECT cmnd
speed1: CASE "1" 'set speed slow
Scmnd =sslow :GOTO mQrecS
speed2: CASE "2" 'set speed normal
Scmnd =snormal :GOTO mQrecS
speed3: CASE "3" 'set speed fast
Scmnd =sfast
mQrecS: f_Bmodified =1
IF f_record=1 THEN
cmnd ="s" GOSUB Record :cmnd =Scmnd :GOSUB Record
ENDIF
vitalL: CASE "4" 'set vitality low
FLcmnd =vll :FPcmnd =vlp :kickcmnd =vlk :temp0 ="l" :GOTO mQrecV
vitalN: CASE "5" 'set vitality normal
FLcmnd =vnl :FPcmnd =vnp :kickcmnd =vnk :temp0 ="n" :GOTO mQrecV
vitalH: CASE "6" 'set vitality high
FLcmnd =vhl :FPcmnd =vhp :kickcmnd =vhk :temp0 ="h"
mQrecV: FTcmnd =FPcmnd
f_Bmodified =1
IF f_record=1 THEN
cmnd ="b" GOSUB Record :cmnd ="v" :GOSUB Record :cmnd =temp0 :GOSUB Record
ENDIF
CASE "7"
CASE "8"
CASE "9"
CASE "0"
CASE "+" f_b_autosense =0 temp0 =cmnd GOTO _sensQrec 'auto sense off
CASE "-" f_b_react =0 temp0 =cmnd 'sensor react off
_sensQrec:IF f_record=1 THEN
cmnd ="b" GOSUB Record :cmnd ="$" :GOSUB Record :cmnd =temp0 :GOSUB Record
ENDIF
ELSE GOSUB tshh : cmnd ="Q" :SERTXD("[?IR]")
ENDSELECT
GOSUB noIRkey 'wait for finger off and clear cmnds processed above, RETURNS "z"
f_recordC=0 'don't record the "z"
'sertxd("IR",cmnd,"IR")
ENDSELECT
'====================================================
DoCmnd:
'sertxd("DoCmnd",cmnd)
'====================================================
'COMMANDS
SELECT cmnd
'CaseQuit:
CASE Esc,"Q","q"
cmnd ="." :DoAt =0 :InDo =0 :mindAt =0 :ReactAt =ReactEnd :GOTO DoCmnd
'CaseStop
CASE "."
IF ReactAt<>ReactEnd THEN :ReactAt =ReactEnd :GOTO DoCommands :ENDIF
IF f_record=0 AND f_play=0 THEN
cmnd ="H" : GOTO RUN1 'Halt
ENDIF
IF f_record=1 THEN
WRITE Actptr,"."
f_record =0
ENDIF
IF f_play=1 THEN
f_play =0
ENDIF
yawn ="0"
IF DoAt<>0 THEN
SERTXD("(",#DoAt,")");
Actptr =DoAt :DoAt =0 :f_play =1 :InDo =1 'back in the Do
ENDIF
'CaseDo:
CASE "(": InDo =1
CASE ")": InDo =0
'CaseMove:
CASE "F","B","R","L","H","I","K","M","<",">" :GOTO QRecRUN1
CASE "E" GOTO RUN2
CASE "V" GOSUB bip
'CaseIgnore:
CASE ","," " 'ignore comma, space
CASE 10,13 : f_recordC=0 'ignore LF,CR and don't record them
'CaseNextSlot:
CASE ";" GOSUB QRecord
Slot =Slot +1 //8 'continue in next slot
IF Actptr<128 THEN :Actptr =0 :ELSE Actptr =128 :ENDIF 'keep in same page
Actptr =Slot *16 +Actptr
f_record =0 '2022-09-07 don't write in next slot
'CaseSleep:
CASE "z","Z" : f8_doServos =0 'sleep
'CaseAct:
CASE "@" 'marker for autorun, so ignore it
CASE "0" f_page0 =1
CASE "1" TO "8"
IF f_record=0 THEN
IF InDo=1 AND DoAt=0 THEN
DoAt =Actptr :SERTXD("(@",#DoAt,")");
InDo =0; 'because we are jumping to another Act
ENDIF
Slot =cmnd -"1" 'Logical Act 0 - 7
Actptr =f_page0 *128
Actptr =Slot *16 +Actptr
f_page0 =0 'back to default
f_play =1
ENDIF
'CaseSensors:
CASE "-" f_b_react=1 :GOTO doSensors 'from IR
CASE "+" f_b_react=1 :GOTO doSensors 'from IR
'CaseAlive:
CASE "A" mindAt =mindstart
'PARAMETER-COMMANDS
'CaseTransmitIR
' CASE "C" GOSUB GetSubCmnd
' if cmnd="F" then :irout pingpin,1,16 :endif
' if cmnd="B" then :irout pingpin,1,17 :endif
'CaseSensors:
CASE "$" GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
doSensors: RootCmnd="$" :GOTO QRecRUN1
'CaseWait:
CASE "w"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" f_waitcmnd =1
CASE "1" TO "9"
GOSUB QRecord
hframes =cmnd -"0" *25 'units about 1/2 sec
cmnd="M" GOTO RUN1
ELSE cmnd ="?"
ENDSELECT
'CaseTalkAli:
CASE "T"
'0 1300 "So you think you're pretty"
'1 2295 "So you think you're pretty, well I'm the prettiest"
'2 5500 "So you think....I am the greatest"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
cmnd =cmnd -"0"
W2temp =0
LOOKUP cmnd,(1300,2295,5500),W2temp
W2temp =W2temp *2 '8MHz to 16Mhz
HIGH VoiceLED
HIGH C.6 'power to TalkAli module
PAUSE W2temp
INPUT C.6 'power down TalkAli module
'CaseGetUp:
CASE "u"
GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
f_b_autoUp =0 'else action gets done twicw
RootCmnd="u" :GOTO QRecRUN1
'CaseTurn: 'm o a t r l
CASE "t"
GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
RootCmnd ="t" GOTO QRecRUN1
'CaseVoice:
CASE "v"
GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
RootCmnd="v" :GOTO QRecRUN2
'Case eye:
CASE "e"
GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
rootcmnd ="e" GOTO QRecRUN2
'CasePoses:
CASE "p"
GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
RootCmnd="p" :GOTO QRecRUN1
'Position 0 in, 5 mid, 9 out
CASE "P"
Rootcmnd =cmnd
GOSUB GetSubCmnd POKE RAM_LHpose,cmnd
GOSUB GetSubCmnd POKE RAM_LApose,cmnd
GOSUB GetSubCmnd POKE RAM_RApose,cmnd
GOSUB GetSubCmnd POKE RAM_RHpose,cmnd
GOTO Run1
'CaseSubroutine:
CASE "a"
GOSUB QRecord :GOSUB GetSubCmnd 'and update servos while waiting
RootCmnd="a" :GOTO QRecRUN1
'Case Control:
' CASE 92,"k" '92 is "\" which gives syntax error here!!!
' GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
' SELECT cmnd
' ENDSELECT
'CaseBehave_Speed:
CASE "s"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "1" TO "9" Scmnd =cmnd
CASE "d","-" Sspeed =Sspeed /2 MIN 1 :Scmnd ="0" +Sspeed
CASE "u","+" Sspeed =Sspeed +1 MAX Speedmax :Scmnd ="0" +Sspeed
CASE "m" Speedmax =Scmnd -"0"
ELSE GOSUB tshh Scmnd ="1"
ENDSELECT
f_Bmodified =1
'CaseBehave_Yawn:
CASE "y"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "1" TO "9"
IF f_play=1 THEN
yawn =yawn +1
IF yawn>=cmnd THEN :Actptr =Actptr +1 :yawn ="0" :ENDIF
ENDIF
ENDSELECT
'------------------
'BEHAVE:
'CaseBehave
CASE "b" 'I0SlptodkTCug$UWF@ 0$@ CFISTUW dgkloptu
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd ' 0 FSUW bdfgklpstu $@
' b_Initialise 'Initialise EEPROM with defaults
CASE "I" GOTO QRecRun2
' b_Behave_Default
CASE "0" GOTO QRecRun2 'LoadBehaviour
' b_Save_Defaults
CASE "S" GOTO QRecRun2 'save current behaviour to EEPROM
' b_Vigorous
CASE "V" GOTO case_bvh
' b_Normal
CASE "N" GOTO case_bvn
' b_Lethargic
CASE "L" GOTO case_bvl
' b_vitality
CASE "v"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "l"
case_bvl: FLcmnd =vll :FPcmnd =vlp :kickcmnd =vlk
CASE "n"
case_bvn: FLcmnd =vnl :FPcmnd =vnp :kickcmnd =vnk
CASE "h"
case_bvh: FLcmnd =vhl :FPcmnd =vhp :kickcmnd =vhk
CASE "x"
case_bvx: FLcmnd =vxl :FPcmnd =vxp :kickcmnd =vxk
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_lift
CASE "l"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9" : FLcmnd =cmnd
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_pace
CASE "p"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9" : FPcmnd =cmnd
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_turn
CASE "t"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9" : FTcmnd =cmnd
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_ToesOffsetOut
CASE "o" 'Toes Offset Out
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9" : TOO =cmnd -"0"
CASE "-" :GOSUB QRecord : GOSUB GetSubCmnd
SELECT cmnd
CASE "0" TO "9" : TOO =256 -cmnd +"0"
ELSE GOSUB tshh
ENDSELECT
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_ToesOffsetDown
CASE "d"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9" : TOD =cmnd -"0"
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_kick
CASE "k" 'kick
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9" : kickcmnd =cmnd
ELSE GOSUB tshh
ENDSELECT
f_Bmodified =1
' b_GetUp:
CASE "u"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" f_b_autoUp =0
CASE "1" f_b_autoUp =1
ELSE GOSUB tshh
ENDSELECT
' b_$ensor react
CASE "$"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "a" f_b_autosense =1
CASE "1" f_b_react =1
CASE "0" f_b_react =0 f_b_autosense =0
ELSE GOSUB tshh
ENDSELECT
' b_Ultrasonic_range
CASE "U"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" f_b_Uon =0
CASE "1" f_b_Uon =1 'enable Ultrasonic reactions
CASE "+"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "1" TO "9"
temp0 =cmnd -"0"
POKE RAM_USawareAt,temp0
ENDSELECT
CASE "-"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "1" TO "9"
temp0 =cmnd -"0"
POKE RAM_UStoonear,temp0
ENDSELECT
ELSE GOSUB tshh
ENDSELECT
' b_WhiskerThreshold
CASE "W"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "S" 'Scale
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9"
PEEK RAM_Wthresh,temp0 :temp0 =temp0 //10 'remove decade
temp0 =cmnd -"0" *10 +temp0 :POKE RAM_Wthresh,temp0
ELSE GOSUB tshh
ENDSELECT
CASE "0" TO "9"
PEEK RAM_Wthresh,temp0 :temp0 =temp0 /10 *10 'round to decades
temp0 =cmnd -"0" +temp0 :POKE RAM_Wthresh,temp0
ELSE GOSUB tshh
ENDSELECT
' b_FeelerThreshold
CASE "F"
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "S" 'Scale
GOSUB QRecord : GOSUB GetSubCmnd 'and update servos while waiting
SELECT cmnd
CASE "0" TO "9"
PEEK RAM_Fthresh,temp0 :temp0 =temp0 //10 'remove decade
temp0 =cmnd -"0" *10 +temp0 :POKE RAM_Fthresh,temp0
ELSE GOSUB tshh
ENDSELECT
CASE "0" TO "9"
PEEK RAM_Fthresh,temp0 :temp0 =temp0 /10 *10 'round to decades
temp0 =cmnd -"0" +temp0 :POKE RAM_Fthresh,temp0
ELSE GOSUB tshh
ENDSELECT
' b_AdjustServos
CASE "@" GOTO RUN3 'Adjust joints to determine Servo values for Pose
' b_ELSE
ELSE
GOSUB tshh
ENDSELECT 'Behaves
IF f_Bmodified =1 THEN : cmnd ="M" : GOTO RUN1 : ENDIF
'EndCaseBehaves:
'------------------
'CaseRecord:
CASE "r"
IF f_record=0 THEN
GOSUB GetSubCmndIR 'and update servos while waiting
f_recordC =0
ELSE
cmnd ="." 'if recording will end the recording
ENDIF
SELECT cmnd
CASE "1" TO "8"
IF f_page0=1 AND cmnd>"7" THEN :GOSUB badkey :GOTO EndRecordcmnd :ENDIF
Slot =cmnd -"1" 'Logical Act 0 - 7
Actptr =f_page0 *128
Actptr =Slot *16 +Actptr
f_page0 =0 'back to default
ActEnd =Actptr +15 MAX EEPROM_ActsEnd
IF Actptr>=ActEnd THEN RETURN :ENDIF 'don't overwrite BeHaves
f_record =1
HIGH voiceLED
IF f_IRcmnd=1 THEN
GOSUB noIRkey 'wait for finger off button
IF Slot=7 THEN : cmnd ="@" : f_recordC =1 : ENDIF 'for IR Act8 is always Autorun
ENDIF
ELSE GOSUB tshh
EndRecordcmnd:
ENDSELECT
'------------------
'SYSTEM
'CaseHelp
CASE "?" GOSUB QRecord :RootCmnd ="?" :GOSUB GetCmnd :GOTO QRecRUN2
'CaseExit
CASE "X" GOTO ReProgram
CASE "x" GOTO ReProgram
'CaseLoadAct:
CASE "l"
IF f_record=1 THEN 'otherwise recording continues in loaded Act!
f_record =0 WRITE Actptr,"."
ENDIF
GOSUB GetCmnd 'and update servos while waiting
IF cmnd="0" THEN :f_page0 =1 :GOSUB GetCmnd :ENDIF
SELECT cmnd
CASE "1" TO "8"
IF f_page0=1 AND cmnd>"7" THEN :GOSUB badkey :GOTO EndLoadcmnd :ENDIF
Slot =cmnd -"1" 'Logical Act 0 - 7
Actptr =f_page0 *128
Actptr =Slot *16 +Actptr
DO
GOSUB GetCmnd 'and update servos while waiting
IF Actptr=EEPROM_ActsEnd THEN :cmnd="." :ENDIF
IF cmnd=Esc OR cmnd="." OR cmnd=";" THEN EXIT
WRITE Actptr,cmnd
Actptr =Actptr +1
LOOP
IF cmnd<>";" THEN :cmnd ="." ENDIF
WRITE Actptr,cmnd
ELSE GOSUB tshh
EndLoadcmnd:
ENDSELECT 'cmnd
'CaseReset
CASE "¬" RESET
'Error:
ELSE GOSUB badkey f_recordC =0 'don't record a bad command
SERTXD("!",#cmnd,cmnd,"!")
ENDSELECT 'cmnd
'-----------------------------
GOSUB QRecord
LOOP
'====================================================
' SYSTEM
'====================================================
GetSubCmndIR: 'only "r","^","9" VCROSS="$"
IF inIRpin=0 THEN GOSUB noIRkey 'wait for finger off button
GetCmnd:
'sertxd(" GetCmnd")
QIR:
'sertxd(" QIR")
f_IRcmnd =0
IF inIRpin=0 THEN 'pulses low if IR being received, waiting for IRmsg messes up hserin
'sertxd("I")
IRIN[100,Qserial],inIR,IRcmnd 'msg 45ms interwordgap 40ms =85ms. 100 catches next word.
f_IRcmnd =1
'SOUND voice,(80,40) '~2.5*40ms =100ms takes us past the end of the next word
GOSUB bip
'must phase with the length of the IR word
'pause 20 'sometimes Play never gets started
'pause 50 'Play gets restarted
'pause 100 'Play doesn't get restarted
cmnd ="z"
LOOKDOWN IRcmnd,(KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9,KEY_0,KEY_MINUS,KEY_PLUS),cmnd
LOOKUP cmnd,("1","2","3","4","5","6","7","8","9","0","-","+"),cmnd
IF cmnd<>"z" THEN Gotcmnd
LOOKDOWN IRcmnd,(KEY_POWER,KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT,KEY_BAR,KEY_TENT,KEY_VCROSS,KEY_XCROSS),cmnd
LOOKUP cmnd, ( ".", "F", "B", "R", "L", "r", "^", "$", "z"),cmnd
IF cmnd="." AND mindAt<>0 THEN :cmnd ="Q" ENDIF
IF cmnd=lastcmnd THEN Qserial 'lastcmnd only used here, set to 0 for F B R L in prog1
IF cmnd<>"z" THEN Gotcmnd
'if bad IR then carry on
ENDIF
GetSubCmnd: 'here to miss repeated IR cmnds
Qserial:
'sertxd(" Qserial")
IF hserinflag=1 THEN ReadSerCmnd
QReact:
IF ReactAt<>ReactEnd THEN
READTABLE reactAt,cmnd :ReactAt =ReactAt +1
'sertxd("reactcmnd=",cmnd)
RETURN
ENDIF
QPlayAct:
'sertxd(" QPlayAct")
IF f_play=1 AND f_waitcmnd=0 THEN
READ Actptr,cmnd
IF cmnd=0 OR cmnd=255 THEN
cmnd ="." 'avoid uninitialised DATA
ENDIF
Actptr =Actptr +1
RETURN
ENDIF
QMind:
IF mindAt<>0 THEN
IF mindsub=0 THEN
RANDOM W22random
mindAt =W22random0 *W22random1 /256 /2 '0-127
IF mindAt<32 THEN
mindAt =mindAt +mindstart 'single char cmnds
mindsub =0
ELSE
mindAt =mindAt -32 /2 *2 +32 +mindstart
mindsub =mindAt +1
ENDIF
READTABLE mindAt,cmnd
ELSE
READTABLE mindsub,cmnd mindsub =0
ENDIF
RETURN
ENDIF
'RefreshServos:
GOSUB TellServos 'x TellServos, f_Spulse test is in Move,
'if Sspeed>1 then StandFoot bounces at end without this, pity
GOTO GetCmnd
'-----------------
ReadSerCmnd:
'@@@IF f_allSerial=1 THEN 'f_readAllSerial (re)set by load(0/all) "l0/a"
W2temp =ptr 'see if last cmnd was Quit
ptr =hserptr -1
cmnd =@ptrinc
IF cmnd="Q" OR cmnd=Esc THEN :hserinflag =0 :GOTO Qbip :ENDIF
ptr =W2temp 'if not Quit then carry on
cmnd =@ptrinc
IF ptr>=hserptr THEN
hserinflag =0
ptr =hserptr 'shouldn't be greater, but sometimes is - why?
ENDIF
'@@@ELSE
'@@@ ptr =hserptr -1 'one command at a time
'@@@ cmnd =@ptrinc
'@@@ hserinflag =0
'@@@ENDIF
Qbip:
#ifdef keybip
GOSUB bip
#endif
'-----------------
GotCmnd:
IF f_waitcmnd=1 THEN 'w0 waits for an IR or keycmnd
f_waitcmnd =0
IF cmnd="Q" OR cmnd=Esc or cmnd="." THEN :RETURN :ENDIF
IF f_play=1 THEN QPlayAct 'throw away command and resume playing iff playing
ENDIF
IF cmnd=Esc THEN
SERTXD("[Esc]")
ELSE
SERTXD(cmnd)
ENDIF
RETURN
'----------------------------------------------------
noIRkey:
sertxd("k")
IRIN [100,_noIRkeyend],inIR,IRcmnd 'IRIN timeout =>return
GOTO noIRkey
_noIRkeyend:
IRcmnd =255
cmnd ="z"
RETURN
'----------------------------------------------------
QRecord:
IF f_record=0 OR f_recordC=0 THEN RETURN ENDIF
Record:
HIGH voiceLED
IF Actptr>=EEPROM_ActsEnd THEN 'don't overwrite BeHaves
WRITE EEPROM_ActsEnd,"."
f_record =0
GOSUB tshh
GOSUB tshh
ELSE
WRITE Actptr,cmnd
ENDIF
Actptr =Actptr +1
IF Actptr>ActEnd THEN :f_record=0 :ENDIF '28May19 don't overwrite next slot
RETURN
'====================================================
' HMI
'====================================================
' SOUND voice,(sound,time) time=*~2.5ms @16MHz
bip:
SOUND voice,(80,7) '~17.5ms
RETURN
'-----------------------
tshh: 'because that is what it sounds like
SOUND voice,(240,20) '(255,10ms) @32MHz
RETURN
'-----------------------
badkey:
HIGH whiskerRLED
GOSUB tshh
LOW whiskerRLED
HIGH whiskerLLED
GOSUB tshh
LOW whiskerLLED
' PWMOUT EyeLLED,off
' PWMOUT EyeRLED,off
' HIGH EyeRLED
' GOSUB tshh
' LOW EyeRLED
' HIGH EyeLLED
' GOSUB tshh
' LOW EyeLLED
Z:
RETURN
'====================================================
'************************* Machine Dependent *** Servo direction *********
'SYMBOL servoLA =A.1
'SYMBOL servoLH =A.0
'SYMBOL servoRA =D.3
'SYMBOL servoRH =D.2
'SERTXD(#LAat,#LHat,#RHat,#RAat,cr)
TellServos: '@m16
'SERTXD("T")
IF f_RApulse=1 THEN
W2pulse =256 -RAat *4 'for 10us to 2.5us pulsout resolution, reverse servo
PULSOUT servoRA,W2pulse
ENDIF
IF f_LApulse=1 THEN
W2pulse =LAat *4 'for 10us to 2.5us pulsout resolution
PULSOUT servoLA,W2pulse
ENDIF
'TellHipServos: ' TellHipServos: only used in InitLegs:
IF f_LHpulse=1 THEN
W2pulse =256 -LHat *4 'for 10us to 2.5us pulsout resolution, reverse servo
PULSOUT servoLH,W2pulse
ENDIF
IF f_RHpulse=1 THEN
W2pulse =RHat *4 'for 10us to 2.5us pulsout resolution
PULSOUT servoRH,W2pulse
ENDIF
_Spause: 'pause Servo frame
W2pulse =Sframe *2 'Pause units 0.5ms @16MHz
PAUSE W2pulse
'************************* END Machine Dependent *************************
RETURN
'====================================================