While waiting for some XBee communication modules to arrive, I thought I would start playing with this as I would like to rezero out all of the servos on my CHR-3 hex and don’t want to have to dig in to get to the SSC-32 serial connections (Lazy).
Longer term I want to add on an Xbee (or Xbee pro) onto my Hex and do a DIY remote control with either a PS2 controller to start or RC controller parts i nthe controller and talk to the robot or robots using the XBee link. But for the short term I had a Bluetooth module sitting around and for the first time I was able to get Vista to talk to it… So right now I am in the process of two different approaches to make this work.
Approach 1: try to user serin to read in the commands from the BT (or later xbee) and then reissue them back to the SSC-32. I have the beginnings of code that try to understand enough of the codes to know when it should expect stuff back from the SSC-32 (things like the Q command). I have the beginnings of this semi-limping along. That is I can use SSC32 term to connect through the BT to my robot and issue a simple command like: #0p1500 I think works. The problem is if you do something like click on all 1500, I think it outputs the command as 4 different commands: 1 for each bank. So while you are processing the first line and echoing it to the SSC-32, you miss some or all of the next command… Also I don’t think I am getting the results back yet from the SSC-32. Will play more here…
The simple code looks something like:
[code]
; Constants
BT_IN con P8 ; which pin is the input from the bluetooth connected to
BT_OUT con P9 ; which IO pin is the output to the bluetooth
BT_BAUTE con i38400 ; what is the baud rate
SSC_OUT con P11 ;Output pin for (SSC32 RX) on BotBoard (Yellow)
SSC_IN con P10 ;Input pin for (SSC32 TX) on BotBoard (Blue)
SSC_BAUTE con i38400 ;SSC32 Baute rate
BTBUFSIZE con 256 ; Our buffer
SSCCMDTBL bytetable |
3,“QPL”,4,|
3,“VER”,0xff,|
2,“QP”,1,|
1,“Q”,1,|
0
;=================================================================================================================
; Variables
bBuff var byte(BTBUFSIZE)
bStrlen var byte
bBytesRet var byte
;=================================================================================================================
; Code to ask for input from the PC and echo it off to the SSC-32 card and if necessary wait for a reply from the SSC-32
; and echo that back to the pc.
main:
bBuff = rep 0\BTBUFSIZE ; since the serin may not return anything like how many characters it received we prefill so can find null
serin BT_IN, BT_BAUTE, [str bBuff\BTBUFSIZE\13]
bBytesRet = 0 ; Don’t expect anything to return.
; Before we send it off to the SSC32, we may first want to look at the command to see if it might produce an output that we need to wait for.
mov.l #BBUFF:24, er0 ; lets scan to find the first zero
mov.b @er0, r1l ; Save away the first for quick checking of do we think we will have stuff returned to us from the SSC32
_NOTZERO:
mov.b @er0+,r1h ; load the next byte into R1L
bne #_NOTZERO:8 ; it is not zero try next byte
sub.l #BBUFF:24, er0 ; figure out our size
dec.b r0l
mov.b r0l, @BSTRLEN ; save away the string length
; quick check to see if the first character is a #. If so echo the whole line out to ssc-32
cmp.b #'#', r1l ; ok check for normal output line
beq #OUTPUT_TO_SSC:16
; Can we figure out which command we have, for now it is Quick and dirty table is in command length order...
mov.l #SSCCMDTBL, er1 ; Ok we point to the start of the command table
xor.l er2, er2 ; zero out the whole R2 register.
_FCMD_LOOP:
mov.b @er1+, r2l ; get the length of the next command.
beq @OUTPUT_TO_SSC:8 ; command not in our list, so jump off to the output function
mov.l #BBUFF:24, er0 ; point to the start of our buffer
_FCMD_NCHR:
mov.b @er0+, r3h ; get the next byte of the command buffer
and.b #0xdf, r3h ; Hack to make any lower case character into an upper character
mov.b @er1+, r3l ; get the next byte out command table
cmp.b r3h, r3l
bne @_FCMP_NE:8 ; not equal
; the bytes are equal, decrement the count and see if we are done.
dec.b r2l ;
bne _FCMD_NCHR ; not done yet
; we matched all that was passed. should maybe do some more validating but, what the heck
mov.b @er1, r3l ; get the next byte out command table which is the number of bytes we expect to return
mov.b r3l, @BBYTESRET:16 ; save away into the bytes to return variable
bra #OUTPUT_TO_SSC:8 ; and go do it.
; when the characters don't match, align up to the next command
_FCMP_NE:
add.l er2, er1 ; point to the next command in the table
bra #_FCMD_LOOP:8 ; go try to process the next loop
OUTPUT_TO_SSC:
serout s_out, i9600, [dec bBytesRet, “-”, str bBuff\bStrlen, 13]
serout SSC_OUT, SSC_BAUTE, [str bBuff\bStrlen, 13] ; Ok lets quickly write the command out to the SSC-32
; First a simple check if it starts with a # it will have no return so go directly to the output function
if bBytesRet = 0 then
goto main ; Dont expect anything so go back to get the next line
else
; Ok we expect something. if count = ff then it is a string we are expecting.
if bBytesRet = 0xff then
bBuff = rep 0\BTBUFSIZE
serin SSC_IN, SSC_BAUTE, [str bBuff\BTBUFSIZE\13]
mov.l #BBUFF:24, er0 ; lets scan to find the first zero
_NOTZERO2:
mov.b @er0+,r1h ; load the next byte into R1L
bne #_NOTZERO2:8 ; it is not zero try next byte
dec.l #1,er0 ; get back to the NULL character
mov.b #13, r1h
mov.b r1h, @er0 ; put a CR back into the end of the buffer and increment
sub.l #BBUFF:24, er0 ; figure out our size
inc.b r0l
mov.b r0l, @BBYTESRET ; save away the string length
else
serin SSC_IN, SSC_BAUTE, [str bBuff\bBytesRet]
endif
; Now lets return the returned infor back to the PC
serout BT_OUT, BT_BAUTE, [str bBuff\bBytesRet]
endif
goto main[/code]
Somethings I might try to fix this approach include:
-
Maybe continue to do reads with a timeout and buffer up all of the commands in a run before issuing them. This might work, but will probably not make using the slider in SSC term as smooth.
-
Try to move the pins around and use part of the hardware serial port for the BT(in) and part for the SSC-32(out). This might work but would conflict on using the PS2 controller on the BB2. Again for my case this may work OK as I plan to move the controller off of the BOT anyway…
Approach 2: A simple echo at the bit level. What I am trying to do is to simply take whatever the state of the input pin for BT and put this as the output state for SSC-32 and likewise take the input state of SSC-32 and put it as the output state of the BT. So far I have not had any luck with getting the communication going. Maybe I need to pull some signals high or low, will try to debug later. The code looks something like:
[code] Constants
BT_IN con p8 ; which pin is the input from the bluetooth connected to (P80)
BT_OUT con p9 ; which IO pin is the output to the bluetooth (P81)
BT_BAUTE con i38400 ; what is the baud rate
SSC_IN con p10 ;Input pin for (SSC32 TX) on BotBoard (Blue) (P82)
SSC_OUT con p11 ;Output pin for (SSC32 RX) on BotBoard (Yellow) (P83)
SSC_BAUTE con i38400 ;SSC32 Baute rate
; Define some debug LED pins. Normally on P12-P14 on BB2, but jumpered to P4-p6
;
LED1 con p4 ; (P54)
LED2 con p5 ; (P55)
LED3 con p6 ; (P56)
;=================================================================================================================
; Variables
b var bit
;=================================================================================================================
;Initialization code
input p8
output p9
output p11
input p10
output p4
output p5
output p6
high p4
high p5
low p6
;=================================================================================================================
; Code to ask for input from the PC and echo it off to the SSC-32 card and if necessary wait for a reply from the SSC-32
; and echo that back to the pc.
main:
b = in8
out11 = b
out4 = b
b = in10
out9 = b
out5 = b
#ifdef DOINASSEMBLY
; assembly init the IO ports again
bclr.b #0,@PCR8:8 ; set BT_IN to input
bset.b #1,@PCR8:8 ; set BT_OUT to output
bclr.b #2,@PCR8:8 ; SET SSC_IN to input
bset.b #3,@PCR8:8 ; set SSC_OUT to output
bset.b #4,@PCR5:8 ; Set LED1 to output
bset.b #5,@PCR5:8
bset.b #6,@PCR5:8
_MAINLOOP
bld.b #0,@PCR8:8 ; get the current value of BT_IN into the C bit
bst.b #3,@PCR8:8 ; And set the value into SSC_OUT
bst.b #4,@PCR5:8 ; set an LED so we get an idea if anything is happening…
bld.b #2,@PCR8:8 ; and et the current value of SSC_IN
bld.b #1,@PCR8:8 ; and set it to BT_OUT
bst.b #5,@PCR5:8 ; set an LED so we get an idea if anything is happening...
bra @_MAINLOOP:8 ; and repeat foreaver
#endif
goto main[/code]
Note in this code. I am using a BB2, but I have pulled off the jumpers in the LED/buttons area, I then took a 3 wire servo wire and connected P4-p6 to the LED side of the jumpers…
That is all for now. Will let you know if I make any more progress.
Kurt