Asked — Edited
Resolved Resolved by Redzone!

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?

Thanks!


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#17  

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") }

#18  

I worked it out: At the beginning of Init Script for Board 0 I have


if( $script0 != 3 )
  ControlCommand( "Connection", "Connect1" )
endif
#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.

#19  

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.

Alan

#20  

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
Sleep(250)
ControlCommand( "Connection", Connect0) #Connect Torso EZB Board-0
Sleep(250)
ControlCommand( "Connection", Connect1) #Connect Leg Section EZB Board-1
Sleep(250)
ControlCommand( "Connection", Connect2) #Connect Arm Section EZB Board-2
Sleep(250)
ControlCommand( "Connection", Connect3) #Connect Brain Section LoTiny EZB Board-3
Sleep(500)

#-------------------------------------------------------\
##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)

#-------------------------------------------------------
Sleep(50)

## Srart and Set servo Speeds 

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

#------------------------------------------------------

##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_ARS_Extended=0
$Both_Arms_Centered = 1
$Rt_Arm_Centered=1 
$Lft_Arm_Centered=1
Sleep(50)

#-----------------------------------------------------

##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
Sleep(1000)
uartWrite(2, 2, "1, start", 0x0d) #Start channel 1 on EZB 2 - Right ARS
Sleep(500)
uartWrite(2, 2, "2, start", 0x0d) #Start channel 2 on EZB 2 - Left ARS
Sleep(100)
uartWrite(2, 0, "1, start", 0x0d) #Start channel 1 on EZB 2 - Rt Elbow
Sleep(0500)
uartWrite(2, 0, "2, start", 0x0d) #Start channel 2 on EZB 2 - Left Elbow
Sleep(100)
uartWrite(1, 0, "1, start", 0x0d) #Start channel 1 on EZB 1 - Waist
Sleep(100)
uartWrite(1, 1, "2, start", 0x0d) #Start channel 2 on EZB 1 - Hips
Sleep(100)
uartWrite(0, 0, "1, start", 0x0d) #Start channel 1 on EZB 0 - Radar
Sleep(500)

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

#######################
#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")
Sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Home Hips") 
Sleep(500)
ControlCommand("Script Manager", ScriptStart, "Home Radar")
Sleep(50)
ControlCommand("Script Manager", ScriptStart, "Claws non-loop")
Sleep(750)
ControlCommand("Script Manager", ScriptStart, "Lft_Claw_Non_Loop")
Sleep(50)
PWMRandom(D0,40, 70)# Turn on Ear Motors, (Torso EZB Board-0)
Sleep(50)
Set(3.D6,on )#Turn on Fast Brain Lights(EZB Torso Board-0)
Sleep(100)
PWM(3.D5,20)# Turn on Crown Motor,(EZB Torso Board-0)
Sleep(3000)
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
Sleep(200)
uartWrite(2, 2, "2, Home", 0x0d) #Home Left ASR channel 2
Sleep(5000)
uartWrite(2, 2, "1, p0 s400", 0x0d) #Release tention on RT ARS drive train.
Sleep(200)
uartWrite(2, 2, "2, p0 s400", 0x0d) #Release tention on Left ARS drive train.

#---------------------------------------------------
Sleep(11000)

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

#-----------------------------------------------------------

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

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

Sleep(50)

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

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")
Sleep(0250)

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

Sleep(250)
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. :)

#21  

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.

Cheers

#22  

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!

#23  

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. :)

#24  

@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.