Canada
Asked — Edited
Resolved Resolved by Dunning-Kruger!

I Need Help Figuring Out This Scripting Question

I have a few scripts that don't do what they are suppose to do until I run thru them once. Let me explain that - in the script below the robot is doing addition. What should happen is, for example, when I say "two" the robot should look at it's hand, extend 2 fingers and say "two" and when I say "plus four" the robot should look at it's other hand, extend 4 fingers and say "add four". What is happening is the robot is looking where it should and saying what it should but not extending the fingers. It does the addition part correctly and returns to the start of the script. Then given the commands again everything runs properly. It may be something I'm doing in my scripting because this happens in a couple of other scripts I have written. I would appreciate any thoughts on how to solve this problem. Thanks




Sayezb("ok, I like doing math")


sleep(500)

ControlCommand("Script Manager", ScriptStart, "Do math")

sleep(4000)

sayezb("ready")

:start

$heard = "speech"

WaitForChange($heard)

if($Heard = "one")

$x = 1

elseif($heard="two")

$x = 2

elseif($heard ="three")

$x = 3

elseif($heard = "four")

$x = 4

elseif($heard = "five")

$x = 5


endif



WaitForChange($heard)

if($heard = "plus one")

$y = 1

elseif($heard = "plus two")

$y = 2

elseif($heard ="plus three")

$y = 3

elseif($heard ="plus four")

$y = 4

elseif($heard = "plus five")

$y = 5

#print($x + $y)

endif





WaitForChange($heard)

if($heard = "what does that equal")

servo(d0,150)

servospeed(d0,3)

servo(d1,90)

servospeed(d1,3)

sayezb("ummm")


ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(1500)

Servo(d0,116)

servospeed(d0,3)

servo(d1,118)

servospeed(d1,3)

sleep(1500)

$sum = Abs($x + $y)

Sayezb($x + " plus " + $y + " equals " + $sum)

endif





if($sum = 2)

ControlCommand("Script Manager", ScriptStart, "equals two")

elseif($sum = 3)

ControlCommand("Script Manager", ScriptStart, "equals three")

elseif($sum = 4)

ControlCommand("Script Manager", ScriptStart, "equals four")

elseif($sum = 5)

ControlCommand("Script Manager", ScriptStart, "equals five")

elseif($sum = 6)

ControlCommand("Script Manager", ScriptStart, "equals six")

elseif($sum = 7)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum =8)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum = 9)

ControlCommand("Script Manager", ScriptStart, "equals nine")

elseif($sum = 10)

ControlCommand("Script Manager", ScriptStart, "equals ten")

endif



sleep(4000)

ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(500)



GoTo(start)



ARC Pro

Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

#1  

Hey Bob. I assume that the scripts called equal two and equal three and so on are used to extend the fingers on a certain hand. I also assuming that equal seven extends 5 fingers on one hand and two on the other hand.

What I think you need are scripts like "left two" which would extend 2 fingers on the left hand and say "right two" which would extend two fingers on the right hand. In your script, when you say two, in your if statement, you would call the "left two" script. Later in your script, when you catch you saying plus two, you would call the "right two" script. The rest of the script is doing what you want so there is no need for changes.

#2  

This is assuming that you are looking at the left hand first, but it is easy to change once the other scripts have been made.






Sayezb("ok, I like doing math")


sleep(500)

ControlCommand("Script Manager", ScriptStart, "Do math")

sleep(4000)

sayezb("ready")

:start

$heard = "speech"

WaitForChange($heard)

if($Heard = "one")

$x = 1
ControlCommand("Script Manager", ScriptStart, "Left One")
elseif($heard="two")

$x = 2
ControlCommand("Script Manager", ScriptStart, "Left Two")
elseif($heard ="three")

$x = 3
ControlCommand("Script Manager", ScriptStart, "Left Three")
elseif($heard = "four")

$x = 4

elseif($heard = "five")

$x = 5


endif



WaitForChange($heard)

if($heard = "plus one")

$y = 1
ControlCommand("Script Manager", ScriptStart, "Right One")

elseif($heard = "plus two")

$y = 2
ControlCommand("Script Manager", ScriptStart, "Right Two")

elseif($heard ="plus three")

$y = 3
ControlCommand("Script Manager", ScriptStart, "Right Three")

elseif($heard ="plus four")

$y = 4

elseif($heard = "plus five")

$y = 5

#print($x + $y)

endif





WaitForChange($heard)

if($heard = "what does that equal")

servo(d0,150)

servospeed(d0,3)

servo(d1,90)

servospeed(d1,3)

sayezb("ummm")


ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(1500)

Servo(d0,116)

servospeed(d0,3)

servo(d1,118)

servospeed(d1,3)

sleep(1500)

$sum = Abs($x + $y)

Sayezb($x + " plus " + $y + " equals " + $sum)

endif





if($sum = 2)

ControlCommand("Script Manager", ScriptStart, "equals two")

elseif($sum = 3)

ControlCommand("Script Manager", ScriptStart, "equals three")

elseif($sum = 4)

ControlCommand("Script Manager", ScriptStart, "equals four")

elseif($sum = 5)

ControlCommand("Script Manager", ScriptStart, "equals five")

elseif($sum = 6)

ControlCommand("Script Manager", ScriptStart, "equals six")

elseif($sum = 7)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum =8)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum = 9)

ControlCommand("Script Manager", ScriptStart, "equals nine")

elseif($sum = 10)

ControlCommand("Script Manager", ScriptStart, "equals ten")

endif



sleep(4000)

ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(500)



GoTo(start)

#3  

@d. cochran Here's my script for "two" and "plus four"

two


$heard = "two"
Sayezb("two")

servo(d0,57)
servospeed(d0,4)
servo(d1,90)
servospeed(d1,4)
servo(d4,0)
servospeed(d4,0)
servo(d3,0)
servospeed(d3,0)

plus four


$heard ="plus four"
Sayezb("plus four")

servo(d0,57)
servospeed(d0,2)
servo(d1,135)
servospeed(d1,2)
Servo(d14,0)
servospeed(d14,0)
servo(d15,0)
ServoSpeed(d15,0)
servo(d16,0)
servospeed(d16,0)
servo(d17,0)
servospeed(d17,0)

Like I said everything works properly after the first time thru the script. It seems like it isn't "releasing" from the Control Command.


ControlCommand("Script Manager", ScriptStart, "Do math")

The other scripts I am having problems with, start with an Auto Position script.

#4  

Question for you. Are you wanting there to be a response by the hand when you say "Two" and again when someone says "Plus Two"?

I dont see how the robot is extending 2 fingers in the script unless it is happening in another script that isn't provided. It may be that it is happening in another script which isn't started until later in the script.

It is also possible to stop scripts if one is hanging around causing you issues. ControlCommand("Script Manager", ScriptStop,"TheScriptName")

From what you are describing, it looks like its more of a matter of something happening in another script that isnt started early enough in this script.

Gotcha, after rereading your second post.

The "two" and "plus four" scripts are not being called from this script.

#5  

It looks like these might be being called from the "Do Math" script. Post that one if you would.

#6  

Are the Two and Plus four scripts launched from the Do Math script along with all of the other possible answers? If this is the case, it may just be that enough time isn't being given for the other scripts to all start. If this is what is happening, I would think that it would be far more efficient to only launch these when needed as in the example that I sent to you. There would be a lot less activity on the processor that ARC is running on as there would be 10 less processes for the processor to monitor.

#7  

The "Do Math" script simply brings the arms and fingers into position. Each number has a script , like the ones I posted and are only called on when that number is heard.

#8  

Are you using a WaitForChange($HEARD) there also or are you evaluating $x and $y?

#9  

WaitForChange($HEARD) I also tried ControlCommand("Script Manager", ScriptStop,"TheScriptName") and that didn't make any difference.

#10  

Hey Bob... I am late to the party and may be way off base but.... I do notice in my own scripts that sometimes when I release servos or set them using Servo(D0,0) they won't respond to another position command at first... Sometimes I need to reset servo speed again to 0 and then to another speed that I wanted before they would respond again...

#11  

I think that what richard is saying is probably the issue. Maybe setting all of the hand servos before starting the math script ( at the top of this script) would solve this for you.

#12  

Good idea Richard, I set all of the finger servo speeds to 0 and that seems to have solved the problem. In another script, I had to do it twice. It seems I have to do this after a CC or an AutoPosition that sets the fingers to a certain position.

Thanks to both of you for your help.

#13  

@Bob.... Hey I got lucky.... LOL. How is the lower stomach mechanism coming along? I still plan to do mine, but I actually started a part time job so I have a little less free time than I use to have... :)