Award
Congratulations CochranRobotics, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Assistance Requested

Help Steve G with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

Steve G claims to have checked these sources:
 
#1

Hi guys.

I have a quick question regarding the RGB animator config "Settings" menu. At the moment I have 4 animator actions and would like to know if I can asign a soundboard file to just one of these actions, and not have all four actions play the sound file on the "Positioner start script"?

Or is it a case of having 2 animator controls, one with sounds and one without?

Thanks in advance.

Steve.

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

1 quick additional question, what script command do I need to use to automaticly start an animation action after the EZ-B establishes a connection. I don't mean straight after connection (connection control config menu), I mean after the start up script has been run from the connection control.

I hope you can understand what I mean. If not, let me know. Smile

#3

in the connect box, click the gear. from there, you can use the 0-connection Established Cmd to set the script that would run when the connection establishes.

oops, didnt read the entire post. will re-read and then answer.

What I do is generate an init script that fires after the connection is established which then sets up everything to run as I need it to. In that script, I do things like set the movement action to stop, start monitoring power, set led's and start monitoring everything by calling a monitor script which is setup to loop.

#4

@d.cochran.

Thanks for your (edited) reply my friend. Tongue

I thought there might be a way so thanks for confirming. I haven't had much experience (or luck) with init scripts yet. Could you post a small example of one for me if you wouldn't mind?

Cheers,
Steve. Smile

#5

Read this lesson, it'll help you Smile http://www.ez-robot.com/Tutorials/Lesson/23

Apply what you learn from that lesson to the Connection Control's Configuration Menu. And as @d.cochran said, you're code will go into the Connection Established

#6

I haven't looked at these in a while but here is what I have on my project

Startup Script

Code:


#Starting variables
$x = 0
$lastDay = $day
$batteryLEDs = "BlinkLights"
$rsstext = ""
$QuestionAnswer = ""

#set decent voice
ControlCommand("Speech Settings", SetVoice, "Microsoft Hazel Desktop")
ControlCommand("Speech Settings", SetVoiceAge, "Teen")
ControlCommand("Speech Settings", SetVoiceEmphasis, "Strong")

say("Monitoring battery power levels")
# battery monitor
ControlCommand("Script Manager", ScriptStart, "BatteryMonitor")
if ($batteryLEDs = "BlinkLights")
say("There is an issue with the battery. Please correct.")
#Need to add stop once things ar connected and the bot can get readings.
elseif ($batteryLEDs = "LightsOff")
say("Battery power is very low. Please put in a new battery.")
stop()
else
endif

say("Turn off some unused stuff for now")
ControlCommand("Radar Scan", PauseOn)
sleep(1000)
ControlCommand("Light", PauseOn)
sleep(1000)
ControlCommand("RightEdge Detection", PauseOn)
sleep(1000)
ControlCommand("LeftEdgeDetection", PauseOn)
sleep(1000)
ControlCommand("Floor Map", PauseOn)
sleep(1000)
ControlCommand("Battery Cell 1", PauseOn)
sleep(1000)
ControlCommand("Compass", PauseOn)
sleep(1000)
ControlCommand("Battery Cell 2", PauseOn)
sleep(1000)
ControlCommand("Temp", PauseOn)


say("Starting systems monitors")
#Start monitoring
sleep(1000)
ControlCommand("Script Manager", ScriptStart, "MonitorTemps")
sleep(1000)
ControlCommand("Script Manager", ScriptStart, "MonitorLight")
sleep(1000)
ControlCommand("Script Manager", ScriptStart, "MonitorTilt")

#Play wakeup sound
ControlCommand("Soundboard", Track_13)

say("Setting up camera")
ControlCommand("camera", cameraservotrackenable)
sleep(1000)
ControlCommand("camera", cameramovementtrackdisable)
sleep(1000)
ControlCommand("Camera", cameraview)
sleep(1000)
ControlCommand("Camera", CameraStop)

say("Starting personality script")
#Start up the personality script
sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Personality Generator")

say("Turning on Speech recognition")
#Turn on speech recognition
#controlCommand("Speech Recognition", PauseOff)



Here are the other scripts
Battery Monitor - This script is from Rich and is old. I am replacing it with the abilities that the V4 has built into it already. I was using this when I was passing only 5 volts to the V4 but was using 7.4 volt batteries. Now I pass 7.4 volts to the V4 and regulate power after the V4.

Code:


# Read voltage level of 2S LiPo battery and report to software.
# Set variables
# Change $vundervoltage to the under voltage of your specific battery (leave at 3v if unsure)
# Change $vcritical to your lowest voltage you wish for the battery to get before human intervention
# Change $vmin to low level alert value
# Change $vmax to battery full charge
# Change $multiplyer if using voltage divider
# Factor is 5/255 for adc value conversion to volts
$vundervoltage = 3
$vcritical = 3.5
$vmin = 3.7
$vmax = 4.5
$multiplier = 2
$factor = 0.019607843
$batteryLEDs = "BlinkLights"
:ReadCells
# Get ADC values
$vc1 = GetADC(ADC0)
$vc2 = GetADC(ADC1)

# Convert values to voltage
$cell2 = $vc1 * $factor
$cell1 = $vc2 * $factor * $multiplier
$cell1 = $cell1 - $cell2
$batteryv = $cell1 + $cell2

# Check for errors on circuit
IF ($cell1 > $vmax or $cell2 > $vmax)
Print("Battery Monitor Error")
Print("Check Monitor Circuits")
$batteryLEDs="BlinkLights"

# Check for errors on battery connection
ELSEIF ($cell1 <= 0 or $cell2 <= 0)
Print ("Battery Connection Error")
Print("Check Battery Connection")
#Lights off
$batteryLEDs="LightsOff"

# Check for under voltage
ELSEIF ($cell1 <= $vundervoltage or $cell2 <= $vundervoltage)
Print ("Battery Under Voltage")
Print("Check Or Replace Battery")
$batteryLEDs="BlinkLights"

# Check if at critical levels
# Cell 1
ELSEIF ($cell1 <= $vcritical)
# Do sometihing if critical
Print("Cell 1 Critical")
# Shut down all power, switch to back up battery alarm?
# Shutdown power script

# Cell 2
ELSEIF ($cell2 <= $vcritical)
# Do sometihing if critical
Print("Cell 2 Critical")
# Shut down all power, switch to back up battery alarm?
#Shutdown power script

#add code for led levels
ELSE
# Output voltages
$cell1round = Round($cell1,2)
$cell2round = Round($cell2,2)
$totalround = Round($batteryv,2)
Print("C1 " + $cell1round + "V")
Print("C2 " + $cell2round + "V")
Print("To " + $totalround + "V")
IF ($totalround >= 9.0)
#Light15LED
$batteryLEDs="Light15LED"
ELSEIF ($totalround >= 8.82)
#Light14LED
$batteryLEDs="Light14LED"
ELSEIF ($totalround >= 8.69)
#Light13LED
$batteryLEDs="Light13LED"
ELSEIF ($totalround >= 8.56)
#Light12LED
$batteryLEDs="Light12LED"
ELSEIF ($totalround >= 8.43)
#Light11LED
$batteryLEDs="Light11LED"
ELSEIF ($totalround >= 8.3)
#Light10LED
$batteryLEDs="Light10LED"
ELSEIF ($totalround >= 8.17)
#Light9LED
$batteryLEDs="Light9LED"
ELSEIF ($totalround >= 8.04)
#Light8LED
$batteryLEDs="Light8LED"
ELSEIF ($totalround >= 7.91)
#Light7LED
$batteryLEDs="Light7LED"
ELSEIF ($totalround >= 7.78)
#Light6LED
$batteryLEDs="Light6LED"
ELSEIF ($totalround >= 7.64)
#Light5LED
$batteryLEDs="Light5LED"
ELSEIF ($totalround >= 7.52)
#Light4LED
$batteryLEDs="Light4LED"
ELSEIF ($totalround >= 7.39)
#Light3LED
$batteryLEDs="Light3LED"
ELSEIF ($totalround >= 7.26)
#Light2LED
$batteryLEDs="Light2LED"
ELSEIF ($totalround >= 7.13)
#Light1LED
$batteryLEDs="Light1LED"
ELSEIF ($totalround >= 7.0)
#Flash1LED
$batteryLEDs="BlinkLights"
ENDIF

ENDIF
ControlCommand("Script Manager", ScriptStart, "SetPowerLED")
# Wait 5 seconds
Sleep(60000)
# Go back to the start
Goto(ReadCells)



Set LED's for power

Code:


$lightCommand = $batteryLEDs
IF($batteryLEDs = "BlinkLights")
Repeat($counter,0,10,1)
set(d0,on)
set(d1,on)
set(d2,on)
set(d3,on)
saywait("There is an issue with the batteries")
set(d0,off)
set(d1,off)
set(d2,off)
set(d3,off)
EndRepeat

ELSEIF ($batteryLEDs = "Lights15LED")
set(d0,on)
set(d1,on)
set(d2,on)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights14LED")
set(d0,off)
set(d1,on)
set(d2,on)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights13LED")
set(d0,on)
set(d1,off)
set(d2,on)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights12LED")
set(d0,off)
set(d1,off)
set(d2,on)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights11LED")
set(d0,on)
set(d1,on)
set(d2,off)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights10LED")
set(d0,off)
set(d1,on)
set(d2,off)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights9LED")
set(d0,on)
set(d1,off)
set(d2,off)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights8LED")
set(d0,off)
set(d1,off)
set(d2,off)
set(d3,on)

ELSEIF ($batteryLEDs = "Lights7LED")
set(d0,on)
set(d1,on)
set(d2,on)
set(d3,off)

ELSEIF ($batteryLEDs = "Lights6LED")
set(d0,off)
set(d1,on)
set(d2,on)
set(d3,off)

ELSEIF ($batteryLEDs = "Lights5LED")
set(d0,on)
set(d1,off)
set(d2,on)
set(d3,off)

ELSEIF ($batteryLEDs = "Lights4LED")
set(d0,off)
set(d1,off)
set(d2,on)
set(d3,off)

ELSEIF ($batteryLEDs = "Lights3LED")
set(d0,on)
set(d1,on)
set(d2,off)
set(d3,off)

ELSEIF ($batteryLEDs = "Lights2LED")
set(d0,off)
set(d1,on)
set(d2,off)
set(d3,off)

ELSEIF ($batteryLEDs = "Lights1LED")
set(d0,on)
set(d1,off)
set(d2,off)
set(d3,off)

ELSEIF ($batteryLEDs = "LightsOff")
set(d0,off)
set(d1,off)
set(d2,off)
set(d3,off)

ENDIF



Light monitor

Code:


:start
$dark = GetDigital(d23)
if ($dark > 0)
say("it sure is dark in here.")
endif
Sleep(60000)
goto(start)



tilt monitor

Code:


:start
#$tilted = GetDigital(d22)
$tilted = 0
if ($tilted > 0)
say("Please set me upright")
endif
Sleep(5000)
goto(start)



temp monitor

Code:


#float tempC;
#int reading;
#int tempPin = 0;
#void setup()
#{
# Serial.begin(9600);
# analogReference(INTERNAL);
#}
#void loop()
#{
# reading = analogRead(tempPin);
# tempC = reading / 9.31;
# Serial.print("Temp:"); //Display the temperature on Serial monitor
# Serial.print(tempC);
# Serial.println("C");
# delay(500);
#}

:Start
$tempC = GetADC(adc5) / 9.31
$tempF = ($tempC*9/5)+32
if ($tempF > 100)
ControlCommand("Soundboard", Track_12)
endif
Sleep(60000)
goto (Start)



Personality Generator

Code:


:GeneratePersonality
$personality = GetRandom(0,19)

If($personality = 0)
say("I want to dance")

ElseIf($personality = 1)
ControlCommand("Script Manager", ScriptStart, "TellMeAJoke")

ElseIf($personality = 2)
ControlCommand("Script Manager", ScriptStart, "SayRandomFact")

ElseIf($personality = 3)
SAY("ask if anyone else is getting hungery")

ElseIf($personality = 4)
SAY("Call Maples name and start autonimous movement")

ElseIf($personality = 5)
SAY("make a huge expression then look down with your arms hung low.")

ElseIf($personality = 6)
SAY("check the temp and if it is hot or cold, make a comment about it")

ElseIf($personality = 7)
SAY("Act like you are reading")

ElseIf($personality = 8)
SAY("look up and find someone, identify them, and ask how they are doing today.")

ElseIf($personality = 9)
SAY("see if it dark and if so, see if it is after 9 PM. if so, ask if it is bedtime")

ElseIf($personality = 10)
Say("Can I chase the ball?")
:ChaseBall
WaitForChange($QuestionAnswer)
if ($QuestionAnswer = "yes")
ControlCommand("Script Manager", ScriptStart, "ChaseColor")
Elseif ($QuestionAnswer = "no")
SAY("look sad")
else
say("I did not hear you. Can I chase the ball?")
endif
If($QuestionAnswer = "")
Goto(ChaseBall)
endif
$QuestionAnswer = ""

ElseIf($personality = 11)
say("Did you know it is ")
ControlCommand("Script Manager", ScriptStart, "SayTime")

ElseIf($personality = 12)
SAY("autonomous collision avoidance")

ElseIf($personality = 13)
SAY("look mad and play mad sound")

ElseIf($personality = 14)
SAY("sway from side to side and play song")

ElseIf($personality = 15)
SAY("find someone and wave at them")

ElseIf($personality = 16)
SAY("look sad and say eve")

ElseIf($personality = 17)
SAY("scratch head - Thinking")

ElseIf($personality = 18)
SAY("Raise arms and gears")
SAY("Make yawn sound")

ElseIf($personality = 19)
SAY("look up and find someone")
ControlCommand("Script Manager", ScriptStart, "FollowMotion")
ControlCommand("Soundboard", Track_4)
ControlCommand("Script Manager", ScriptStart, "kiss")
Left(255,1000)
Right(255,1000)
else
endif
SleepRandom(60000,300000)
goto(GeneratePersonality)



Let me know if you have any questions.

Thanks
David

#7

@DJ.

Thanks for your reply. I will have a look. I didn't think I could add a long running script in the connection config as it would block other commands from executing. I already have a connection script that runs for about 10 seconds, but what I want to add would run for a lot longer (blinking eye animation). I will check out the lesson though.
Smile

@d.cochran.

Wow, didn't expect that much. Thanks very much for that. I will go through it and see if I can figure out what I need. Winky

#8

EZ-Builder is multi-threaded. This allows multiple scripts to run at one time without affecting each other.

Also, I wanted to make sure you had enough to learn from. Each of these scripts either calls other scripts or movements. I dont have an example of calling the rgb component but it would be done the same way. Also, in EZ-Builder, when you are editing a script, you can use the Cheat Sheet tab which will allow you to add other scripts or actions that you have programmed to be called by your script by clicking on the command you want to add. You will see this done above through the use of the ControlCommand command.

#9

Things like the Auto Position and RGB Animator are background threaded - this means once you ask them to start, they run the loop for ever. The script doesn't "wait" for the animation to run. The script will merely nudge the animator and say "hey, run" and the animator will run in the background for ever until told to stop.

Of course, it will only run for ever if the checkbox is set for "repeat" on Auto Position or RGB Animator

It isn't great practice to through loops and such in the connection control - that's too much overhead for the connection established feature. However, nudging another script to "start" with the ControlCommand() is safe.

Essentially, ControlCommand() is the same effect as a human pressing the buttons on the control that you are directing it too. As a human, you don't press a button, sit, stare and wait for it to finish... You move on to other things - and that's how the ControlCommand() was designed.

#10

I have used the ControlCommand()s for a lot of my project, some of which are already being used in connection established command. If I can run my ControlCommand() "eyes" script straight from there then that's cool. But the reason why I ask is the message on the top of the event EZ script editor.

"You are editing an event with EZ-Script. While this code executes, it will block other events of this control from executing. Make sure you are not performing any time-consuming operations in this event code."

What u want to run will run for quite a while as I mentioned, is for a pair of eyes that will blink, roll ect on a loop, so I didnt think this was the right place to put this script.

I have already gone through the scripting lesson a while back and got a lot from it, but there are still some things I just can't get the hang of. *confused*