Not that sneaky… lol
D’oh!
D’oh!
Oh, you people… Get outta my thread!
Oh oh… now you done it… you’ve fed the fanbois.
Beth, If I were you, I would demand a flat panel monitor as pay back. I have not seen a CRT in quite some time!
Ahaha, funny, Eddie.
Mike, that picture’s several years old - now I’ve got dual flat-panel monitors, ninja-like camera avoiding skills, and different color hair! 8)
Though I could use a third monitor…
Aaaaanyway. Getting back on track here.
I’ve been messing around with the code and I’ve come up with a few new (much needed) features.
-
You can now aim up/down by using the hip servos to change the guns’ angle. It’s not such a dramatic effect when aiming to the side, but it gets the job done while keeping servos (and therefore weight) to a minimum.
-
Variable gait speed… Which is always nice to have.
New videos in just a few minutes 8)
In the meantime (and for anyone who wants to create a similar bot)…
Here’s the current code I’m using:
[code]
;System variables
righthip con p5
rightknee con p4
rightankle con p3
lefthip con p2
leftknee con p1
leftankle con p0
turret con p6
RGUNP con p16
RGswP con p17
LGUNP con p18
LGswP con p19
LaserPin con p7
;[PS2 Controller]
PS2DAT con P12 ;PS2 Controller DAT (Brown)
PS2CMD con P13 ;PS2 controller CMD (Orange)
PS2SEL con P14 ;PS2 Controller SEL (Blue)
PS2CLK con P15 ;PS2 Controller CLK (White)
PadMode con $79
TRUE con 1
FALSE con 0
BUTTON_DOWN con 0
BUTTON_UP con 1
TravelDeadZone con 4 ;The deadzone for the analog input from the remote
;calibrate steps per degree.
stepsperdegree fcon 166.6
;You must calibrate the servos to “zero”. Each robot will be different!
;When homed in and servos are at 0 degrees the robot should be standing
;straight with the AtomPro chip pointing backward. If you know the number
;of degrees the servo is off, you can calculate the value. 166.6 steps
;per degree. The values for our test robot were found by running the
;program bratosf.bas written by James Frye.
righthip_start con 540
rightknee_start con -240
rightankle_start con 300
lefthip_start con -1140
leftknee_start con -120
leftankle_start con -660
turret_start con 0
;Interrupt init
ENABLEHSERVO
command var byte
xx var byte
RSwitch var bit
PrevRSW var bit
LSwitch var bit
PrevLSW var bit
TurretAngle var sword
LHipAngle var sword
RHipAngle var sword
IdleBot var word
WalkSpeed var float
TravLength var byte
TravLength = 6
LastStep var byte
LastStep = 0
LaserOn var bit
LaserOn = FALSE
BotActive var bit
BotActive = FALSE
;[Ps2 Controller]
DualShock var Byte(7)
LastButton var Byte(2)
DS2Mode var Byte
PS2Index var byte
BodyYShift var sbyte
;PS2 controller
high PS2CLK
LastButton(0) = 255
LastButton(1) = 255
;Init positions
;Note, movement subroutine arguments are Rightankle,Rightknee,Righthip,Leftankle,Leftknee,Lefthip,Turret,speed
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
hservo [Turret(TurretAngle + turret_start)\0]
;Gun/Laser Initialization
hservo [RGUNP\0\0,LGUNP\0\0,LaserPin\0\0]
;low 1
;low 2
pause 1000
;---------------------------------------;
;--------Command Quick Reference--------;
;---------------------------------------;
;- Command 1 = Walk Forward -;
;- Command 2 = Walk Backward -;
;- Command 3 = Long Stride Forward -;
;- Command 4 = Long Stride Backward -;
;- Command 5 = Kick -;
;- Command 6 = Headbutt -;
;- Command 7 = Get up from Front -;
;- Command 8 = Get up from Back -;
;- Command 9 = Rest Position -;
;- Command 0 = Home Position -;
;- Command 11= Turn Left -;
;---------------------------------------;
sound 9,[50\4000,40\3500,40\3200,50\3900]
main
gosub PS2INPUT
if(IdleBot = 1000)then
command = 9
gosub move
else
IdleBot = IdleBot + 1
pause 15
endif
RSwitch = in17
LSwitch = in19
if PrevRSW = 0 AND RSwitch = 1 then
hservo [RGUNP-7000\0]
else
PrevRSW = RSwitch
endif
if PrevLSW = 0 AND LSwitch = 1 then
hservo [LGUNP-7000\0]
else
PrevLSW = LSwitch
endif
IF (ABS(Dualshock(6)-128) > TravelDeadZone) AND (BotActive = TRUE) THEN
if (Dualshock(6)-128) > 0 then
WalkSpeed = TOFLOAT(((Dualshock(6)-128)/TravLength) MIN 8)
else
WalkSpeed = TOFLOAT(((Dualshock(6)-128)/TravLength) MAX -8)
endif
command = 1
gosub move
ENDIF
;serout s_out,i14400,[sdec WalkSpeed, " ", dec Dualshock(6), 13]
goto main
move:
if(command = 1) then ; Walk Forward
if LastStep = 0 then
gosub movement 9.0, WalkSpeed, WalkSpeed, -9.0,-WalkSpeed,-WalkSpeed,500.0]
gosub movement -9.0, WalkSpeed, WalkSpeed, 9.0,-WalkSpeed,-WalkSpeed,500.0]
LastStep = 1
elseif LastStep = 1
gosub movement -9.0,-WalkSpeed,-WalkSpeed, 9.0, WalkSpeed, WalkSpeed,500.0]
gosub movement 9.0,-WalkSpeed,-WalkSpeed, -9.0, WalkSpeed, WalkSpeed,500.0]
LastStep = 0
endif
; elseif(command = 3) ; Long Stride Forward
; gosub movement -12.0, 45.0, 45.0, 12.0,-45.0,-45.0, 0.0,750.0]
; gosub movement 12.0, 45.0, 45.0,-12.0,-45.0,-45.0, 0.0,750.0]
; gosub movement 12.0,-45.0,-45.0,-12.0, 45.0, 45.0, 0.0,750.0]
; gosub movement -12.0,-45.0,-45.0, 12.0, 45.0, 45.0, 0.0,750.0]
; elseif(command = 4) ; Long Stride Backward
; gosub movement -12.0,-45.0,-45.0, 12.0, 45.0, 45.0, 0.0,750.0]
; gosub movement 12.0,-45.0,-45.0,-12.0, 45.0, 45.0, 0.0,750.0]
; gosub movement 12.0, 45.0, 45.0,-12.0,-45.0,-45.0, 0.0,750.0]
; gosub movement -12.0, 45.0, 45.0, 12.0,-45.0,-45.0, 0.0,750.0]
; elseif(command = 5) ; Kick
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 42.0, 0.0, 0.0,-14.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 0.0,-32.0, 41.0,-23.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 0.0, 24.0,-20.0,-23.0, 0.0, 0.0, 0.0, 250.0]
; gosub movement 0.0, 0.0, 0.0,-18.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
; elseif(command = 7) ; Get up from front
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
; gosub movement 0.0, 90.0, 45.0, 0.0, 90.0, 45.0, 0.0,500.0]
; gosub movement 40.0, 90.0,-37.0, 0.0, 90.0, 45.0, 0.0,500.0]
; gosub movement 0.0, 90.0,-65.0, 0.0, 90.0,-65.0, 0.0,500.0]
; elseif(command = 8) ; Get up from back
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,1000.0]
; gosub movement 0.0,-90.0, 5.0, 0.0,-90.0, 5.0, 0.0,1000.0]
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,1000.0]
;pause 1000
;gosub movement 0.0, 22.0,-80.0, 0.0, 22.0,-80.0,1000.0]
;gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,1000.0]
elseif(command = 0) ; Home Position
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
hservo [Turret(TurretAngle + turret_start)\500]
; sound 9,[50\4400]
; pause 50
; sound 9,[50\4400]
; pause 50
; sound 9,[50\4400]
; elseif(command = 6) ; Headbutt
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
; gosub movement 0.0,-50.0,-90.0, 0.0,-50.0,-90.0, 0.0,500.0]
; gosub movement 0.0, 32.0,-58.0, 0.0, 32.0,-58.0, 0.0,400.0]
; pause 200
;gosub movement 0.0,-11.0, 7.0, 0.0,-11.0, 7.0, 500.0]
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
; sound 9,[50\4400]
; pause 50
; sound 9,[50\3960]
; pause 50
; sound 9,[50\3960]
elseif(command = 11) ; Turn left
gosub movement 0.0,-35.0,-40.0, 0.0, 35.0, 37.0,500.0]
gosub movement 0.0, 35.0, 37.0, 0.0,-35.0,-40.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0,-35.0,-40.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0, 35.0, 37.0,500.0]
gosub movement 20.0, 35.0, 37.0,-14.0, 35.0, 37.0,500.0]
gosub movement 20.0,-35.0,-40.0,-14.0, 35.0, 37.0,500.0]
;gosub movement 0.0,-35.0,-70.0, 0.0, 35.0, 7.0,500.0]
;gosub movement 0.0, 35.0, 7.0, 0.0,-35.0,-70.0,500.0]
;gosub movement -14.0, 35.0, 7.0, 20.0,-35.0,-70.0,500.0]
;gosub movement -14.0, 35.0, 7.0, 20.0, 35.0, 7.0,500.0]
;gosub movement 20.0, 35.0, 7.0,-14.0, 35.0, 7.0,500.0]
;gosub movement 20.0,-35.0,-70.0,-14.0, 35.0, 7.0,500.0]
elseif(command = 12) ; Turn right?
gosub movement 0.0, 35.0, 37.0, 0.0,-35.0,-40.0,500.0]
gosub movement 0.0,-35.0,-40.0, 0.0, 35.0, 37.0,500.0]
gosub movement 20.0,-35.0,-40.0,-14.0, 35.0, 37.0,500.0]
gosub movement 20.0, 35.0, 37.0,-14.0, 35.0, 37.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0, 35.0, 37.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0,-35.0,-40.0,500.0]
elseif(command = 13) ;coarse correct left
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
gosub movement 35.0, 0.0, 0.0,-18.0, 0.0, 0.0,500.0]
pause 100
gosub movement 2.0,-20.0,-20.0,-18.0, 20.0, 20.0,500.0]
gosub movement 0.0,-20.0,-20.0, 0.0, 20.0, 20.0,500.0]
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
elseif(command = 14) ;coarse correct right
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
gosub movement -18.0, 0.0, 0.0, 35.0, 0.0, 0.0,500.0]
pause 100
gosub movement -18.0, 20.0, 20.0, 2.0,-20.0,-20.0,500.0]
gosub movement 0.0, 20.0, 20.0, 0.0,-20.0,-20.0,500.0]
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
elseif(command = 9) ; Rest Position
gosub movement 0.0, 35.0, 40.0, 0.0, 35.0, 40.0,500.0]
endif
IdleBot = 0
return
;--------------------------------------------------------------------
;[PS2Input] reads the input data from the PS2 controller and processes the
;data to the parameters.
Ps2Input:
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8]
shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DS2Mode\8]
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8,$42\8]
shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
high PS2SEL
pause 1
;serout s_out,i14400,[dec DS2Mode, 13]
DS2Mode = DS2Mode & 0x7F
if DS2Mode <> PadMode THEN
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high PS2SEL
pause 100
sound P9,[100\3000, 100\3500, 100\4000]
return
ENDIF
IF (DualShock(1).bit3 = 0) and LastButton(0).bit3 THEN ;Start Button test
IF(BotActive) THEN
'Turn off
Sound P9,[100\4400,80\3800,60\3200]
command = 9
gosub move
BotActive = False
ELSE
'Turn on
Sound P9,[60\3200,80\3800,100\4400]
command = 0
gosub move
BotActive = True
ENDIF
ENDIF
IF BotActive THEN
IF (DualShock(1).bit0 = 0) and LastButton(0).bit0 THEN ;Select Button test
IF LaserOn = FALSE THEN
LaserOn = TRUE
hservo [LaserPin\7000\0]
Sound P9,[40\3200,80\3500]
ELSE
LaserOn = FALSE
hservo [LaserPin-7000\0]
Sound P9,[40\3500,80\3200]
ENDIF
ENDIF
IF (DualShock(1).bit4 = 0) THEN;and LastButton(0).bit4 THEN ;Up Button test
command = 1
gosub move
pause 20
ENDIF
IF (DualShock(1).bit6 = 0) THEN;and LastButton(0).bit6 THEN ;Down Button test
command = 2
gosub move
pause 20
ENDIF
; IF (DualShock(1).bit5 = 0) THEN;and LastButton(0).bit4 THEN ;? Button test
; command = 1
; gosub move
; ;pause 10
; ENDIF
; IF (DualShock(1).bit3 = 0) THEN;and LastButton(0).bit4 THEN ;? Button test
; command = 1
; gosub move
; ;pause 10
; ENDIF
; IF (DualShock(2).bit4 = 0) and LastButton(1).bit4 THEN ;Triangle Button test
; ENDIF
IF (DualShock(2).bit5 = 0) and LastButton(1).bit5 THEN ;Circle Button test
command = 20
gosub move
ENDIF
IF (DualShock(2).bit6 = 0) and LastButton(1).bit6 THEN ;Cross Button test
command = 0
TurretAngle = 0
gosub move
ENDIF
; IF (DualShock(2).bit7 = 0) and LastButton(1).bit7 THEN ;Square Button test
; ENDIF
IF (DualShock(2).bit3 = 0) THEN ;R1 Button test
;gosub Fire_R
hservo [RGUNP\7000\0]
PrevRSW = BUTTON_UP
ENDIF
IF (DualShock(2).bit2 = 0) THEN ;L1 Button test
hservo [LGUNP\7000\0]
PrevLSW = BUTTON_UP
ENDIF
; IF (DualShock(2).bit0 = 0) THEN;AND (LastButton(2).bit0 = 1) THEN ;L2 Button test
; ENDIF
; IF (DualShock(2).bit3 = 0) THEN;AND (LastButton(2).bit3 = 1) THEN ;R2 Button test
; ENDIF
; ENDIF
IF (ABS(DualShock(3)-128) > TravelDeadZone) THEN
TurretAngle = TurretAngle + ((Dualshock(3) - 128)*2)
IF TurretAngle > 12000 THEN
TurretAngle = 12000
ELSEIF TurretAngle < -12000
TurretAngle = -12000
ENDIF
;serout s_out,i14400,[sdec TurretAngle, 13]
hservo [Turret\(TurretAngle + turret_start)\0]
IdleBot = 0
ENDIF
IF (ABS(Dualshock(4)-128) > TravelDeadZone) THEN
RHipAngle = RHipAngle +(Dualshock(4) -128)
IF RHipAngle > 8500 THEN
RHipAngle = 8500
ELSEIF RHipAngle < -10000
RHipAngle = -10000
ENDIF
LHipAngle = LHipAngle -(Dualshock(4) -128)
IF LHipAngle > 10000 THEN
LHipAngle = 10000
ELSEIF LHipAngle < -8500
LHipAngle = -8500
ENDIF
;serout s_out,i14400,[sdec RHipAngle, " ", sdec LHipAngle, " ", dec Dualshock(6), 13]
hservo [righthip(RHipAngle + righthip_start)\0,lefthip(LHipAngle + lefthip_start)\0]
IdleBot = 0
ENDIF
; TravelRotationY = -(Dualshock(6) - 128)/4
ENDIF
LastButton(0) = DualShock(1)
LastButton(1) = DualShock(2)
return
;--------------------------------------------------------------------
;Fire_R:
;pulsout RGUNP,2000
;return
;Should never need to edit anything below this line. Add user subroutines above this and below main.
lefthippos var float
leftkneepos var float
leftanklepos var float
righthippos var float
rightkneepos var float
rightanklepos var float
;turretpos var float
last_lefthippos var float
last_leftkneepos var float
last_leftanklepos var float
last_righthippos var float
last_rightkneepos var float
last_rightanklepos var float
;last_turretpos var float
lhspeed var float
lkspeed var float
laspeed var float
rhspeed var float
rkspeed var float
raspeed var float
;tuspeed var float
speed var float
longestmove var float
;movement [lefthippos,leftkneepos,leftanklepos,righthippos,rightkneepos,rightanklepos,speed]
movement [rightanklepos,rightkneepos,righthippos,leftanklepos,leftkneepos,lefthippos,speed];,turretpos
if(speed<>0.0)then
gosub getlongest[lefthippos-last_lefthippos, |
leftkneepos-last_leftkneepos, |
leftanklepos-last_leftanklepos, |
righthippos-last_righthippos, |
rightkneepos-last_rightkneepos, |
rightanklepos-last_rightanklepos],longestmove
; turretpos-last_turretpos],longestmove
speed = ((longestmovestepsperdegree)/(speed/20.0))
gosub getspeed[lefthippos,last_lefthippos,longestmove,speed],lhspeed
gosub getspeed[leftkneepos,last_leftkneepos,longestmove,speed],lkspeed
gosub getspeed[leftanklepos,last_leftanklepos,longestmove,speed],laspeed
gosub getspeed[righthippos,last_righthippos,longestmove,speed],rhspeed
gosub getspeed[rightkneepos,last_rightkneepos,longestmove,speed],rkspeed
gosub getspeed[rightanklepos,last_rightanklepos,longestmove,speed],raspeed
; gosub getspeed[turretpos,last_turretpos,longestmove,speed],tuspeed
else
lhspeed=0.0;
lkspeed=0.0;
laspeed=0.0;
rhspeed=0.0;
rkspeed=0.0;
raspeed=0.0;
; tuspeed=0.0;
endif
hservo [lefthip\TOINT (-lefthipposstepsperdegree) + lefthip_start\TOINT lhspeed, |
righthip\TOINT (righthipposstepsperdegree) + righthip_start\TOINT rhspeed, |
leftknee\TOINT (-leftkneeposstepsperdegree) + leftknee_start\TOINT lkspeed, |
rightknee\TOINT (rightkneeposstepsperdegree) + rightknee_start\TOINT rkspeed, |
leftankle\TOINT (-leftankleposstepsperdegree) + leftankle_start\TOINT laspeed, |
rightankle\TOINT (rightankleposstepsperdegree) + rightankle_start\TOINT raspeed]
; turret\TOINT (turretposstepsperdegree) + turret_start\TOINT tuspeed]
hservowait [lefthip,righthip,leftknee,rightknee,leftankle,rightankle];,turret]
LHipAngle = TOINT (-lefthipposstepsperdegree)
RHipAngle = TOINT (righthipposstepsperdegree)
idle var byte
finished var byte
junk var word
;sensorloop
; finished = true
; gethservo lefthip,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo righthip,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo leftknee,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo rightknee,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo leftankle,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo leftankle,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo turret,junk,idle
; if(NOT idle)then
; finished=false
; endif
;add sensor handling code here
;adin 0,ir
;if (ir > 210) then
; detect = true
;endif
; if(NOT finished)then sensorloop
last_lefthippos = lefthippos
last_leftkneepos = leftkneepos
last_leftanklepos = leftanklepos
last_righthippos = righthippos
last_rightkneepos = rightkneepos
last_rightanklepos = rightanklepos
; last_turretpos = turretpos
return
one var float
two var float
three var float
four var float
five var float
six var float
;seven var float
getlongest[one,two,three,four,five,six];,seven]
if(one<0.0)then
one=-1.0one
endif
if(two<0.0)then
two=-1.0two
endif
if(three<0.0)then
three=-1.0three
endif
if(four<0.0)then
four=-1.0four
endif
if(five<0.0)then
five=-1.0five
endif
if(six<0.0)then
six=-1.0six
endif
; if(seven<0.0)then
; seven=-1.0*seven
; endif
if(one<two)then
one=two
endif
if(one<three)then
one=three
endif
if(one<four)then
one=four
endif
if(one<five)then
one=five
endif
if(one<six)then
one=six
endif
; if(one<seven)then
; one=seven
; endif
return one
newpos var float
oldpos var float
longest var float
maxval var float
getspeed[newpos,oldpos,longest,maxval]
if(newpos>oldpos)then
return ((newpos-oldpos)/longest)*maxval
endif
return ((oldpos-newpos)/longest)*maxval [/code]
Alrighty.
Here’s a video demonstrating the new aiming system…
youtube.com/watch?v=wHt8qA2Exzw
…and here’s one that we shot thanks to the guys at Trossen forums. We strapped an additional two battery packs (that’s 12oz ) on top and sent it on its merry way.
youtube.com/watch?v=eiZxRMG4ips
Beautiful videos What kind of camera are you using (mounted on the Brat)?
The pan and tilt aiming was nice and smooth. The second video was an older video, the 12oz one has a different link.
I was wondering why have those two extra batteries on top? It seems a bit top heavy with them and the battery placement looks a bit odd. My single pack on the Bratinator last a long time and my brat weighs quite a bit.
The pan and tilt aiming was nice and smooth. The second video was an older video, the 12oz one has a different link.
I was wondering why have those two extra batteries on top? It seems a bit top heavy with them and the battery placement looks a bit odd. My single pack on the Bratinator last a long time and my brat weighs quite a bit.
Hi Mike,
Yeah the second video link was the wrong one. It’s fixed now. The video was done to show some naysayers from the Trossen forum that the BRAT can easily be made into a Mech, even if it required an additional 12oz. of weight. They were saying the BRAT wouldn’t work at the competition because we didn’t have a wifi camera (weighs more) and the ammo hoppers aren’t on it yet, and the score keeping (hit counter). So it was said the BRAT would never be able to work with the added weight. It clearly can. I do not believe for one second that it will require an additional 12 oz. of equipment, but we did it just to prove a point.
Beautiful videos What kind of camera are you using (mounted on the Brat)?
It’s a standard 2.4ghz “spy cam”, but soon it will be using a wifi cam.
The pan and tilt aiming was nice and smooth. The second video was an older video, the 12oz one has a different link.
Oops… Posted the wrong link
It’s been fixed now.
I was wondering why have those two extra batteries on top? It seems a bit top heavy with them and the battery placement looks a bit odd. My single pack on the Bratinator last a long time and my brat weighs quite a bit.
They’re just there for weight. The guys at the Trossen forums didn’t think that the BRAT chassis would be able to handle the needed weight, so in typical fashion, we say “Yuh-huh!”
Edit: Bah… As usual, my Father beats me to the post
Hi Mike,
Yeah the second video link was the wrong one. It’s fixed now. The video was done to show some naysayers from the Trossen forum that the BRAT can easily be made into a Mech, even if it required an additional 12oz. of weight. They were saying the BRAT wouldn’t work at the competition because we didn’t have a wifi camera (weighs more) and the ammo hoppers aren’t on it yet, and the score keeping (hit counter). So it was said the BRAT would never be able to work with the added weight. It clearly can. I do not believe for one second that it will require an additional 12 oz. of equipment, but we did it just to prove a point.
I’m surprised they thought that since the Brat has a low CG which is ideal for mechs considering mechs have massive upper torsos making them a bit top-heavy. If you need more power, then all one needs is to pop in stronger servos. The Brat base design is probably one of the most robust designs one could build on. Examples being the Bratinator and James Mech.
Yeah after the competition James and I were looking at the results. Saw only a couple bots and they were all quads. We decided to slap some guns on a turret on a BRAT to see what would happen. After we saw favorable results I decided to go to the Trossen forum as they are the ones behind the Mech Warrior competition to post a video. While there I found a thread asking if a BRAT would make a good mech base. The thread over there was quite funny. Post after post of people stating their advanced experience level and insisting it was not possible… After I posted the first video over there I was attacked! They insisted it was not competition ready and after we added a wifi camera and more batteries to increase the run time to 15 minutes, and there’s no ammo hopper or hit score PC board. Well as you know the 1600mAh battery will last forever on a BRAT. It just doesn’t take very much current to walk. Like 500mA. There is no way we need 12oz. of additional equipment. I couldn’t believe they attacked me like that. Yay, fun…
Truly inspiring! I think I might get better performance stripping my mech down similarly, currently at 6#!!! Yeah, I don’t know why the reaction? But good to see LM representing!
Alright you programming gurus, since I’m not one by any stretch of the term… Suffice to say, I need a bit of help with the code for the mech.
The code I’m working with seems to be some sort of illegitimate child of Acidtech and Xan’s code, with my own cybernetic implants spliced in here and there. It works, but just barely (at least in my opinion.) My main issue with it is that I can’t walk and aim the turret at the same time.
So, anyone have any advice of what I could do to make that possible? Perhaps Kurt of the Assembly Interrupts has an idea or two?
Here’s what I have so far:
[code];System variables
righthip con p5
rightknee con p4
rightankle con p3
lefthip con p2
leftknee con p1
leftankle con p0
turret con p6
RGUNP con p16
RGswP con p17
LGUNP con p18
LGswP con p19
LaserPin con p7
;[PS2 Controller]
PS2DAT con P12 ;PS2 Controller DAT (Brown)
PS2CMD con P13 ;PS2 controller CMD (Orange)
PS2SEL con P14 ;PS2 Controller SEL (Blue)
PS2CLK con P15 ;PS2 Controller CLK (White)
PadMode con $79
TRUE con 1
FALSE con 0
BUTTON_DOWN con 0
BUTTON_UP con 1
TravelDeadZone con 4 ;The deadzone for the analog input from the remote
;calibrate steps per degree.
stepsperdegree fcon 166.6
;You must calibrate the servos to “zero”. Each robot will be different!
;When homed in and servos are at 0 degrees the robot should be standing
;straight with the AtomPro chip pointing backward. If you know the number
;of degrees the servo is off, you can calculate the value. 166.6 steps
;per degree. The values for our test robot were found by running the
;program bratosf.bas written by James Frye.
;righthip_start con 540
;rightknee_start con -240
;rightankle_start con 300
;lefthip_start con -1140
;leftknee_start con -120
;leftankle_start con -660
righthip_start con 780
rightknee_start con -240
rightankle_start con 480
lefthip_start con -1140
leftknee_start con -120
leftankle_start con -660
turret_start con 0
;Interrupt init
ENABLEHSERVO
command var byte
xx var byte
RSwitch var bit
PrevRSW var bit
LSwitch var bit
PrevLSW var bit
TurretAngle var sword
LHipAngle var sword
RHipAngle var sword
IdleBot var word
WalkSpeed var float
WalkAngle var float
TravLength var byte
TravLength = 6
LastStep var byte
LastStep = 0
AnkleAdj var byte
AnkleAdj = 0
LaserOn var bit
LaserOn = FALSE
BotActive var bit
BotActive = FALSE
;[Ps2 Controller]
DualShock var Byte(7)
LastButton var Byte(2)
DS2Mode var Byte
PS2Index var byte
BodyYShift var sbyte
PS2IN var float
;PS2 controller
high PS2CLK
LastButton(0) = 255
LastButton(1) = 255
;Init positions
;Note, movement subroutine arguments are Rightankle,Rightknee,Righthip,Leftankle,Leftknee,Lefthip,Turret,speed
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
hservo [Turret(TurretAngle + turret_start)\0]
;Gun/Laser Initialization
hservo [RGUNP\0\0,LGUNP\0\0,LaserPin\0\0]
;low 1
;low 2
pause 1000
;---------------------------------------;
;--------Command Quick Reference--------;
;---------------------------------------;
;- Command 1 = Walk Forward -;
;- Command 2 = Walk Backward -;
;- Command 3 = Long Stride Forward -;
;- Command 4 = Long Stride Backward -;
;- Command 5 = Kick -;
;- Command 6 = Headbutt -;
;- Command 7 = Get up from Front -;
;- Command 8 = Get up from Back -;
;- Command 9 = Rest Position -;
;- Command 0 = Home Position -;
;- Command 11= Turn Left -;
;---------------------------------------;
sound 9,[50\4000,40\3500,40\3200,50\3900]
main
gosub PS2INPUT
if(IdleBot = 1000)then
command = 9
gosub move
elseif(IdleBot = 50)
AnkleAdj = 0
else
IdleBot = IdleBot + 1
pause 15
endif
RSwitch = in17
LSwitch = in19
if PrevRSW = 0 AND RSwitch = 1 then
hservo [RGUNP-7000\0]
else
PrevRSW = RSwitch
endif
if PrevLSW = 0 AND LSwitch = 1 then
hservo [LGUNP-7000\0]
else
PrevLSW = LSwitch
endif
IF (ABS(Dualshock(6)-128) > TravelDeadZone) AND (BotActive = TRUE) THEN
PS2IN = TOFLOAT (Dualshock(6) - 128)
if (Dualshock(6)-128) > 0 then
WalkSpeed = TOFLOAT((Dualshock(6) - 128)/TravLength)
WalkAngle = (((PS2IN/10.0) + 4) - AnkleAdj)
else;if (Dualshock(6)-128) < 0
WalkSpeed = TOFLOAT((Dualshock(6) - 128)/TravLength)
WalkAngle = -(((PS2IN/10.0) - 4) + AnkleAdj)
endif
command = 1
gosub move
ENDIF
;serout s_out,i14400,[sdec WalkAngle, " ",sdec walkspeed, " ps2| ", sdec (dualshock(6)-128), 13]
pause 30
goto main
move:
if(command = 1) then ; Walk
if LastStep = 0 then
gosub movement WalkAngle, WalkSpeed, WalkSpeed, -WalkAngle,-WalkSpeed,-WalkSpeed,500.0]
gosub movement -WalkAngle, WalkSpeed, WalkSpeed, WalkAngle,-WalkSpeed,-WalkSpeed,500.0]
LastStep = 1
elseif LastStep = 1
gosub movement -WalkAngle,-WalkSpeed,-WalkSpeed, WalkAngle, WalkSpeed, WalkSpeed,500.0]
gosub movement WalkAngle,-WalkSpeed,-WalkSpeed, -WalkAngle, WalkSpeed, WalkSpeed,500.0]
LastStep = 0
endif
AnkleAdj = AnkleAdj + 1
if (AnkleAdj > 6) then
AnkleAdj = 6
endif
; elseif(command = 3) ; Long Stride Forward
; gosub movement -12.0, 45.0, 45.0, 12.0,-45.0,-45.0, 0.0,750.0]
; gosub movement 12.0, 45.0, 45.0,-12.0,-45.0,-45.0, 0.0,750.0]
; gosub movement 12.0,-45.0,-45.0,-12.0, 45.0, 45.0, 0.0,750.0]
; gosub movement -12.0,-45.0,-45.0, 12.0, 45.0, 45.0, 0.0,750.0]
; elseif(command = 4) ; Long Stride Backward
; gosub movement -12.0,-45.0,-45.0, 12.0, 45.0, 45.0, 0.0,750.0]
; gosub movement 12.0,-45.0,-45.0,-12.0, 45.0, 45.0, 0.0,750.0]
; gosub movement 12.0, 45.0, 45.0,-12.0,-45.0,-45.0, 0.0,750.0]
; gosub movement -12.0, 45.0, 45.0, 12.0,-45.0,-45.0, 0.0,750.0]
; elseif(command = 5) ; Kick
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 42.0, 0.0, 0.0,-14.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 0.0,-32.0, 41.0,-23.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 0.0, 24.0,-20.0,-23.0, 0.0, 0.0, 0.0, 250.0]
; gosub movement 0.0, 0.0, 0.0,-18.0, 0.0, 0.0, 0.0, 500.0]
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
; elseif(command = 7) ; Get up from front
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
; gosub movement 0.0, 90.0, 45.0, 0.0, 90.0, 45.0, 0.0,500.0]
; gosub movement 40.0, 90.0,-37.0, 0.0, 90.0, 45.0, 0.0,500.0]
; gosub movement 0.0, 90.0,-65.0, 0.0, 90.0,-65.0, 0.0,500.0]
; elseif(command = 8) ; Get up from back
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,1000.0]
; gosub movement 0.0,-90.0, 5.0, 0.0,-90.0, 5.0, 0.0,1000.0]
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,1000.0]
;pause 1000
;gosub movement 0.0, 22.0,-80.0, 0.0, 22.0,-80.0,1000.0]
;gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,1000.0]
elseif(command = 0) ; Home Position
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
hservo [Turret(TurretAngle + turret_start)\500]
; sound 9,[50\4400]
; pause 50
; sound 9,[50\4400]
; pause 50
; sound 9,[50\4400]
; elseif(command = 6) ; Headbutt
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
; gosub movement 0.0,-50.0,-90.0, 0.0,-50.0,-90.0, 0.0,500.0]
; gosub movement 0.0, 32.0,-58.0, 0.0, 32.0,-58.0, 0.0,400.0]
; pause 200
;gosub movement 0.0,-11.0, 7.0, 0.0,-11.0, 7.0, 500.0]
; gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
; sound 9,[50\4400]
; pause 50
; sound 9,[50\3960]
; pause 50
; sound 9,[50\3960]
elseif(command = 11) ; Turn left
gosub movement 0.0,-35.0,-40.0, 0.0, 35.0, 37.0,500.0]
gosub movement 0.0, 35.0, 37.0, 0.0,-35.0,-40.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0,-35.0,-40.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0, 35.0, 37.0,500.0]
gosub movement 20.0, 35.0, 37.0,-14.0, 35.0, 37.0,500.0]
gosub movement 20.0,-35.0,-40.0,-14.0, 35.0, 37.0,500.0]
;gosub movement 0.0,-35.0,-70.0, 0.0, 35.0, 7.0,500.0]
;gosub movement 0.0, 35.0, 7.0, 0.0,-35.0,-70.0,500.0]
;gosub movement -14.0, 35.0, 7.0, 20.0,-35.0,-70.0,500.0]
;gosub movement -14.0, 35.0, 7.0, 20.0, 35.0, 7.0,500.0]
;gosub movement 20.0, 35.0, 7.0,-14.0, 35.0, 7.0,500.0]
;gosub movement 20.0,-35.0,-70.0,-14.0, 35.0, 7.0,500.0]
elseif(command = 12) ; Turn right?
gosub movement 0.0, 35.0, 37.0, 0.0,-35.0,-40.0,500.0]
gosub movement 0.0,-35.0,-40.0, 0.0, 35.0, 37.0,500.0]
gosub movement 20.0,-35.0,-40.0,-14.0, 35.0, 37.0,500.0]
gosub movement 20.0, 35.0, 37.0,-14.0, 35.0, 37.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0, 35.0, 37.0,500.0]
gosub movement -14.0, 35.0, 37.0, 20.0,-35.0,-40.0,500.0]
elseif(command = 13) ;coarse correct left
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
gosub movement 35.0, 0.0, 0.0,-18.0, 0.0, 0.0,500.0]
pause 100
gosub movement 2.0,-20.0,-20.0,-18.0, 20.0, 20.0,500.0]
gosub movement 0.0,-20.0,-20.0, 0.0, 20.0, 20.0,500.0]
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
elseif(command = 14) ;coarse correct right
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
gosub movement -18.0, 0.0, 0.0, 35.0, 0.0, 0.0,500.0]
pause 100
gosub movement -18.0, 20.0, 20.0, 2.0,-20.0,-20.0,500.0]
gosub movement 0.0, 20.0, 20.0, 0.0,-20.0,-20.0,500.0]
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,500.0]
elseif(command = 9) ; Rest Position
gosub movement 0.0, 35.0, 40.0, 0.0, 35.0, 40.0,500.0]
endif
IdleBot = 0
return
;--------------------------------------------------------------------
;[PS2Input] reads the input data from the PS2 controller and processes the
;data to the parameters.
Ps2Input:
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8]
shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DS2Mode\8]
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8,$42\8]
shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
high PS2SEL
pause 1
;serout s_out,i14400,[dec DS2Mode, 13]
DS2Mode = DS2Mode & 0x7F
if DS2Mode <> PadMode THEN
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high PS2SEL
pause 100
sound P9,[100\3000, 100\3500, 100\4000]
return
ENDIF
IF (DualShock(1).bit3 = 0) and LastButton(0).bit3 THEN ;Start Button test
IF(BotActive) THEN
'Turn off
Sound P9,[100\4400,80\3800,60\3200]
command = 9
gosub move
BotActive = False
ELSE
'Turn on
Sound P9,[60\3200,80\3800,100\4400]
command = 0
gosub move
BotActive = True
ENDIF
ENDIF
IF BotActive THEN
IF (DualShock(1).bit0 = 0) and LastButton(0).bit0 THEN ;Select Button test
IF LaserOn = FALSE THEN
LaserOn = TRUE
hservo [LaserPin\7000\0]
Sound P9,[40\3200,80\3500]
ELSE
LaserOn = FALSE
hservo [LaserPin-7000\0]
Sound P9,[40\3500,80\3200]
ENDIF
ENDIF
IF (DualShock(1).bit4 = 0) THEN;and LastButton(0).bit4 THEN ;Up Button test
command = 1
gosub move
pause 20
ENDIF
IF (DualShock(1).bit6 = 0) THEN;and LastButton(0).bit6 THEN ;Down Button test
command = 2
gosub move
pause 20
ENDIF
; IF (DualShock(1).bit5 = 0) THEN;and LastButton(0).bit4 THEN ;? Button test
; command = 1
; gosub move
; ;pause 10
; ENDIF
; IF (DualShock(1).bit3 = 0) THEN;and LastButton(0).bit4 THEN ;? Button test
; command = 1
; gosub move
; ;pause 10
; ENDIF
; IF (DualShock(2).bit4 = 0) and LastButton(1).bit4 THEN ;Triangle Button test
; ENDIF
IF (DualShock(2).bit5 = 0) and LastButton(1).bit5 THEN ;Circle Button test
command = 20
gosub move
ENDIF
IF (DualShock(2).bit6 = 0) and LastButton(1).bit6 THEN ;Cross Button test
command = 0
TurretAngle = 0
gosub move
ENDIF
; IF (DualShock(2).bit7 = 0) and LastButton(1).bit7 THEN ;Square Button test
; ENDIF
IF (DualShock(2).bit3 = 0) THEN ;R1 Button test
;gosub Fire_R
hservo [RGUNP\7000\0]
PrevRSW = BUTTON_UP
ENDIF
IF (DualShock(2).bit2 = 0) THEN ;L1 Button test
hservo [LGUNP\7000\0]
PrevLSW = BUTTON_UP
ENDIF
; IF (DualShock(2).bit0 = 0) THEN;AND (LastButton(2).bit0 = 1) THEN ;L2 Button test
; ENDIF
; IF (DualShock(2).bit3 = 0) THEN;AND (LastButton(2).bit3 = 1) THEN ;R2 Button test
; ENDIF
; ENDIF
IF (ABS(DualShock(3)-128) > TravelDeadZone) THEN
TurretAngle = TurretAngle + ((Dualshock(3) - 128)*2)
IF TurretAngle > 12000 THEN
TurretAngle = 12000
ELSEIF TurretAngle < -12000
TurretAngle = -12000
ENDIF
;serout s_out,i14400,[sdec TurretAngle, 13]
hservo [Turret\(TurretAngle + turret_start)\0]
IdleBot = 0
ENDIF
IF (ABS(Dualshock(4)-128) > TravelDeadZone) THEN
RHipAngle = RHipAngle +(Dualshock(4) -128)
IF RHipAngle > 8500 THEN
RHipAngle = 8500
ELSEIF RHipAngle < -10000
RHipAngle = -10000
ENDIF
LHipAngle = LHipAngle -(Dualshock(4) -128)
IF LHipAngle > 10000 THEN
LHipAngle = 10000
ELSEIF LHipAngle < -8500
LHipAngle = -8500
ENDIF
;serout s_out,i14400,[sdec RHipAngle, " ", sdec LHipAngle, " ", dec Dualshock(6), 13]
hservo [righthip(RHipAngle + righthip_start)\0,lefthip(LHipAngle + lefthip_start)\0]
IdleBot = 0
ENDIF
; TravelRotationY = -(Dualshock(6) - 128)/4
ENDIF
LastButton(0) = DualShock(1)
LastButton(1) = DualShock(2)
return
;--------------------------------------------------------------------
;Fire_R:
;pulsout RGUNP,2000
;return
;Should never need to edit anything below this line. Add user subroutines above this and below main.
lefthippos var float
leftkneepos var float
leftanklepos var float
righthippos var float
rightkneepos var float
rightanklepos var float
;turretpos var float
last_lefthippos var float
last_leftkneepos var float
last_leftanklepos var float
last_righthippos var float
last_rightkneepos var float
last_rightanklepos var float
;last_turretpos var float
lhspeed var float
lkspeed var float
laspeed var float
rhspeed var float
rkspeed var float
raspeed var float
;tuspeed var float
speed var float
longestmove var float
;movement [lefthippos,leftkneepos,leftanklepos,righthippos,rightkneepos,rightanklepos,speed]
movement [rightanklepos,rightkneepos,righthippos,leftanklepos,leftkneepos,lefthippos,speed];,turretpos
if(speed<>0.0)then
gosub getlongest[lefthippos-last_lefthippos, |
leftkneepos-last_leftkneepos, |
leftanklepos-last_leftanklepos, |
righthippos-last_righthippos, |
rightkneepos-last_rightkneepos, |
rightanklepos-last_rightanklepos],longestmove
; turretpos-last_turretpos],longestmove
speed = ((longestmovestepsperdegree)/(speed/20.0))
gosub getspeed[lefthippos,last_lefthippos,longestmove,speed],lhspeed
gosub getspeed[leftkneepos,last_leftkneepos,longestmove,speed],lkspeed
gosub getspeed[leftanklepos,last_leftanklepos,longestmove,speed],laspeed
gosub getspeed[righthippos,last_righthippos,longestmove,speed],rhspeed
gosub getspeed[rightkneepos,last_rightkneepos,longestmove,speed],rkspeed
gosub getspeed[rightanklepos,last_rightanklepos,longestmove,speed],raspeed
; gosub getspeed[turretpos,last_turretpos,longestmove,speed],tuspeed
else
lhspeed=0.0;
lkspeed=0.0;
laspeed=0.0;
rhspeed=0.0;
rkspeed=0.0;
raspeed=0.0;
; tuspeed=0.0;
endif
hservo [lefthip\TOINT (-lefthipposstepsperdegree) + lefthip_start\TOINT lhspeed, |
righthip\TOINT (righthipposstepsperdegree) + righthip_start\TOINT rhspeed, |
leftknee\TOINT (-leftkneeposstepsperdegree) + leftknee_start\TOINT lkspeed, |
rightknee\TOINT (rightkneeposstepsperdegree) + rightknee_start\TOINT rkspeed, |
leftankle\TOINT (-leftankleposstepsperdegree) + leftankle_start\TOINT laspeed, |
rightankle\TOINT (rightankleposstepsperdegree) + rightankle_start\TOINT raspeed]
; turret\TOINT (turretposstepsperdegree) + turret_start\TOINT tuspeed]
hservowait [lefthip,righthip,leftknee,rightknee,leftankle,rightankle];,turret]
LHipAngle = TOINT (-lefthipposstepsperdegree)
RHipAngle = TOINT (righthipposstepsperdegree)
idle var byte
finished var byte
junk var word
;sensorloop
; finished = true
; gethservo lefthip,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo righthip,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo leftknee,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo rightknee,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo leftankle,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo leftankle,junk,idle
; if(NOT idle)then
; finished=false
; endif
; gethservo turret,junk,idle
; if(NOT idle)then
; finished=false
; endif
;add sensor handling code here
;adin 0,ir
;if (ir > 210) then
; detect = true
;endif
; if(NOT finished)then sensorloop
last_lefthippos = lefthippos
last_leftkneepos = leftkneepos
last_leftanklepos = leftanklepos
last_righthippos = righthippos
last_rightkneepos = rightkneepos
last_rightanklepos = rightanklepos
; last_turretpos = turretpos
return
one var float
two var float
three var float
four var float
five var float
six var float
;seven var float
getlongest[one,two,three,four,five,six];,seven]
if(one<0.0)then
one=-1.0one
endif
if(two<0.0)then
two=-1.0two
endif
if(three<0.0)then
three=-1.0three
endif
if(four<0.0)then
four=-1.0four
endif
if(five<0.0)then
five=-1.0five
endif
if(six<0.0)then
six=-1.0six
endif
; if(seven<0.0)then
; seven=-1.0*seven
; endif
if(one<two)then
one=two
endif
if(one<three)then
one=three
endif
if(one<four)then
one=four
endif
if(one<five)then
one=five
endif
if(one<six)then
one=six
endif
; if(one<seven)then
; one=seven
; endif
return one
newpos var float
oldpos var float
longest var float
maxval var float
getspeed[newpos,oldpos,longest,maxval]
if(newpos>oldpos)then
return ((newpos-oldpos)/longest)*maxval
endif
return ((oldpos-newpos)/longest)*maxval [/code]
Thanks in advance for any and all information
Hi Fish,
My Old TV brat is looking on with envy
This looks like it might take some major surgery to make this code to do what you want. I think all of this can be reasonably done without any assembly language code. There are some cleaner ways of doing it and some probably quick and dirty ways. The clean way would be to convert a bunch of this into a state machine, but that may be more work than you wish to do at this point. So I will try to explain what the problem is and a possible quick and dirty way to get it to work.
The problem is that with the current code, once you choose a command for example long stride forward, the code is stuck calling the movement function 4 times. These calls to “Movement” do their calculations and then do an HSERVO command to move the 6 servos and then it does a HSERVOWAIT which will wait for the 6 servos to get to their destination. So in other words, once you choose a command the PS2 code will not be called again until the complete command is done and as such your aiming the turret can not happen.
You have the beginnings of the solution maybe hacked up in your code with what was the idle/busy code that is commented out after the hservowait.
My idea for the hack code would be, to remove the HSERVOWAIT and put in the code to detect if the the hservo has completed, if it has then return, else, I would call the PS2 function again and limit, what things I processed in this PS2 code. This could be either some mode variable you pass in or a second PS2 function, which has limited things it does such as the HSERVO for lefthip/righthip. You may want to limit calling this function to only when those servos have completed their last movement.
I have to take off soon, so I hope some of this makes some sense. I will try to help you fill it maybe tomorrow morning.
Kurt
I had this problem with my Bratinator. My issue was when the play sequence routine was called, my IR sensors had to wait till it finished before it could resume operation. Another issue was the SSC-32 itself. It had to wait for the entire sequence to complete before issuing another different sequence. To fix this, or improve it, to use a better word, I inserted a Freqout command in the play sequence so while the sequence player routine was doing its loops, I was still able to use the ir sensors. I also had to use a trigger variable to store the results so that when the SSC-32 was finished it could react to any missed events. It’s probably not the best way to do things but it gets the job done using the SSC-32.
I would guess using HSERVO you have more control over when things happen. I have not used the Query command yet for the SSC32, this might be useful.
My Old TV brat is looking on with envy
This looks like it might take some major surgery to make this code to do what you want. I think all of this can be reasonably done without any assembly language code. There are some cleaner ways of doing it and some probably quick and dirty ways. The clean way would be to convert a bunch of this into a state machine, but that may be more work than you wish to do at this point. So I will try to explain what the problem is and a possible quick and dirty way to get it to work.
You have the beginnings of the solution maybe hacked up in your code with what was the idle/busy code that is commented out after the hservowait.
My idea for the hack code would be, to remove the HSERVOWAIT and put in the code to detect if the the hservo has completed, if it has then return, else, I would call the PS2 function again and limit, what things I processed in this PS2 code. This could be either some mode variable you pass in or a second PS2 function, which has limited things it does such as the HSERVO for lefthip/righthip. You may want to limit calling this function to only when those servos have completed their last movement.
I have to take off soon, so I hope some of this makes some sense. I will try to help you fill it maybe tomorrow morning.
Kurt
I think I get it. I also think that it’ll take me a while to wrap my head around how exactly to do it, but I think I see a way to fix it. Thanks for pointing out that bit of code, I had forgotten about it