BRAT NEWB SSC-32 BASIC code generator program

Hello!

I do not own a Basic Micro BasicATOM28-M (yet! :smiley: ) so the following is a small BASIC program that I’ve created to generate codes needed to use my BRAT with either a Parallax BS2 or a PICAXE-18X microcontroller. Of course, these microcontrollers do not have enough memory for this program:

lynxmotion.com/images/files/brata1.bas

But I want to thank (a lot! :smiley: ) Nathan Scherdin, Jim and James Frye for the above. It inspired me in creating the following BASIC program:

1000 cls
1010 righthip = 29
1020 rightknee = 30
1030 rightankle = 31
1040 lefthip = 13
1050 leftknee = 14
1060 leftankle = 15
1100 stepsperdegree = 166.6
1110 righthip_start = 0
1120 rightknee_start = 0
1130 rightankle_start = 0
1140 lefthip_start = 0
1150 leftknee_start = 0
1160 leftankle_start = 0
1170 lefthippos = 0
1180 leftkneepos = 0
1190 leftanklepos = 0
1200 righthippos = 0
1210 rightkneepos = 0
1220 rightanklepos = 0
1230 last_lefthippos = 0
1240 last_leftkneepos = 0
1250 last_leftanklepos = 0
1260 last_righthippos = 0
1270 last_rightkneepos = 0
1280 last_rightanklepos = 0
1290 lhspeed = 0
1300 lkspeed = 0
1310 laspeed = 0
1320 rhspeed = 0
1330 rkspeed = 0
1340 raspeed = 0
1350 speed = 0
1355 speed2 = 0
1360 longestmove = 0
1370 one = 0
1380 two = 0
1390 three = 0
1400 four = 0
1410 five = 0
1420 six = 0
1430 newpos = 0
1440 oldpos = 0
1450 longest = 0
1460 maxval = 0
1470 temp = 0
1480 lines =0
1490 dim position$(7)
1491 position$(1) = "rightanklepos"
1492 position$(2) = "rightkneepos"
1493 position$(3) = "righthippos"
1494 position$(4) = "leftanklepos"
1495 position$(5) = "leftkneepos"
1496 position$(6) = "lefthippos"
1497 position$(7) = "speed"

1500 print "B.R.A.T. angle position conversion"
1510 print "----------------------------------"
1520 print
1530 print "SSC-32 pin #";lefthip ;" =  LH hip"
1540 print "SSC-32 pin #";leftknee ;" =  LH knee"
1550 print "SSC-32 pin #";leftankle ;" =  LH ankle"
1560 print "SSC-32 pin #";righthip ;" =  RH hip"
1570 print "SSC-32 pin #";rightknee ;" =  RH knee"
1580 print "SSC-32 pin #";rightankle ;" =  RH ankle"
1600 print:input "Number of lines to convert?:";lines:print
1610 if lines > 0 then goto 1630
1620 print "Please enter a positive number other than zero.":goto 1600 
1630 dim codes(lines*7)
1640 for a = 0 to lines-1
1650 	print "Please enter angles & speed for line #";a+1
1660 	for b = 1 to 7
1670 		print position$(b)":";
1680 		input"?";codes(a*7+b)
1690 	next
1700 	print
1710 next


2000 for a = 0 to lines-1
2020 	rightanklepos = codes(a*7+1)
2030 	rightkneepos = codes(a*7+2)
2040	 righthippos = codes(a*7+3)
2050 	leftanklepos = codes(a*7+4)
2060 	leftkneepos = codes(a*7+5)
2070 	lefthippos = codes(a*7+6)
2080 	speed = codes(a*7+7)
2090 	speed2 = speed
2100 	gosub 10000
2110 next 
3000 print
3010 print "These codes can be sent serially to the SSC-32 card."
3020 print "Just copy from this screen & paste into your program. Thank you."
3030 print 
9999 end

10000 rem movement [rightanklepos,rightkneepos,righthippos,leftanklepos,leftkneepos,lefthippos,speed]
10010 if (speed <> 0) then 10030
10020 goto 11000
10030 rem gosub getlongest[lefthippos-last_lefthippos, |
10040 rem leftkneepos-last_leftkneepos, |
10050 rem leftanklepos-last_leftanklepos, |
10060 rem righthippos-last_righthippos, |
10070 rem rightkneepos-last_rightkneepos, |
10080 rem rightanklepos-last_rightanklepos],longestmove
10100 one = lefthippos-last_lefthippos
10110 two = leftkneepos-last_leftkneepos
10120 three = leftanklepos-last_leftanklepos
10130 four = righthippos-last_righthippos
10140 five = rightkneepos-last_rightkneepos
10150 six = rightanklepos-last_rightanklepos
10200 if (one < 0) then one = -1*one
10210 if (two < 0) then two = -1*two
10220 if (three < 0) then three = -1*three
10230 if (four < 0) then four = -1*four
10240 if (five < 0) then five = -1*five
10250 if (six < 0) then six = -1*six
10260 if (one < two) then one = two
10270 if (one < three) then one = three
10280 if (one < four) then one = four
10290 if (one < five) then one = five
10300 if (one < six) then one = six
10310 longestmove = one
10320 speed = ((longestmove*stepsperdegree)/(speed/20))
10330 rem gosub getspeed[lefthippos,last_lefthippos,longestmove,speed],lhspeed 
10340 rem getspeed[newpos,oldpos,longest,maxval]
10350 newpos = lefthippos
10360 oldpos = last_lefthippos
10370 longest = longestmove
10380 maxval = speed
10390 if (newpos > oldpos) then lhspeed = ((newpos-oldpos)/longest)*maxval : goto 10410
10400 lhspeed = ((oldpos-newpos)/longest)*maxval
10410 rem gosub getspeed[leftkneepos,last_leftkneepos,longestmove,speed],lkspeed
10420 newpos = leftkneepos
10430 oldpos = last_leftkneepos
10440 longest = longestmove
10450 maxval = speed
10460 if (newpos > oldpos) then lkspeed = ((newpos-oldpos)/longest)*maxval : goto 10480
10470 lkspeed = ((oldpos-newpos)/longest)*maxval
10480 rem gosub getspeed[leftanklepos,last_leftanklepos,longestmove,speed],laspeed
10490 newpos = leftanklepos
10500 oldpos = last_leftanklepos
10510 longest = longestmove
10520 maxval = speed
10530 if (newpos > oldpos) then laspeed = ((newpos-oldpos)/longest)*maxval : goto 10550
10540 laspeed = ((oldpos-newpos)/longest)*maxval
10550 rem gosub getspeed[righthippos,last_righthippos,longestmove,speed],rhspeed
10560 newpos = righthippos
10570 oldpos = last_righthippos
10580 longest = longestmove
10590 maxval = speed
10600 if (newpos > oldpos) then rhspeed = ((newpos-oldpos)/longest)*maxval : goto 10620
10610 rhspeed = ((oldpos-newpos)/longest)*maxval
10620 rem gosub getspeed[rightkneepos,last_rightkneepos,longestmove,speed],rkspeed
10630 newpos = rightkneepos
10640 oldpos = last_rightkneepos
10650 longest = longestmove
10660 maxval = speed
10670 if (newpos > oldpos) then rkspeed = ((newpos-oldpos)/longest)*maxval : goto 10690
10680 rkspeed = ((oldpos-newpos)/longest)*maxval
10690 rem gosub getspeed[rightanklepos,last_rightanklepos,longestmove,speed],raspeed
10700 newpos = rightanklepos
10710 oldpos = last_rightanklepos
10720 longest = longestmove
10730 maxval = speed
10740 if (newpos > oldpos) then raspeed = ((newpos-oldpos)/longest)*maxval : goto 10760
10750 raspeed = ((oldpos-newpos)/longest)*maxval
10760 rem
10770 goto 12000
11000 lhspeed = 0
11110 lkspeed = 0
11120 laspeed = 0
11130 rhspeed = 0
11140 rkspeed = 0
11150 raspeed = 0
12000 rem
12010 temp = int(1500+(int((-lefthippos*stepsperdegree)+lefthip_start)/10))
12020 print "#";lefthip;"p";temp;
12030 temp = int(1500+(int((righthippos*stepsperdegree)+righthip_start)/10))
12040 print "#";righthip;"p";temp;
12050 temp = int(1500+(int((-leftkneepos*stepsperdegree)+leftknee_start)/10))
12060 print "#";leftknee;"p";temp;
12070 temp = int(1500+(int((rightkneepos*stepsperdegree)+rightknee_start)/10))
12080 print "#";rightknee;"p";temp;
12090 temp = int(1500+(int((-leftanklepos*stepsperdegree)+leftankle_start)/10))
12100 print "#";leftankle;"p";temp;
12110 temp = int(1500+(int((rightanklepos*stepsperdegree)+rightankle_start)/10))
12120 print "#";rightankle;"p";temp;
12130 print "T";speed2
13000 return

You will need a BASIC interpreter found at the following:

nicholson.com/rhn/basic/

to run the program (or any other BASIC interpreter you prefer! :smiley: ).

Run the program and use the following line of code as an example:

gosub movement   7.0,-20.0,-20.0, -7.0, 20.0, 20.0, 500.0]

When the BASIC programs runs, it will ask for the number of lines to enter. The above line counts as 1. Enter as many as needed.

The program will then ask for:

rightanklepos:?

You would enter:

7.0

and then

rightkneepos:?

enter:

-20

and so on… Try it and see for yourself! :smiley:

Here is a working Parallax BS2 program I’ve used with success:

' BRAT PROGRAM
'{$STAMP BS2}
'{$PBASIC 2.5}

' VARIABLES & CONSTANTS

' available RAM memory
' w0 thru w12
' set SSC-32 @ 38.4k baud rate


' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle

Main:
PAUSE 2000

GOSUB reset

' *** bend hips forward
SEROUT 0,6,"#13 P1800 #14 P1500 #15 P1500 #29 P1200 #30 P1500 #31 P1500 T1000",13]
PAUSE 1000

GOSUB reset

start:
FOR B1 = 1 TO 5
  SEROUT 0,6,"#13 p1166 #29 p1166 #14 p1166 #30 p1166 #15 p1616 #31 p1616 T1000",13]
  PAUSE 500
  SEROUT 0,6,"#13 p1166 #29 p1166 #14 p1166 #30 p1166 #15 p1383 #31 p1383 T1000",13]
  PAUSE 500
  SEROUT 0,6,"#13 p1833 #29 p1833 #14 p1833 #30 p1833 #15 p1383 #31 p1383 T1000",13]
  PAUSE 500
  SEROUT 0,6,"#13 p1833 #29 p1833 #14 p1833 #30 p1833 #15 p1616 #31 p1616 T1000",13]
  PAUSE 500
NEXT







GOSUB reset

DEBUG "End of sequence",CR

PAUSE 5000
GOTO start

END

'Reset position
reset:
SEROUT 0,6,"#13 P1500 #14 P1500 #15 P1500 #29 P1500 #30 P1500 #31 P1500 T1000",13]
PAUSE 1000
RETURN

This will make the BRAT walk slowly forward until you turn it off.
Please note the pinout for the BRAT servos to the SSC-32 card found at the begining of the program.
Don’t forget to also set the SSC-32 card @ a 38.4k baud rate. In this program, I’ve used pin P0 (pin 5) on the BS2 for communication with the SSC-32.

Of course, this is only a start. With the limited memory of the BS2 or PICAXE, I created these programs to try out my BRAT without an ATOM! :smiley:
In no case do I pretend to know how to make the BRAT do everything I want to yet and some of the “T” times and/or PAUSEs may need adjustment, but at least it’s a start! :smiley:

My next idea is to use a BS2 along with a 64K I2Câ„¢ Smart Serialâ„¢ EEPROM such as the 24C65 I have lying around to store those lenghty codes needed for the BRAT. That way, I could maybe squeeze in a more interesting program in the BS2 instead of all those lines of codes! :smiley:

Hopefully, this will help somebody try out their BRATs!

Enjoy! :smiley: