Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
USA
Asked — Edited
Resolved Resolved by Rich!

Debugging Mobile Interface

First off, let me say thank you to all of you who have been so helpful. I'm a newbe with EZ-Builder, so I really appreciate the assistance.

I'm having trouble with a script getting hung up, or stopping because of an error. It's a fairly striaght forward script, just moving a pan servo with my HCsr04 sonar on it, looking for obstacles, and directing the drive motors. Someone was very helpful in pointing out the Variable watch as this was a great help in debugging. I also used the Console to watch the code execute, and finally got it working the way I expected it too.

Then I downloaded the same code to my tablet and the code hangs up apparently early in its execution. First off, I don't understand why it would work on my PC and not on the tablet, I know the tablet does not have all of the functionality as the PC, but I'm only using the following commands;

If/then
servo()
servospeed()
goto()
print()
sleep()
getping()
return()

Is there a way to watch it execute on the tablet the way you can use the Console on the PC so I can debug this?

Thanks

AI Support Bot
Related Content
Synthiam
PRO
Synthiam
#1  
You can run a script and watch the output on the mobile interface. However, it's the same complied as the PC version. Can you share your code?
#2  
sure, be glad to share it. Some of it is commented out only because I'm debugging it and trying to see which parts are causing problems, but as it stands now it works from the PC. Please let me know if I didn't use the UBB Code properly;

Code:



# ********* Roam 1.0 10/5/15 ***********
# variables only listed for testing
# as they are included in the Initialize script
$MinDistance = 25
$Center = 105
$Left = 25
$Right = 165
$LeftDist = 100
$CtrDist = 100
$RightDist = 100
$Distance = 100
$D0 = 108
$D1 = 108

SayEZB("I would like to explore my surroundings")

Servo(D2, $Center)
ServoSpeed(D2,4)

:DirectionDecision
Servo(D0,108)
Servo(D1,108)

Servo(D0,98)
Servo(D1,118)
sleep(2000)

Servo(D0,108)
Servo(D1,108)

#Left
Servo(D2, $Left)
Servo(D3,98)
sleep(4000)
Goto(Sonar)
$LeftDist = $Distance
Print("Left = " + $LeftDist)

#Center
Servo(D2,$Center)
sleep(4000)
Goto(Sonar)
$CtrDist = $Distance
Print("Center = " + $CtrDist)

#Right
Servo(D2, $Right)
sleep(4000)
Goto(Sonar)
$RightDist = $Distance
Print("Right = " + $RightDist)

Servo(D2,$Center)
sleep(4000)

if($LeftDist > $CtrDist AND $LeftDist > $RightDist)
Goto(TurnLeft)
endif

if($CtrDist > $LeftDist AND $CtrDist > $RightDist)
Goto(DriveStraight)
endif

Goto(TurnRight)

Goto(DirectionDecision)


:TurnLeft
Servo(D0,138)
Servo(D1,138)
sleep(1200)
#if(Round(GetPing(D9,D8)/2.54,0) < $LeftDist + 5)
# goto(DriveStraight)
#Elseif (Round(GetPing(D9,D8)/2.54,0) > $LeftDist - 5)
goto(DriveStraight)
#endif
goto(TurnLeft)


:TurnRight
Servo(D0,78)
Servo(D1,78)
sleep(1200)
#if(Round(GetPing(D9,D8)/2.54,0) < $RightDist + 5)
goto(DriveStraight)
#Elseif (Round(GetPing(D9,D8)/2.54,0) > $RightDist - 5)
# goto(DriveStraight)
#endif
Goto(TurnRight)


:DriveStraight
Servo(D0,118)
Servo(D1,98)

#Look Left
#Servo(D2, $Left)
#Servo(D3,98)
#ServoSpeed(D2,2)
#sleep(2000)
#Goto(Sonar)
#if($Distance < $MinDistance)
#Goto (Avoid_Left)
#endif

#Look Center
Servo(D2, $Center)
sleep(2000)
Goto(Sonar)
if($Distance < $MinDistance)
goto(DirectionDecision)
endif

#Look Right
#Servo(D2, $Right)
#sleep(1500)
#Goto(Sonar)
#if($Distance < $MinDistance)
#goto(Avoid_Right)
#endif

#Look Center
Servo(D2, $Center)
sleep(2000)
Goto(Sonar)
if($Distance < $MinDistance)
goto(DirectionDecision)
endif
goto(DriveStraight)


:Avoid_Left
$D0 = $D0 - 10
$D1 = $D1 - 10
Servo(D0,$D0)
servo(D1,$D1)
sleep(1500)
$D0 = $D0 + 10
$D1 = $D1 + 10
servo(D0,$D0)
servo(D1,$D1)
Return

:Avoid_Right
$D0 = $D0 + 10
$D1 = $D1 + 10
Servo(D0,$D0)
servo(D1,$D1)
sleep(1500)
$D0 = $D0 - 10
$D1 = $D1 - 10
servo(D0,$D0)
servo(D1,$D1)
Return


:Sonar
$Distance1 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance1)
sleep(1000)
$Distance2 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance2)
sleep(1000)
$Distance3 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance3)
sleep(1000)

if($Distance1 = $Distance2)
$Distance = $Distance1
Return()
endif

if($Distance1 = $Distance3)
$Distance = $Distance1
Return()
endif

if($Distance2 = $Distance3)
$Distance = $Distance2
Return()
endif

# Redundant section in case of no matching sonar readings

$Distance1 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance1)
sleep(1000)
$Distance2 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance2)
sleep(1000)
$Distance3 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance3)
sleep(1000)

if($Distance1 = $Distance2)
$Distance = $Distance1
Return()
endif

if($Distance1 = $Distance3)
$Distance = $Distance1
Return()
endif

if($Distance2 = $Distance3)
$Distance = $Distance2
Return()
endif

$Distance1 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance1)
sleep(1000)
$Distance2 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance2)
sleep(1000)
$Distance3 = Round(GetPing(D9,D8)/2.54,0)
Print($Distance3)
sleep(1000)

if($Distance1 = $Distance2)
$Distance = $Distance1
Return()
endif

if($Distance1 = $Distance3)
$Distance = $Distance1
Return()
endif

if($Distance2 = $Distance3)
$Distance = $Distance2
Return()
endif

Goto(DirectionDecision)#only executes if no matching sonar readings
Goto(Sonar)# if this line executes, script stops running


#3  
what tool can I use to watch the code execute from my mobile device?
PRO
Synthiam
#4  
Use the script control. There are many suggestions for your code - I'm on my phone at the moment and will not be in front of a computer for another few hours to edit it.
#5  
You need to add a sleep command in this section. Can you see where?

:DirectionDecision
Servo(D0,108)
Servo(D1,108)

Servo(D0,98)
Servo(D1,118)
sleep(2000)

Servo(D0,108)
Servo(D1,108)

This may not be your main problem but it will get this section working.
#6  
Thank you, it's obvious to me now, but not before. I need to insert a sleep command after the first two lines above because I'm giving the servos a command and not allowing time for it to be fulfilled.

Still don't understand though why this would work from the PC and just not on the tablet? I would like to be able to debug from the tablet in the future. Above you said to use the Script Control, but I don't see this on the tablet anywhere. I looked under the controls tab and the closest thing I could find is the "Script Manager", but that says it's not available on the mobile.
#7  
I thought it was obvious above on where to put the sleep command, but perhaps I guessed it wrong because my script still does not work on my mobile, but does work from my PC after inserting the sleep command after the first two lines above.
#8  
sorry to be a bother, but I would appreciate it if you could tell / show me where to find the script control you are referring to above. I have looked all over in the ARC for it, but don't see it. I've found the Variable watch, which works, but doesn't give me every thing I need to debug my mobile script. The Script Monitor and Script Console are not enabled for Mobile.

I need to debug it from the mobile because my script works when run from my PC and when I open the script to edit it and click on the run script, but does not work when run from my mobile app.

Thanks in advance for any direction.
United Kingdom
#9  
There should be no difference between the desktop PC version and the Mobile version. Scripts run the same on both.

You can use temporary flags to help debugging, it's what I did when scripting anything. This is as simple as using something like $DebugFlag0 = 1

Pop those in various places, rename them if needed i.e. $SonarFault = 1 and watch the variable watcher. If it doesn't error on the PC then it wont error on the tablet. If it does have strange behaviour on the tablet then the problem lies in the OS or software on the tablet and I would suggest removing and reinstalling everything again on the tablet.

Another thing you could do is add an LED which will blink at specific points in the script. While running from the tablet count the blinks, you can then find out exactly where the script is when it fails.

To add, on the PC, if you are debugging a script in the script control it runs slower. This is important to note when you are relying on time i.e. the sleep commands or the time it takes to compute so many commands.
#10  
Thanks for the good suggestions, I will try the variable flag to watch in the variable watcher.

There is a definite difference between running my script from my pc & tablet, as I have done it several times. I hadn't thought about the tablet is being the issue, as I have run about half a dozen other scripts without issue. I even got a notice last week that there is an update for my android is, and am putting off installing it because I was afraid of software conflicts with ARC.

Thanks again, will give it a shot.