by Tim » Tue Feb 05, 2008 10:48 am
by Tim
Tue Feb 05, 2008 10:48 am
Hi Visuvius
Glad to be of help
I suspect your latest problem is that when you push a key that falls outside the range of the valid options in the on .. goto statement for the bank you are in, it will cause the code to find its way back to MAIN: and you have to start over.
You can avoid all that by implementing the following approach where the bank select keys are just like any other 'move', except that they change the context (i.e. the bank). That context is picked up every time you process a move key. You'll see that I've kept the default behaviour for all banks except for the first say 2 - 6 moves where I have new code. This means the favourites like walk forward/backward cartwheel/tumble etc are always available if you so wish (not that this is a new feature), also note that you have to keep the K18,K23,K32 the same in each bank's on_goto so that you can change the bank! This is just what I blatted down after reading this thread so nothing exactly new here . . . .
'<snip>
DIM BANKSEL AS BYTE 'Used for code banking
'E key => BANKSEL = 0 => default routines
'F key => BANKSEL = 1 => dance and routines
'G key => BANKSEL = 2 => combat and sonar routines
'<snip>
GOSUB standard_pose
GOSUB gyro_setup
BANKSEL = 0 ' default bank
MAIN:
'GOSUB robot_voltage
GOSUB robot_tilt
'-----------------------------
IF RR = 0 THEN GOTO MAIN1
ON RR GOTO MAIN,K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO main_exit
'-----------------------------
MAIN1: 'this is the remote control section
A = REMOCON(1)
A = A - ID
IF BANKSEL > 2 THEN BANKSEL = 2 'only three banks at the minute
ON BANKSEL GOTO default_bank, cute_bank, combat_bank
default_bank:
ON A GOTO MAIN,K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
cute_bank:
ON A GOTO MAIN,a1,a2,a3,a4,a5,a6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
combat_bank:
ON A GOTO MAIN,b1,b2,b3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
'<snip>
k18: ' E
TEMPO 230
MUSIC "CDE"
BANKSEL = 0
GOTO main_exit
'<snip>
k23: ' G (not F!)
TEMPO 230
MUSIC "EF"
BANKSEL = 2 ' combat_bank
GOTO main_exit
'<snip>
k32: ' F
TEMPO 230
MUSIC "CCFC"
BANKSEL = 1 ' cute bank
GOTO main_exit
'==================================
' CUTE BANK
a1:
GOSUB butt_scratch
SPEED 10
GOSUB standard_pose
GOTO main_exit
a2:
GOSUB ymca
SPEED 10
GOSUB standard_pose
GOTO main_exit
a3:
GOSUB tip_toes
SPEED 10
GOSUB standard_pose
GOTO main_exit
a4:
GOSUB led_toggle
SPEED 10
GOSUB standard_pose
GOTO main_exit
a5:
GOSUB led_toggle2
SPEED 10
GOSUB standard_pose
GOTO main_exit
a6:
GOSUB govenor
SPEED 10
GOSUB standard_pose
GOTO main_exit
'===================================
' COMBAT BANK
b1:
GOSUB sonar_grab
SPEED 10
GOSUB standard_pose
GOTO main_exit
b2:
GOSUB map_right_attack
SPEED 10
GOSUB standard_pose
GOTO main_exit
b3:
GOSUB martial_arts_pose
DELAY 500
GOSUB standard_pose
GOTO main_exit
'<snip> That's all folks.
oh - to add a new move, say called 'hug' on key 9 in the cute_bank you need to do the following three things:-
1/ change the routine called when you hit key 9 in cute bank from k9 to a9, like so:
cute_bank:
ON A GOTO MAIN,a1,a2,a3,a4,a5,a6,K7,K8,a9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
2/ add some code with label a9 to call your routine
a9:
GOSUB hug
SPEED 10
GOSUB standard_pose
GOTO main_exit
3/ implement your new code
hug:
'do something interesting.
RETURN
That should improve things for you
Also, if you get tempted to make the bank_select tunes longer (the ones that play when you hit E,F,G), you might find RN-1 falls over. It would seem that the motors are relaxed whilst he is whistling, so my attempt at a (unfortunately high-pitched) recreation of an 8 note jaws theme for the combat section just meant he fell over whilst waiting for the tune to finish! F
Cheers
Tim
Hi Visuvius
Glad to be of help
I suspect your latest problem is that when you push a key that falls outside the range of the valid options in the on .. goto statement for the bank you are in, it will cause the code to find its way back to MAIN: and you have to start over.
You can avoid all that by implementing the following approach where the bank select keys are just like any other 'move', except that they change the context (i.e. the bank). That context is picked up every time you process a move key. You'll see that I've kept the default behaviour for all banks except for the first say 2 - 6 moves where I have new code. This means the favourites like walk forward/backward cartwheel/tumble etc are always available if you so wish (not that this is a new feature), also note that you have to keep the K18,K23,K32 the same in each bank's on_goto so that you can change the bank! This is just what I blatted down after reading this thread so nothing exactly new here . . . .
'<snip>
DIM BANKSEL AS BYTE 'Used for code banking
'E key => BANKSEL = 0 => default routines
'F key => BANKSEL = 1 => dance and routines
'G key => BANKSEL = 2 => combat and sonar routines
'<snip>
GOSUB standard_pose
GOSUB gyro_setup
BANKSEL = 0 ' default bank
MAIN:
'GOSUB robot_voltage
GOSUB robot_tilt
'-----------------------------
IF RR = 0 THEN GOTO MAIN1
ON RR GOTO MAIN,K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO main_exit
'-----------------------------
MAIN1: 'this is the remote control section
A = REMOCON(1)
A = A - ID
IF BANKSEL > 2 THEN BANKSEL = 2 'only three banks at the minute
ON BANKSEL GOTO default_bank, cute_bank, combat_bank
default_bank:
ON A GOTO MAIN,K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
cute_bank:
ON A GOTO MAIN,a1,a2,a3,a4,a5,a6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
combat_bank:
ON A GOTO MAIN,b1,b2,b3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
'<snip>
k18: ' E
TEMPO 230
MUSIC "CDE"
BANKSEL = 0
GOTO main_exit
'<snip>
k23: ' G (not F!)
TEMPO 230
MUSIC "EF"
BANKSEL = 2 ' combat_bank
GOTO main_exit
'<snip>
k32: ' F
TEMPO 230
MUSIC "CCFC"
BANKSEL = 1 ' cute bank
GOTO main_exit
'==================================
' CUTE BANK
a1:
GOSUB butt_scratch
SPEED 10
GOSUB standard_pose
GOTO main_exit
a2:
GOSUB ymca
SPEED 10
GOSUB standard_pose
GOTO main_exit
a3:
GOSUB tip_toes
SPEED 10
GOSUB standard_pose
GOTO main_exit
a4:
GOSUB led_toggle
SPEED 10
GOSUB standard_pose
GOTO main_exit
a5:
GOSUB led_toggle2
SPEED 10
GOSUB standard_pose
GOTO main_exit
a6:
GOSUB govenor
SPEED 10
GOSUB standard_pose
GOTO main_exit
'===================================
' COMBAT BANK
b1:
GOSUB sonar_grab
SPEED 10
GOSUB standard_pose
GOTO main_exit
b2:
GOSUB map_right_attack
SPEED 10
GOSUB standard_pose
GOTO main_exit
b3:
GOSUB martial_arts_pose
DELAY 500
GOSUB standard_pose
GOTO main_exit
'<snip> That's all folks.
oh - to add a new move, say called 'hug' on key 9 in the cute_bank you need to do the following three things:-
1/ change the routine called when you hit key 9 in cute bank from k9 to a9, like so:
cute_bank:
ON A GOTO MAIN,a1,a2,a3,a4,a5,a6,K7,K8,a9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K30,K31,K32
GOTO MAIN
2/ add some code with label a9 to call your routine
a9:
GOSUB hug
SPEED 10
GOSUB standard_pose
GOTO main_exit
3/ implement your new code
hug:
'do something interesting.
RETURN
That should improve things for you
Also, if you get tempted to make the bank_select tunes longer (the ones that play when you hit E,F,G), you might find RN-1 falls over. It would seem that the motors are relaxed whilst he is whistling, so my attempt at a (unfortunately high-pitched) recreation of an 8 note jaws theme for the combat section just meant he fell over whilst waiting for the tune to finish! F
Cheers
Tim