I'm needing some help figuring out a way to use a returned position value from a Kangaroo X2 in a EZ-Script. What I want to do is take that value and use it in an "If"/"ElseIF" statement, do a couple "Less Than, Greater Than" comparisons and send the script to one of two sub sections. The problem I think I'm having is the returned value is not a clean number that the computer can do math with. For example; I'll send a position value to the Kangaroo of 1800 to move the motor into one position. After the move and I send a request for a position it will return a value of 1,p1800. All's well because it looks like the motor is in the proper spot. But I want to use that value to compare it to the center point of 1290 so I can move back to center.
Any idea how I can use that returned 1,p1800 in an ez script to compare it to a number like 1290 or chance it into a number I can use? I'm sending these commands through the Uart port using SimpleSerial Commands.
Here's the script I'm trying to get to work. assuming the motor has already moved to the endpoint of 1800 (or even the other side of center at 900) and I want to get it back to 1290 (center). It will run and in the script window I can see it's returning the proper position reading the script is asking for. However it will always go to the same subsection weather that reading is above 1290 or below. I have a feeling that the script is not recognizing the way the returned position value is formatted and cannot do the math(1,p1800). However my logic in the script may also be screwed up :
$Arm_Speed = 600 # Speed that arm runs at (will Stay in this script)
$Positon = 1290 # Arm Center position sent to Roo in serial command
$Getp = "Getp" #Command to get position from Roo
#UARTWrite(2, 0, "1, P"+$Positon, "S"+$Arm_Speed, 0x0d) #Send serial command w/wanted variables
uartWrite(2, 0, "1, Getp", 0x0d)
$x = UartAvailable(2, 0)
print("Bytes in buffer: " + $x)
$GetP = UARTRead(2, 0, $x)
print("Received: " + $Getp)
Sleep( 1000 )
if($Getp >($getp + ($getp + 19/100)))
ELSEif ($Getp < ($getp + ($getp + 19/100)))
uartWrite(2, 0, "1, P1290 s600", 0x0d)
uartWrite(2, 0, "1, Powerdown", 0x0d)
uartWrite(2, 0, "1, P1256 s600", 0x0d)
uartWrite(2, 0, "1, Powerdown", 0x0d)
Upgrade to ARC Pro
Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming
EDIT: COOL! I see the main clue (among others). You showed me a way to split up the returned position value and just use the numbers, changed them to a $Position variable and changed my stupid GetP comparison to the $Position variable. I'm truly grateful! I'll give it a try tomorrow after work if I don't have to stay late.
I used the split() command to receive only the data after the letter p.
I noticed that the Split function seems to be Case sensitive. When asking for a return position from the Kangaroo it will return a value starting with either a Capital P showing that the move has been completed or a Lowercase p showing that the move is still in progress. The Split command you showed me was written with the Lowercase p. You skillfully edited my sad little script and added that simple but cool loop that makes it go back and check to see if the Uart buffer has the proper info loaded. That loop makes sure the move is complete before it reads the buffer so I'll always get a Uppercase P returned. In short I needed only to change your lowercase p to an Uppercase P before the script would work properly. Here is a comparison:
Here's my final script and assumes the motor is in a different position other than center and will bring it back to center (I'm sure I still need to tweak it a little):
Again DJ, thanks. You've opened a door for me. I think this was the basic key I needed to keep going and finish my scripting of my B9 arm.