I moved this from the Bot Board section to here…
BRAT TV remote control redo!
I really wanted to get this into a tutorial, but that’s not going to happen very quickly. So here is the new program for the BRAT with Bot Board, Atom Pro 28, IRPD, for TV style remote control. It works great! I have my BRAT walking forward and backwards, long and short strides, left turns, kick, headbutt, rest, get up from laying on it’s front or back… all from the TV remote control. I have several more buttons that are not programmed yet.
The generic TV remote control is set to Sony #218. The IRPD sensor output (yellow) is connected to pin 3. The blue and violet lines (LED enable) lines are connected to pins 2 and 1. They’re not used yet. The servo connection information is in the program. This version requires the new Pro IDE version 8.0.0.0 beta. I’m really in a time crunch so I’m just putting the code right here in a code box.
The only thing you will have to do is calculate your servos offset value. The HSERVO command uses +/- 24000 for the servo pulses with 0 being 1500us. Each count is worth 0.0625uS. If you know the pulse value to set the servo to exact center you can figure the offset.
Left knee servo example:
Centered value - 1500uS = correction
1470uS -1500uS = -30
-30 / 0.0625 = -480
then put this in the program…
leftknee_start con -480
All the hard work is done, just put in the angles from your Sequencer files to add your own sequences to the bot.
[code];System variables
righthip con p15
rightknee con p14
rightankle con p13
lefthip con p12
leftknee con p11
leftankle con p10
;calibrate steps per degree.
stepsperdegree fcon 166.6
;calibrate servos to “zero”.
;When homed in and servos are at 0 degrees
;the robot should be standing strait with
; irpd pointing up and AtomPro chip pointing forward.
righthip_start con -560
rightknee_start con -720
rightankle_start con 0
lefthip_start con -560
leftknee_start con -480
leftankle_start con -160
;Interrupt init
ENABLEHSERVO
ONINTERRUPT WKPINT_3,handle_irpd
ONINTERRUPT TIMERAINT,handle_timera
PMR5.bit3 = 1
TMA=4 ;increments on clock/256
ENABLE WKPINT_3
ENABLE TIMERAINT
lasttime var long
overflowtime var long
currenttime var long
diff var long
datacount var byte
irpd_data var word
command var byte
lasttime = -1 ;indicate next data should be a startpulse
;End of System setup. Add user variables below this line.
;Init positions
;Note, movement subroutine arguments are Rightankle,Rightknee,Righthip,Leftankle,Leftknee,Lefthip,speed
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
low 1
low 2
pause 1000
command=0xFF
main
if(command<>0xFF)then
if(command = 1) then ;(Button 2) Walk Forwards
gosub movement -7.0, 20.0, 20.0, 7.0,-20.0,-20.0, 500.0]
gosub movement 7.0, 20.0, 20.0, -7.0,-20.0,-20.0, 500.0]
gosub movement 7.0,-20.0,-20.0, -7.0, 20.0, 20.0, 500.0]
gosub movement -7.0,-20.0,-20.0, 7.0, 20.0, 20.0, 500.0]
elseif(command = 4) ;(Button 5) Walk Backwards
gosub movement -7.0,-20.0,-20.0, 7.0, 20.0, 20.0, 500.0]
gosub movement 7.0,-20.0,-20.0, -7.0, 20.0, 20.0, 500.0]
gosub movement 7.0, 20.0, 20.0, -7.0,-20.0,-20.0, 500.0]
gosub movement -7.0, 20.0, 20.0, 7.0,-20.0,-20.0, 500.0]
elseif(command = 18) ;(Up Vol) long stride forward
gosub movement -12.0, 45.0, 45.0, 12.0,-45.0,-45.0, 750.0]
gosub movement 12.0, 45.0, 45.0,-12.0,-45.0,-45.0, 750.0]
gosub movement 12.0,-45.0,-45.0,-12.0, 45.0, 45.0, 750.0]
gosub movement -12.0,-45.0,-45.0, 12.0, 45.0, 45.0, 750.0]
elseif(command = 19) ;(Dn Vol) long stride backward
gosub movement -12.0,-45.0,-45.0, 12.0, 45.0, 45.0, 750.0]
gosub movement 12.0,-45.0,-45.0,-12.0, 45.0, 45.0, 750.0]
gosub movement 12.0, 45.0, 45.0,-12.0,-45.0,-45.0, 750.0]
gosub movement -12.0, 45.0, 45.0, 12.0,-45.0,-45.0, 750.0]
elseif(command = 2) ;(Button 3) Kick
gosub movement 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, 500.0]
gosub movement 0.0,-32.0, 41.0,-23.0, 0.0, 0.0, 500.0]
gosub movement 0.0, 24.0,-20.0,-23.0, 0.0, 0.0, 250.0]
gosub movement 0.0, 0.0, 0.0,-18.0, 0.0, 0.0, 500.0]
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
sound 9,[50\3960]
pause 50
sound 9,[50\4400]
pause 50
sound 9,[50\3960]
elseif(command = 16) ;(Channel Up) Get up from front
gosub movement 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, 500.0]
gosub movement 40.0, 90.0,-37.0, 0.0, 90.0, 45.0, 500.0]
gosub movement 0.0, 90.0,-65.0, 0.0, 90.0,-65.0, 500.0]
pause 500
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 750.0]
sound 9,[50\4400]
pause 50
sound 9,[50\4400]
pause 50
sound 9,[50\3960]
elseif(command = 17) ;(Channel Dn) Get up from back
gosub movement 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,1000.0]
gosub movement 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]
sound 9,[50\3960]
pause 50
sound 9,[50\3960]
pause 50
sound 9,[50\4400]
elseif(command = 0) ;(Button 1) Home Position
gosub movement 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 500.0]
sound 9,[50\4400]
pause 50
sound 9,[50\4400]
pause 50
sound 9,[50\4400]
elseif(command = 5) ;(Button 6) Headbutt
gosub movement 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, 500.0]
gosub movement 0.0, 32.0,-58.0, 0.0, 32.0,-58.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, 500.0]
sound 9,[50\4400]
pause 50
sound 9,[50\3960]
pause 50
sound 9,[50\3960]
elseif(command = 6) ;(Button 7) Turn
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 = 3) ;(Button 4) Rest Position
gosub movement 0.0, 45.0, 45.0, 0.0, 45.0, 45.0, 500.0]
endif
Command=0xFF
endif
goto main
;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
last_lefthippos var float
last_leftkneepos var float
last_leftanklepos var float
last_righthippos var float
last_rightkneepos var float
last_rightanklepos var float
lhspeed var float
lkspeed var float
laspeed var float
rhspeed var float
rkspeed var float
raspeed var float
speed var float
longestmove var float
;movement [lefthippos,leftkneepos,leftanklepos,righthippos,rightkneepos,rightanklepos,speed]
movement [rightanklepos,rightkneepos,righthippos,leftanklepos,leftkneepos,lefthippos,speed]
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
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
else
lhspeed=0.0;
lkspeed=0.0;
laspeed=0.0;
rhspeed=0.0;
rkspeed=0.0;
raspeed=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 (rightanklepos*stepsperdegree) + rightankle_start\TOINT raspeed]
hservowait [lefthip,righthip,leftknee,rightknee,leftankle,rightankle]
last_lefthippos = lefthippos
last_leftkneepos = leftkneepos
last_leftanklepos = leftanklepos
last_righthippos = righthippos
last_rightkneepos = rightkneepos
last_rightanklepos = rightanklepos
return
one var float
two var float
three var float
four var float
five var float
six var float
getlongest[one,two,three,four,five,six]
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(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
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
handle_irpd
currenttime=overflowtime+TCA
if(currenttime<0)then ;If we overflow to a negative number reset everything
overflowtime=0
currenttime=TCA
lasttime=-1
endif
if(lasttime<0)then ;If negtive lasttime, reset
datacount=0
lasttime=currenttime
else ;else process pulses
datacount=datacount+1
diff=currenttime-lasttime
irpd_data=irpd_data>>1
if(diff>175 AND diff<195)then ;If we get a start pulse reset datacount and irpd_data
irpd_data=0
datacount=0
elseif(diff>100 and diff<120) ;we got a “1” pulse
irpd_data.bit10=1
elseif(diff>65 and diff<85) ;we got a “0” pulse
irpd_data.bit10=0
else ;we got an invalid pulse so reset
lasttime=-1
resume
endif
if(datacount=11)then
lasttime=-1
command = irpd_data&0x7F
else
lasttime = currenttime
endif
endif
Resume
handle_timera
overflowtime=overflowtime+256
resume[/code]