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
Asked — Edited
Resolved Resolved by merne!

Scripting A Connection To A Second Ezbv4

Upon manually connecting to Board 0, I would like to establish a connection to Board 1 using EZ-Script, process some initialization there (ie: 1.D0 do thus and such) Can I and if yes, how do I connect to Board 1 from script?


AI Support Bot
Related Content
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
First, use the [ code ] formatters if you wish to display code

second, use the SayEZBWait() command if you want to wait for it to speak.


#Board 0 Script:
SayEZBWait("Initializing Board Zero")

ControlCommand( "Connection", "Connect1" )

# do some other stuff

The EZ-Script manual is along the right when editing scripts. Here's a screenshot

User-inserted image

When you see something BLUE in someones reply, you can click on it. For example the Cheat Sheet is in blue. Click on it so you can read about it. Also, ControlCommand is in blue, click on it so you can read about it.
Here is the InitScript running on Board 1
(ps Thank you for your help with this!)


SayEZB("Initializing Board One")
UARTInit( 1, 2, 9600 )
Sleep( 3000 )
SayEZB("Initializing Head and Neck Servos")
#Head Vert
Servo( 1.D0,125 )
ServoSpeed( 1.D0,1 )
SetServoMin( 1.D0,30 )
SetServoMax( 1.D0,165 )
#Head Rot
Servo( 1.D1,125 )
ServoSpeed( 1.D1,1 )
SetServoMin( 1.D1,20 )
SetServoMax( 1.D1,180 )
#Head Side
Servo( 1.D2,145 )
ServoSpeed( 1.D2,1 )
SetServoMin( 1.D2,30 )
SetServoMax( 1.D2,180 )
Servo( 1.D3,105 )
ServoSpeed( 1.D3,1 )
SetServoMin( 1.D3,105 )
SetServoMax( 1.D3,160 )
Servo( 1.D4,95 )
ServoSpeed( 1.D4,1 )
SetServoMin( 1.D4,70 )
SetServoMax( 1.D4,125 )
Servo( 1.D5,105 )
ServoSpeed( 1.D5,1 )
SetServoMin( 1.D5,60 )
SetServoMax( 1.D5,130 )

#Head Vertical Movement
SayEZB("Looking Down")
Servo( 1.D0,30 )
Sleep( 2000 )
SayEZB("Looking Up")
Servo( 1.D0,165 )
Sleep( 2000 )
SayEZB("Looking Ahead")
Servo( 1.D0,125 )
Sleep( 2000 )

#Head Rotation
SayEZB("Looking Left")
Servo( 1.D1,20 )
Sleep( 2000 )
SayEZB("Looking Right")
Servo( 1.D1,180 )
Sleep( 2000 )
SayEZB("Looking Ahead")
Servo( 1.D1,110 )
Sleep( 2000 )

#Head Sidebending
SayEZB("Sidebending Left")
Servo( 1.D2,180 )
Sleep( 2000 )
SayEZB("Sidebending Right")
Servo( 1.D2,30 )
Sleep( 2000 )
SayEZB("Looking Ahead")
Servo( 1.D2,130 )
Sleep( 2000 )

#Jaw Open Close
SayEZB("Opening Mouth")
Servo( 1.D3,160 )
Sleep( 2000 )
Sleep( 2000 )
SayEZB("Closing Mouth")
Servo( 1.D3,105 )
Sleep( 2000 )

#Eyes Look Up and Down
SayEZB("Eyes Looking Up")
Servo( 1.D4,125 )
Sleep( 2000 )
SayEZB("Eyes Looking Down")
Servo( 1.D4,70 )
Sleep( 2000 )
SayEZB("Eyes Looking Ahead")
Servo( 1.D4,95 )
Sleep( 2000 )

#Eyes Look Left and Right
SayEZB("Eyes Looking Left")
Servo( 1.D5,130 )
Sleep( 2000 )
SayEZB("Eyes Looking Right")
Servo( 1.D5,60 )
Sleep( 2000 )
SayEZB("Eyes Looking Ahead")
Servo( 1.D5,105 )
Sleep( 2000 )

SayEZB("Completed Initialization, Testing Neo Pixel")
SendSerial( 1.D18, 9600, "W250,0,0,250,0,0")
Sleep( 2000 )
SendSerial( 1.D18, 9600, "C0,0,0")
Sleep( 2000 )
SendSerial( 1.D18, 9600, "S250,0,0,250,0,0")

#END of Board 1 Script - should pass control back to Board 0 calling script...
I edited your post and put [ code ] [/ code ] tags around the code so people can read it
@DJ Thanks DJ, am using my phone to replay it's harder to reply using just my phone.

@mayaway, us the SayEZBWait() command Like DJ said.

At a quick look you script looks ok, nice init script too.
Thank you both:

"First, use the [ code ] formatters if you wish to display code"
I am not quite sure what this means or how to do it, though I think there must be a way to indicate that a block of my post is code - so I'll see if I can figure out how to do that...

"second, use the SayEZBWait() command if you want to wait for it to speak."
This sounds good because it may solve my problem, and you are also simply 'giving me a fish' and I want to learn HOW to fish... So I'll go lookup this command and maybe it will explain WHY I should use it...



Code goes in between

If you scroll to the bottom of your reply you'll see a list of many of these commands use for new when replying.
aha! Thanks! Got it... There's a learning curve here...
OK - Problem is NOT SOLVED

SayEZBWait("some text") is explicitly for completing the text to speech before moving on. Good tip but not the solution for my problem, which is:

1. I manually start Board 0 by clicking [Connect] in the Connection Control
2. My Init Script begins to execute:


SayEZBWait("Intializing Board Zero")
Sleep ( 2000 )
ControlCommand( "Connection", "Connect1" )

3. At which point the Init Script for Board 1 executes perfectly, but FAILS to Return control to the calling Init Script for Board 0
Would the command


at the end of the Init Script for Board 1 solve this?
The init script is runs once to set your parameters if that is the correct word.

You might want to post your full init script so we can see exactly what you're trying to do thanks.
I think I understand what you're saying now. Are you using 2 init scripts or the same one?
If I am understanding what you are trying to do, the issue is that ARC is multi-threaded. multiple scripts can run simultaneously, so when you issue a command that starts a new script, the original one continues to process. What I think you are asking to do is pause the board 0 init script until board one completes its initialization.

There are probably multiple ways to do this, and I may be missing a simpler way, but one way you can do this is in your board 0 init script, initialize a variable. example


$script0 = 1

then, after the ControlCommand() that starts board 1, you use waitforchange command to look for the value of $script0 to change


ControlCommand("Connection", Connect1)
WaitForChange( $script0 )

this will pause the script until the value of the variable changes.

Now, in your second script, after it has done all of its activity, the last command in the init script for board 1 would change the value of the variable, which triggers the waitforchange to take action and continue the script for board 0.


$script0 = 0

I understand the logic, and tested it's implementation, but it also failed. This leads me to believe that control is never passed back to the InitScript for Board 0. Perhaps I need to call a regular script from the Board 0 Init Script and have that script connect Board 1, wait for the change... Any ideas why control won't pass back to the first script? If vars are GLOBAL then perhaps I can do a ControlCommand("Connection","Connect0") at the end of the script for Board 1, and use if($script!=0) { ControlCommand("Connection","Connect1") }
I worked it out:
At the beginning of Init Script for Board 0 I have


if( $script0 != 3 )
ControlCommand( "Connection", "Connect1" )
#followed by my Board 0 init routines

and at the end of the Init Script for Board 1 I have


$script0 = 3 # using 0 didn't work - perhaps it is synonymous with false, or the value if the var is not yet set...
ControlCommand( "Connection", "Disconnect0" ) #since it was already connected
Sleep( 1000 )
ControlCommand( "Connection", "Connect0" )

whereupon the Board 0 Init Script executes and skips the initialization of board 1 which has already been done.
Sorry about the slight wild goose chase. Didn't realize that setting to 0 would not work. I usually do this kind of thing using text variables ("yes/no" "right/left"). Big thought it would be easier to explain using integers, but didn't actually test before posting (again, since I have had success with similar scripting).

Glad you got it working.

I'm currently running 4 EZB's in my robot with lots of scripts running and devices attached to all 4 EZB's. I found that you should be starting all your EZB's and oher devices along with setting all your perimeters in only one INT script. Start all your EZB's first near the top of your "only" INT script. Start and set things like all EZB's, servo min, max, speeds and poisons in this one INT script. Also set most all global variables in this one int script. EZ Script "steps" through your commands one line at a time. Once everything is setup and ready to run in this script only then should you start calling other scripts from this INT script (Multi-Threading) to move or run devices and motors. Watch what is running at any given time. If you try to call the same device or motor to run at the same time or before it's done with what is is doing, something you expect to happen will not work or even lock up or disconnect the EZB.

Also make sure to place Sleep() commands where needed to give devices time to move into place or finish their function. The script will fly by time sensitive commands without letting them complete. If something is not working look at this as a possible issue.

One more tip; If you try to send an improper command through any of the UART ports the EZB will disconnect. You'll also lock up an EZB if you try to send a command through these UART ports before you initialize the one you want to use. If used, Uarts should also be initialized in your "only" INT script. You only need to do this once per EZB boot up.

I'm no shining example of an EZ script code writer but below is my INT script that will explain what I'm talking about:


##Make sure Personality Gen & Speech Recognition are Paused.
##They will be turned back on at end of this script.
ControlCommand("Personality Generator", PauseOn)
ControlCommand("Speech Recognition", PauseOn)

##Connect all 4 EZBs
ControlCommand( "Connection", Connect0) #Connect Torso EZB Board-0
ControlCommand( "Connection", Connect1) #Connect Leg Section EZB Board-1
ControlCommand( "Connection", Connect2) #Connect Arm Section EZB Board-2
ControlCommand( "Connection", Connect3) #Connect Brain Section LoTiny EZB Board-3

##Specify the ranges for the servos
##this prevents the servos from ever going past these limits

# Rt side_to_side Wrist
SetServoMin(2.D0, 120)
SetServoMax(2.D0, 165)

# Rt Up_Dn Wrist Servo
SetServoMin(2.D1, 20)
SetServoMax(2.D1, 170)

# Right Claw
SetServoMin(2.D3, 77)
SetServoMax(2.D3, 99)

# Left Up_Dn Wrist Servo
SetServoMin(2.D4, 14)
SetServoMax(2.D4, 180)

# Left side_to_side Wrist
SetServoMin(2.D5, 82)
SetServoMax(2.D5, 138)

# Left Claw
SetServoMin(2.D6, 68)
SetServoMax(2.D6, 90)

# Bubble Blocks
SetServoMin(D15, 85)
SetServoMax(D15, 177)

# Bubble Servo
SetServoMin(D1, 45)
SetServoMax(D1, 97)


## Srart and Set servo Speeds

ServoSpeed(D1,20) # Bubble Lifter Servo
Set(D10, On) #Bubble 0n servo Power after move command to keep from jumping.


##State all specifed Varibles

#$adcKilSpecified = 150 #Value for Kill Power Pack Pull Switch(Now done with ADC_Wait command)
#$adcAlvSpecified = 170 #Value for Alive Power Pack Pull Switch(Now done with ADC_Wait command)
$adcSoilSpecified = 200 #Value for Soil Sampler ACD Port
$adcpersonalitySpecified= 220 #Value for Gamma 101 Chest Button ADC Port
$adcVoiceSpecified= 230 #Value for 202 Phase Chest Button ADC Port
$Speech=0 #Sets Speech Variable to show unpaused (Runnung)
$Personality=0 #Sets Personality Variable to show unpaused (Running)
$Rt_ARS_Extended=0 #Sets Rt ArS Carrage in or out Variable 0=in, 1=out
$Lft_ARS_Extended=0 #Sets Left ARS Carrage in or out Variable 0=in, 1=out
$ADC_Lft_Elbow = 0 #Sets ADC variable reading Rt Elbow opto switch to "not centered so script will run"
$ADC_Rt_Elbow = 0 #Sets ADC variable reading Rt Elbow opto switch to "not centered so script will run"
$Rt_Elbow_Center = 2470
$Rt_Elbow_Speed = 800
$Lft_Elbow_Center = 2490
$Lft_Elbow_Speed = 800
$Rt_Carrage_Position = 0
$Lft_Carrage_Position = 0
$Both_Arms_Centered = 1


##Start and Home devices and anamate startup. Also
##Initialize the Peripheral UARTs on all the EZ-B v4 with
##the specified baud rate.

UARTInit(0, 0, 9600 ) #Turn on EZB 0 Uart #0 port - Radar
UARTInit(1, 0, 9600 ) #Turn on EZB 1 Uart #0 port - Waist
UARTInit(1, 1, 9600 ) #Turn on EZB 1 Uart #1 port - Hip
UARTInit(2, 0, 9600) #Turn on EZB 2 Uart #0 port - Elbow's
UARTInit(2, 2, 9600 ) #Turn on EZB 2 Uart #2 port - ARS's
uartWrite(2, 2, "1, start", 0x0d) #Start channel 1 on EZB 2 - Right ARS
uartWrite(2, 2, "2, start", 0x0d) #Start channel 2 on EZB 2 - Left ARS
uartWrite(2, 0, "1, start", 0x0d) #Start channel 1 on EZB 2 - Rt Elbow
uartWrite(2, 0, "2, start", 0x0d) #Start channel 2 on EZB 2 - Left Elbow
uartWrite(1, 0, "1, start", 0x0d) #Start channel 1 on EZB 1 - Waist
uartWrite(1, 1, "2, start", 0x0d) #Start channel 2 on EZB 1 - Hips
uartWrite(0, 0, "1, start", 0x0d) #Start channel 1 on EZB 0 - Radar

ControlCommand("Auto Both Arms", AutoPositionFrameJump, "Center_Both_Arms")
#ControlCommand("Auto Both Arms", AutoPositionAction, "Center Both Arms")
#uartWrite(2, 0, "1,P"+$Rt_Elbow_Center, "s100", 0x0d) #Move Rt Elbow Motor
#uartWrite(2, 0, "2,P"+$lFt_Elbow_Center, "s100", 0x0d) #Move Lft Elbow Motor

#Halt() #Unmark here to stop script here for basic startup for debugging.

#Now that everything is setup the following will Home waist motor and then leave it in the center postion.
ControlCommand("Script Manager", ScriptStart, "Home Waist")
ControlCommand("Script Manager", ScriptStart, "Home Hips")
ControlCommand("Script Manager", ScriptStart, "Home Radar")
ControlCommand("Script Manager", ScriptStart, "Claws non-loop")
ControlCommand("Script Manager", ScriptStart, "Lft_Claw_Non_Loop")
PWMRandom(D0,40, 70)# Turn on Ear Motors, (Torso EZB Board-0)
Set(3.D6,on )#Turn on Fast Brain Lights(EZB Torso Board-0)
PWM(3.D5,20)# Turn on Crown Motor,(EZB Torso Board-0)
ControlCommand("Head Section", ScriptStart, "Radar Sweep")

#Following will Home both arms ARS and leave arm parked in rear postion.
uartWrite(2, 2, "1, Home", 0x0d) #Home Rt ASR channel 1
uartWrite(2, 2, "2, Home", 0x0d) #Home Left ASR channel 2
uartWrite(2, 2, "1, p0 s400", 0x0d) #Release tention on RT ARS drive train.
uartWrite(2, 2, "2, p0 s400", 0x0d) #Release tention on Left ARS drive train.


# Start Bubble Up and Down Script
ControlCommand("Head Section", ScriptStart, "Happy, Sad Bubble")
ControlCommand("Head Section", ScriptStart, "Radar 1/4 Sweep")


##Start turning off anamation and put B9 into standby and ready
PWM(D0,0)#Turn off Ear Motors (Torso EZB Board-0)

ControlCommand("Soundboard v4", Track_20) #Play "Active" Voice Track


Release( 2.D3 ) #Release Rt Claws
Release( 2.D6 ) #Release Lft Claws
Release(2.D4) #Release Lft wrist Up & Down Servo
Release( 2.D5 ) #Release Lft Side to side servo
Release(2.D1) #Release Rt Wrist Up & Down Servo
Release( 2.D0 ) #Release Rt Side to side servo
#uartWrite(2, 0, "1, Powerdown", 0x0d) #Powerdown Rt Elbow Motor
##uartWrite(2, 0, "2, Powerdown", 0x0d) #Powerdown left Elbow Motor
uartWrite(2, 2, "1, Powerdown", 0x0d) #Powerdown Rt ARS Carrage motor
uartWrite(2, 2, "2, Powerdown", 0x0d) #Powerdown left ARS Carrage motor

Set(3.D6,off) #Turn off Fast Brain Lights

PWM(3.D5,0) #Turn off Crown Motor

# Start Power Pack Pull script
# (Triggered when Power Pack is pulled)
ControlCommand("Script Manager", ScriptStart, "Power Pack Pull")

# Start Chest Button Scripts. Makes chest buttons operational
ControlCommand("Script Manager", ScriptStart, "Victor Hold Soil Sampler")
ControlCommand("Script Manager", ScriptStart, "Gamma 101 Personality")
ControlCommand("Script Manager", ScriptStart, "Gamma 202 Voice")

ControlCommand("Personality Generator", PauseOff)
ControlCommand("Speech Recognition", PauseOff)

One last tip. In the future try not to be so quick to mark a help thread resolved until your sure your problem is actually fixed. You run the rick of not getting the help you really need. There are lots of people here willing to lend a hand. :)
Thanks Dave, these are great tips for mayaway and others. I too was wondering if mayaway had more than one init script. And you're right about not marking solution solved until it's fully solved.

Hey thanks guys! These are very helpful tips. I'll consolidate to one Init. I think @DJ said with SendSerial() you don't need the UARTinit. It's probably two dif. ways of doing the same thing. I think I also saw that the ServoSpeed() command needs to be preceded by a Servo() position command. Maybe it used to be... maybe it still is!
No problem Merne. I also had to work through these same issues when I started using more the one EZB. One of the hardest things for me to wrap my mind around was the concepts of multi-threading scripts and how they interact with each other. I still find this challenging at times when complex things are going on. I hope I helped in some way.

After reading through the OP's posts in this thread it sure sounds like he was trying to use separate scripts to start up and set up each EZB. Then run start up routines for devices attached to it's EZB that it's starting. :)
@mayaway, That's not correct. You always need to start a UART port (Need to do this only once) before you use it. Use the UARTinit() command for the port your going to use in your INT script. If you send a command through the UART port without starting it first you will lock up your EZB.

EDIT: Actually if your sending a Sendserial command through a digital port then your are correct. You dont need to use a UARTinit() command. Only use the UARTinit() command if you're sending through a UART port.

Servo Speed commands are hard to understand (for me at least). Here's a few notes from the Script help section in ARC:


*Note: To initialize the ServoSpeed() at first use, set a Servo() position before using the ServoSpeed() command. If there is no previous position (such as during power-on), the software assumes the position is 0 and will cause issues with your robot.
*Note: Once the ServoSpeed() has been initialized the first time, specify the ServoSpeed() before specifying the Servo() position.


I think I also saw that the ServoSpeed() command needs to be preceded by a Servo() position command

That's correct... before you set servo speed you need to set an initial servo position so....