
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...
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?
Have you considered using the kangaroo as a servo in servo mode? I did a live hack for it because I find it’s a better alternative rather than querying position and trying to control it through script.
Tevans did this older tutorial: https://synthiam.com/Community/Tutorials/Sabertooth-Kagaroo-DC-motors-as-Servos-16229
and I did this live hack: https://synthiam.com/Community/HackEvents/Dimension-Engineering-Sabertooth-Kangaroo-19484
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!
I’ll have to look into that and get back to you...
Few questions...
what are you using for position sensor on the wheels? Encoders or potentiometers?
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?
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!
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.
Thank you so much Dave! I'll take a look this evening.
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.
Here is my script.... (I notated line 40 near the bottom for easy identification since that is the line throwing it off.)
What does the hive mind think?
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