To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 15210
15209  |  15211
Subject: 
Re: Serial Port Protocol
Newsgroups: 
lugnet.robotics
Date: 
Wed, 18 Apr 2001 22:18:20 GMT
Viewed: 
858 times
  
In lugnet.robotics, Kekoa Proudfoot writes:

Anyways, let me know if you are still confused.

No. That was perfect.

Several people have written off the list to know more about my serial port
adaptation for Director <> RCX. It's absolutely not finished, and has some
little bugs, but it works. So here's the Lingo code anyway. It won't make
total sense unless you have the Robolab patch to go with it running on the
RCX, but at least you'll be able to make your robot beep. The final system
lets you control a motor from Director, turning it clockwise,
counterclockwise and off from Lingo (you can do anything from there), as
well as a button on the RCX sending a message #4 to director. You have to be
careful about clearing the message buffer in Robolab.

I will post the completed version on my website when I'm finished. I prefer
having a minimum-bug version before rendering it public. But since people
seem so urgently in need of it, here is the working prototype (while you
wait) of the main scripts concerning just the lego communication protocol.
It'll get your project pretty far I think. It just needs work on the first
serial communication from the RCX > Director which fails unless something
has gone out from Director > RCX beforehand. I tried a bad fix of this by
intializing the RCX with a message out when the program loads, but not only
is this bad, it didn't really work. So I'm still at it.

It is entirely based on work already posted on the lugnet list, mostly from
Kekoa Proudfoot (that's quite a name!) and Dave Baum.

If you're lost about the handlers not included here: all calls to
"serialWrite()" are in fact calls to a sub-routine that takes care of serial
port output (I'm testing with both DirectionComm and SerialXtra to determine
which is better). You'll need to implement this yourself (again, this is
only a working draft). :

-- begin lingo --

global gLego

--

on legoInit()

  gLego = [ #lastCommand: #off, #lastOutput:[], #currentInput: [],
#lastInput: [] ]

end


--


on legoCheck()

  legoGetInput()

  if legoCheckInput()=0 then legoParseInput()

end


--


on legoGetInput()

  xString = serialRead()

  if xString = "" then exit

  xLength = xString.length
  xResult = []

  repeat with x = 1 to xLength
    gLego.currentInput.append(value(charToNum(xString.char[x])))
  end repeat

end


--


on legoCheckInput()

  -- pest control (otherwise known as bad programming). This is where I
don't fully understand the serial port xtra

  if gLego.currentInput.count < 3 then exit

  if gLego.currentInput[1] <> 85 and gLego.currentInput[2] <> 255 and
gLego.currentInput[3] <> 0 then
    gLego.currentInput = []
    return(-1)
  else return(0)

end


--


on legoParseInput()

  -- this handler needs to be reworked.

  xCount = gLego.currentInput.count
  if xCount < 9 then exit

  xNewList = []
  if xCount = 9 then

    xNewList = gLego.currentInput
    gLego.currentInput = []

  else

    xStartPtr = 0
    xEnd = (xCount - 2)
    repeat with xPtr = 4 to xEnd
      if gLego.currentInput[xPtr] <> 85 then next repeat
      if gLego.currentInput[xPtr+1] <> 255 or gLego.currentInput[xPtr+2] <>
0 then next repeat
      xStartPtr = xPtr
      exit repeat
    end repeat

    if xStartPtr <> 0 then
      xNewList = []
      xBegin = (xStartPtr - 1)
      repeat with x = xBegin down to 1
        xNewList[x] = gLego.currentInput[x]
        gLego.currentInput.deleteAt(x)
      end repeat
    end if

  end if

  if xNewList <> gLego.lastOutput and xNewList <> [] then
    if xNewList.count < 6 then exit
    xCommand = xNewList[4]
    xMessage = xNewlist[6]
    case (xCommand) of
      247 :
        put "message received from rcx:" && xMessage
        legoMessage(0)
    end case
    gLego.lastInput = xNewList
  end if

end


--


on legoBeep()

  legoSerial(81,3,1) -- 81 = 0x55 (beep command); 3 = 0x03 (rising beep)

end


--


on legoMessage(xMessageNum)

  legoSerial(247,xMessageNum,0) -- 247 = message > RCX

end


--


on legoSerial(xData1,xData2,xBitFlip)

  --  serialFlush() -- disactivated for the moment, probably unnecessary

  if (gLego.lastCommand=xData1) and (xBitFlip) then xData1 = bitXor(8,xData1)

  xCheckSum = (xData1 + xData2) mod 256
  xString = [85, 255, 0, xData1, (255-xData1), xData2, (255-xData2),
xCheckSum, (255-xCheckSum)]

  repeat with x in xString
    serialWrite(numToChar(x))
  end repeat

  gLego.lastCommand = xData1
  gLego.lastOutput  = xString

end


-- end lingo --

Any help to those Lingo users?

Douglas Edric Stanley
destanley@mac.com

http://www.abstractmachine.net

Professor of Digital Arts, School of Fine Arts, Aix-en-provence
Artist-in-residence, Laboratoire SCAN, Villa Arson, Nice
Artist/Researcher, Interactive Aesthetics Lab (LEI), University of Paris 8



Message is in Reply To:
  Re: Serial Port Protocol
 
(...) Here is an example that I hope clears things up: You said you know how to make the RCX beep. You didn't go into details, but to summarize, it is something to the effect of sending it 51 00 encoded in 55 ff 00 with complements and checksums. (...) (23 years ago, 17-Apr-01, to lugnet.robotics)

4 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR