
I have switched my robot over to Ez-Robot and I need some help converting the following Python script over the EZ-Robot language.
if (data == "lets do some math"):
math()
if (data == "one"):
one()
global first
first += 1
print(first)
if (data == "two"):
two()
global first
first += 2
print(first)
if (data == "three"):
three()
global first
first += 3
print(first)
if (data == "four"):
four()
global first
first += 4
print(first)
if (data == "five"):
five()
global first
first += 5
print(first)
if (data == "add one"):
plusone()
global second
second += 1
print(second)
if (data == "add two"):
plustwo()
global second
second += 2
print(second)
if (data == "add three"):
plusthree()
global second
second += 3
print(second)
if (data == "add four"):
plusfour()
global second
second += 4
print(second)
if (data == "add five"):
plusfive()
global second
second += 5
print(second)
if (data == "what does that equal"):
equals()
global number
number = (first+second)
i01.mouth.speak(str(first) + "plus" + str(second) + "is" + str(number))
global first
first = (first + second)
global second
second = 0
if (data == "start over"):
i01.mouth.speak("OK")
rest()
sleep(2)
i01.mouth.speak("ready")
global first
first = 0
global second
second = 0
print("starting from 0")
It's a script where the robot does addition. Can anyone help me out with this, thanks
Upgrade to ARC Pro
Get access to the latest features and updates with ARC Early Access edition. You'll have everything that's needed to unleash your robot's potential!
Thanks
# if then condition for Script one
ControlCommand("Script_1", ScriptStart)
Sleep(1000)
# if then condion for Script two
ControlCommand("Script_2", ScriptStart)
Sleep(1000)
Say(" I'm back in the main program")
Print("done")
You have three EZ Script controls named , main program, Script_1, and Script_2
Code:
The IF statement is similar however it depends where it gets the data from.
All variables need to be marked as variables with the $ symbol so in this case it would be $data.
Not 100% sure what == means in python (I dislike python so seldom use it). If it just means equals then the IF statement would be like so;
Code:
I presume math() calls a sub routine. So, as others have said there are a few ways to do this. Individual scripts or labels, gotos and returns. The label method would be;
Code:
The rest of the script would follow suit. Variables with a $ before it's name. Goto() for sub routines (or ControlCommand() if you want to start other scripts).
That's as much re-writing as I'm likely to do as I prefer to make people work it out themselves by pointing them in the right direction.
Read over the EZ-Script manual and see which commands look like they match the python commands.
$x = "first number"
$y = "second number"
$x + $y = "number"
If($x = "one")
ElseIf($y = "add two")
ElseIf($x + $y = "number")
Print("$x + $y = "number")
ENDIF
So with the verbal commands ( "one" and "add two") I am trying to get it to say three.
A little help needed.
Thanks
Code:
sure the variables should be in quotes?
EZ-Script is script. It will follow it line by line. Where you set the variable $data on line 5 and 6, line 5 is pretty much redundant as it immediately changes to what it's set as in line 6.
Also, "$x + $y =" is not valid.
Where does $x come from? Your IF checks against $x yet it's set to "first number" at the start of the script, nothing changes it from that.
To be honest there is a lot wrong with the script and very little that is right. Read through the EZ-Script manual, follow the EZ-Script tutorial and check out some other projects scripts from the cloud and the examples folder in ARC. For variables and IFs etc. check out the Introduction To Scripting topic I wrote some time ago, while there may have been some minor syntax changes since (possibly) it was minimal and pretty much limited to requiring quotes around strings.
Backing up to my first post;
if (data == "lets do some math"): is "heard data" from a voice command. In your "Introduction to Scripting" is see how to add input from a sensor but I'm not clear on how you add input from a voice command into a variable.
Thanks
my wall-e
There is a script called something like personality. It will help with scripting.
There is one called Init that will help you setup your variables.
There is a voice recognition command that is yes. it will help show you how to set a variable based on a voice command.
There is a lot more in there but these 3 things should help you get moving.
if you look at personality 10, you will see the WaitForChange command that you will need to use. It also shows how to use labels and goto.
If not, come back and ask again and I'll give you some more help.
Which part do you need more help on?
I only quickly read over the above again but it looks like you want to use
WaitForSpeech()
This will hold the script until the command is spoken.
Use that spoken command to set a variable or in an IF statement to trigger commands or responses.
Or use the speech recognition control for speech commands. When one is spoken have that trigger a script or control or sequence of events using ControlCommand()