Asked
Resolved Resolved by Dave Schulpius!

Getp Command For Kangaroox2 For Use With If/Endif??

Hello everyone,

I am trying to create a simple condition using a Kangaroox2 and two motors with independent control.  I found a really great forum dialogue from a few years ago that helped me get started but I am now currently stuck and my EZB is disconnecting at the same point in the code.  I am finishing up code for a working periscope and lifter in my R2 unit.

Here is the original link...

https://synthiam.com/Community/Questions/Help-Using-A-Returned-Position-Value-From-Kangaroo-In-Ez-script-4618

Thanks to help from Dave, I was able to get my setup working fairly well but there are times when the periscope is out of alignment and crashes into the dome when I try to lower it.  So, I managed to tweak the code from Dave and DJ in the article to get position values from the kangaroo but have hit a wall.

Here's my attempted code for monitoring the position of the rotary motor so the periscope can lower without crashing.   I have notated where the code crashes and the EZB disconnects.  I believe it is related with the $Roo_position = Split ($GetP.....) command along with the following If/Endif condition.

Thank you for any help!

Douglas


$Rotary_Position = 43 #Rotary Home position Kangaroo is shooting for $GetP = "Getp" # Command to get position from Roo

uartWrite(2, 0, "2, Getp", 0x0d)

:waitForData

$x = UartAvailable(2, 2) print("Bytes in buffer: " + $x)

if ($x < 4)

Go back and wait for data again because we did not receive the least number of expected bytes

goto(waitForData) endif

$GetP = UARTRead(2, 0, $x) print("Received: " + $GetP)

Sleep( 1000 )

Getting stuck below this line and EZB gets goobered and disconnects from the wifi

$Roo_position = Split($GetP, "P",1) #2,pXXXX is returned. Get everything after the P as P is case senceitive

Send script to proper subscript depending on if position is above or below center

if($Roo_position = $Rotary_Position) goto(CenterDown) ELSE goto(Centerup) endif

:CenterDown #If Rotary is at correct position than lifter will lower uartWrite(2, 0, "1, P798 s600", 0x0d) Sleep(4000) uartWrite(2, 0, "1, Powerdown", 0x0d) Halt()

:Centerup #If Rotry is in the wrong position then lifter will rise uartWrite(2, 0, "1, P1 s600", 0x0d) Sleep(4000) uartWrite(2, 0, "1, Powerdown", 0x0d) Halt()


Anyone have a solution?


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.

#2  

Hmmmmm... forgive my ignorance but would servo mode be able to achieve continuous rotation as well as a homing ability?  If so, then yes, servo mode may be preferable.  I saw your live hack!  It was very informative!

PRO
Synthiam
#3  

I’ll have to look into that and get back to you...

Few questions...

  1. what are you using for position sensor on the wheels? Encoders or potentiometers?

  2. are these two motors used to drive the robot around? Like are they the movement wheels for the robot to get around the room for locomotion?

#4   — Edited

1.) Encoders

2.) Perhaps this video will help.   The sabertooth is controlling two motors independently.  One raises the periscope and the other handles the rotation.  I tuned each motor individually.  I used a mechanical stop tune on the lifter and a single limit switch tune on the rotary motor.  There is a ball bearing the rides a track within the rotary mechanism that hits the limit switch; registering home with the Kangaroox2.

I have control of the mech but I'm trying to get some insurance to be sure the lifter does not lower unless the rotary is at position line 43 (Home position).  I've had a few dome crashes where for some reason the EZB has lost track of the rotary position and lowered the periscope.  The tolerances are really tight.

This morning I noticed this link in the solution suggestion box.  I am also getting the same error when we get to the split line.  Perhaps this is also a factor.   https://synthiam.com/Community/Questions/Error-On-Line-25-Missing-String-Quotes-4978

Thank you so much DJ!  I'm always impressed when I see your participation with the community!

#5  

Hi Douglas,

I haven't really taken the time to study your problem or script. However I think I can help with "one" problem you may be having. There may be others but again I haven't looked that closely.

The one issue that I was having was with that damn "P". The Roo has a feature that mucks things up in the script when it sends the return information for position. THE Roo will return either an upper or lower case "P" depending on if the move is complete or not.  An Upper case means motor has finished it's move and stopped. A Lower Case means that motor is still moving.

Below I have attached the entire script for moving both my arms out of the torso of my B9 robot. It's important that they are fully out before anything moves because of close tolerances. Notice the sections "Find out (and print if wanted) if the P is upper or lower case" and "Defeat the P". This is where the script works it's magic to figure out which is witch and work around this issue.

I hope this helps. Please let us know. I'll study further over the next day or two.

#Move Both ARS's Out of torso
#-----------------------------------------------------------------
$Both_ARS_Extended = 0 #Sets Varable to both ARS still in torso. 0=in, 1=out
ClearVariable("$Get_Lft_Carrage_P") #Clears Variable in case it's in an Array
ClearVariable("$Get_Rt_Carrage_P") #Clears Variable in case it's in an Array

#############################################################
#This Scrit and the action it's attached to will move the ARS DC motors
#and the Wrist Servos.
#Do not use below commands to center DC Elbow motors. They will stay centered when
#when stored in the Torso. They were centered in the "Both Ars In" Script.
#Sleep(50)
#uartWrite(2, 0, "1,P"+$Rt_Elbow_Center, "s100", 0x0d) #Move Rt Elbow Motor
#Sleep(200)
#uartWrite(2, 0, "2,P"+$lFt_Elbow_Center, "s100", 0x0d) #Move Lft Elbow Motor
################################################################
Sleep(100) 

uartWrite(2, 2, "1,p845 s662", 0x0d) #Move Rt ARS Carrage full out
Sleep(50)
uartWrite(2, 2, "2,p845 s662", 0x0d) #Move Lft ARS Carrage full out
Sleep(1250)

# ------------------
# Loop to Read & send ARS position info for Waiting Automation Arm
# Script so it can safely start moving arms when ARS is fully out.
# The following will get the position of the LFt & Rt ARS Kangaroo positions

# --------------------

:Wait_ARS_Loop

# Get Right ARS Roo Position
uartWrite(2, 2, "1, Getp", 0x0d)

:waitFor_Rt_Data
Sleep(30)

$y = UartAvailable(2, 2)
# Sleep(30)
# print("Bytes in buffer:" + $y)
if ($y < 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitFor_Rt_Data)
endif

$Get_Rt_Carrage_P = UARTRead(2, 2, $y)
# Sleep(30)
# print("Received:" + $Get_Rt_Carrage_P)
Sleep( 50 )

# -------------------------------
# Find out (and print if wanted) if the P is upper or lower case.
# Upper case means motor has finished move ans stoped.
# Lower Case means that motor is still moving.
$P_or_p = GetCharAt($Get_Rt_Carrage_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.
# Print("P_or_p:" + $P_or_p)

# -----------------------------
# # Defeat the P_or_p because it must die!
if ($P_or_p = "p")
  $Rt_Carrage_Position = Split($Get_Rt_Carrage_P, "p",1) #1,pXXXX is returned. Get everything after the Lower case p (P is case senceitive).
ELSEif ($P_or_p = "P")
  $Rt_Carrage_Position = Split($Get_Rt_Carrage_P, "P",1) #1,pXXXX is returned. Get everything after the Upper case P (P is case senceitive).
endif
Sleep(100)

# --------------------------

# Get Lft ARS Roo position
uartWrite(2, 2, "2, Getp", 0x0d)

:waitFor_Lft_Data
Sleep(30)

$y_lft = UartAvailable(2, 2)
# Sleep(30)
# print("Bytes in buffer:" + $y_lft)

if ($y_lft < 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitFor_Lft_Data)
endif

$Get_Lft_Carrage_P = UARTRead(2, 2, $y_lft)
# Sleep(30)
# print("Received: " + $Get_Lft_Carrage_P)
Sleep( 50 )

# -------------------------------
# Find out (and print if wanted) if the P is upper or lower case.
# Upper case means motor has finished move and stopped.
# Lower Case means that motor is still moving. We need to know so we can move past this to the rest of the script.

$P_lft_or_p_lft = GetCharAt($Get_Lft_Carrage_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.
# Print("P_lft_or_p_lft:" + $P_lft_or_p_lft)

# -----------------------------
# Defeat the P_lft_or_p_lft
if ($P_lft_or_p_lft = "p")
  $Lft_Carrage_Position = Split($Get_Lft_Carrage_P, "p",1) #1,pXXXX is returned. Get everything after the Lower case p (P is case senceitive).
ELSEif ($P_lft_or_p_lft = "P")
  $Lft_Carrage_Position = Split($Get_Lft_Carrage_P, "P",1) #1,pXXXX is returned. Get everything after the Upper case P (P is case senceitive).
endif

  # ------------------------------
  # The following will loop and read both of the actual ARS carrage positions
  # until both carrages are full out past 700 (830 is actuallu full out but
  # this starts the anamation a little early to take away any delay).
Sleep(150)
if ($Rt_Carrage_Position < 700 and $Lft_Carrage_Position < 700)
  Goto (Wait_ARS_Loop)  # Go back and do this again because carrage is not fully out.
ELSEif ($Rt_Carrage_Position >= 700 and $Lft_Carrage_Position >= 700)
  $Both_ARS_Extended = 1 #Rt Carrage fully out. Set this variable so waiting Automation Script knows carrage is fully out.
endif
  # Arms should now be fully out and arms can safely move.
#6  

Thank you so much Dave!  I'll take a look this evening.

#7  

Ok, a little progress..

I was able to integrate Dave's new script but I'm still getting this error in the console.  I think it has something to do with the EZB receiving "2,P43\r\n" when I only need the number 43.

Good News = taming of the "P or p" Bad News = Line 40 boogers it up.

Start
> Bytes in buffer: 4000
> Received: 2,P43\r\n
> P_or_p:P
> Error on line 40: Missing String Quotes or Invalid Expression at index 0: "
Done (00:00:06.2483586)

Here is my script.... (I notated line 40 near the bottom for easy identification since that is the line throwing it off.)

#Rotary position should be 43   Rotary Home position Kangaroo is shooting for
$GetP = "Getp" # Command to get position from Roo

uartWrite(2, 0, "2, Getp", 0x0d)

:waitForData

$x = UartAvailable(2, 2)
print("Bytes in buffer: " + $x)

if ($x < 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes
  goto(waitForData)
endif

$Get_Rotary_P =UARTRead(2, 0, $x)
print("Received: " + $Get_Rotary_P)

Sleep( 1000 )

# -------------------------------
# Find out (and print if wanted) if the P is upper or lower case.
# Upper case means motor has finished move ans stoped.
# Lower Case means that motor is still moving.
$P_or_p = GetCharAt($Get_Rotary_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.
# Print("P_or_p:" + $P_or_p)

# -----------------------------
# # Defeat the P_or_p because it must die!
if ($P_or_p = "p")
  $Periscope_Position = Split($Get_Rotary_P, "p",1) #1,pXXXX is returned. Get everything after the Lower case p (P is case senceitive).
ELSEif ($P_or_p = "P")
  $Periscope_Position = Split($Get_Rotary_P, "P",1) #1,pXXXX is returned. Get everything after the Upper case P (P is case senceitive).
endif
Sleep(100)
Print("P_or_p:" + $P_or_p)
# --------------------------

# This is if/endif is line 40 in the console
if ($Periscope_Position = 43)
  goto(CenterDown)
ELSE
  goto(Centerup)
endif

:CenterDown #If Rotary is at correct position than lifter will lower
uartWrite(2, 0, "1, P798 s600", 0x0d)
Sleep(4000)
uartWrite(2, 0, "1, Powerdown", 0x0d)
Halt()

:Centerup #If Rotry is in the wrong position then lifter will rise
uartWrite(2, 0, "1, P1 s600", 0x0d)
Sleep(4000)
uartWrite(2, 0, "1, Powerdown", 0x0d)
Halt()

What does the hive mind think?

#8   — Edited

I gotta think about this. I remember having an issue like this. I think it had something to do with the place where the statement is split. I could be wrong but in the mean time try splitting it in one or two characters over. This level of coding is a little hit or miss for me. LOL

$Periscope_Position = Split($Get_Rotary_P, "P",1)