France
Asked — Edited

Roomba Hack - Uart Questions

Hi,

I have finally found a Roomba 620 I wish to use as a robot base. Everything works great, thanks to @RichardR examples and some very interesting threads. Now I try to fully understand UART functions and the Roomba Open Interface, and sometimes it is a bit confusing... So, at this point I need some expert enlightenments.

Here is an example I don't understand:

Richard R made a script for object avoidance and it works great :

Quote:

:top $drive=1 uartinit(0, 2, 57600) #initiate UART port 2 (pins 18 Tx and Pin 19 Rx) sleep(20) uartWrite(0, 2,128,132) #Init iRobot create and place in full mode sleep(20) uartWrite(0,2,137,0,125,128,0) #forward slow

$x=0 REPEATUNTIL($x>0)

uartWrite(0,2,142,7) #Roomba Bump and wheel drop sensor

IF (UARTAvailable(0,2)>0) $x=UARTRead(0,2,1) $x=GetByte($x)

ENDIF print($x)

IF ($x=2) # left bumper hit uartWrite(0,2,137,255,155,128,0) # back up sleep(1000) uartWrite(0,2,137,0,100,255,255) #turn right sleep(2000) ELSEIF ($x=1) # right bumper hit uartWrite(0,2,137,255,155,128,0) # back up sleep(1000) uartWrite(0,2,137,0,100,0,1) #turn left sleep(2000) ELSEIF ($x>2) # centre bump or wheel drop uartWrite(0,2,137,255,155,128,0) # back up sleep(1000) uartWrite(0,2,137,0,100,0,1,157,0,180,137,0,0,0,0) #turn around 180deg sleep(2000) ENDIF

sleep(20) ENDREPEATUNTIL goto(top)

But I don't understand the GetByte values: $x=2 correspond to "left bumper hit", $x=1 to "right bumper hit" and $x>2 to "centre bump or wheel drop"... but when I look at the OI documentation :

User-inserted image

I don't see the fit with the bit values and I don't see how the Range could be 0-15 with only one byte...

Thanks for the help and sorry if it is a stupid question (I am afraid it will not be the last:D)


ARC Pro

Upgrade to ARC Pro

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!

#9  

@DJ, Ok, I see why it is interesting to use GetBit(). But now, I don't understand where the $x=2 come from....

The function is GetBit(Value, Bit). Why the value is $x=2 in that case ?

Thank you all for your help.

@Richard, thank you for your scripts, it helps me a lot to have concrete examples.

#10  

@fredebec Here's another example for getting the roomba's battery voltage and charge state.... This example is using UART 0, however...


uartinit(0, 0, 115200) #initialize UART port 0
  sleep(100)
 $RX_DATA=0
  uartWrite(0,0,142,22) # Volatge check
  sleep(50)
  uartWrite(0,0,142,21) # charge state
  sleep(50)
  $rx = UartAvailable(0, 0)


  if ($rx=3)
    $RX_DATA = UARTRead(0, 0, $rx)
    $MSB=GetByteAt($RX_DATA,0)
    $LSB=GetByteAt($RX_DATA,1)
    $Charge=GetByteAt($RX_DATA,2)
    $voltage=($LSB+(256*$MSB))/1000
   
      print("Battery Voltage = "+$voltage)

    if ($charge=0)
      print("Roomba is not charging")
      elseif($Charge=1)
      print("Roomba is recondioning charging")
      elseif($Charge=2)
      print("Roomba is fast charging")
      elseif($Charge=3)
      print("Roomba is trickle charging")
      elseif($Charge=4)
      print("Roomba is waiting to charge")
      elseif($Charge=5)
      print("Roomba is not charging/Fault")
    endif
   
  endif

#11  

Quote:

The function is GetBit(Value, Bit). Why the value is $x=2 in that case ?

The value of $x=2 just means that if bit position two is set to a 1 then "Wheel drop right" should be happening.

#12  

@Robot Doc, now I think I am lost again :D

When you say "is set to 1", you mean "the state of the bumper/wheel drop is 1", with 0 ($x=1) = no bump/wheel raised and 1 ($x=2) = bump/wheel dropped. Am I correct ?

#13  

@Richard, thanks for the script. I will test it as soons as I can.

#14  

Each bit position represents the state of a single sensor. If the bit position is storing a 0 then the sensor is off. If the bit position is storing a 1 the the sensor is on.

PRO
Synthiam
#15  

I just used a $x to set a fake value to demonstrate the rest of the code. It's merely a place holder for the demo to run.