
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.
ThanksCode:
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)
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.
Code:
two
Code:
plus four
Code:
Like I said everything works properly after the first time thru the script. It seems like it isn't "releasing" from the Control Command.
Code:
The other scripts I am having problems with, start with an Auto Position script.
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.
I also tried ControlCommand("Script Manager", ScriptStop,"TheScriptName") and that didn't make any difference.
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...
Thanks to both of you for your help.