Kinect Xbox 360 Depth Mapping icon Kinect Xbox 360 Depth Mapping Converts Xbox 360 Kinect depth frames into NMS obstacle scans for ARC path planning, SLAM, and obstacle avoidance. Try it →
France
Asked — Edited
Roomba Hack - Uart Questions

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

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#1  

The bit positions all have a decimal weight.

Bit position 0 set to binary 1 has a weight of 1

Bit position 1 set to binary 1 has a weight of 2

Bit position 2 set to binary 1 has a weight of 4

Bit position 3 set to binary 1 has a weight of 8

If all 4 bit positions are set then the decimal value would be 15. 1+2+4+8=15

#2  

Thanks @Robot Doc.

All these "bit", "bytes", "16-bit values", "high bytes", "two’s complement" notions are completely new to me. But I think I get it...

So, to take the same example, if there is both a "Bump Left" and a "Wheel Drop Left", it will correspond to a bit position 1 (weight of 2) + a bit position 3 (weight of 8) and so, in the script, the $x value will be 10. Right?

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#3  

Use GetBit()


$x = 2

if (getbit($x, 0))

  print("Bump Right")

endif

if (GetBit($x, 1))

  print ("Bump Left")

endif

if (GetBit($x, 2))

  print ("Wheel Drop Right")

endif 

if (GetBit($x, 3))

  print ("Wheel Drop Left")

endif

#4  

I am at work now.... i will check this thread later when i get home.... i think this script i wrote for the 400 series roomba.... i think the baud rate is wrong for the 600 series. .. @Doc can help you too after all he is the roomba doctor:)

#5  

That script is a little rough... and the baud rate is wrong. It should be 115200 not 57600... The 600 series uses 115200 baud.... also you only need to initialize the UART once.....

#6  

@Richard' you are right. I already have modify baud rate and, as I said, the script works just fine (that's why it is not "required assistance thread" :) ).

But I want to better understand the way ARC and Roomba OI works together to go further in my future scripts, and your script was a good example to illustrate what I understand and what I don't...

@DJ, thanks for the tip and the script example

#7  

@fredebec... Ok no worries..... I have another script that can read 2 byte data like Roomba battery voltage.... I'll post it for you tomorrow (my time) afternoon when I get home from work...

#8  

fredebec

Quote:

So, to take the same example, if there is both a "Bump Left" and a "Wheel Drop Left", it will correspond to a bit position 1 (weight of 2) + a bit position 3 (weight of 8) and so, in the script, the $x value will be 10. Right?

Yes, you got it !