This tutorial will explain what an initialization script is and how to use them in your EZ-Builder projects. Initialization scripts, sometimes referred to as "Init" scripts are used to prime controls, devices, or existing scripts within your EZ-Builder projects, and sets them ready for use. Sometimes, you may see it referred to as a "Run Once" script. In the next few steps, I will go through how to set an "Init" script up, and go through some of the main uses for this function, that includes servos speeds and setting variables.
Step 1. Servo Speed Init, Part 1.
Some of you who are new to EZ-Builder and use servos with your robotic projects, may notice that if you have your servo speeds set to go slower speeds when your robot performs an action, after connecting you robots EZ-B to your EZ-Builder project and you move any of the servos connected, they will move at full speed the first time they move, then move at the speeds you have set them at. This is not a fault or an error, but simply this is the way most servos are designed.
Quote:Taken from the EZ-Script menu.
ServoSpeed (servoPort, speed)
Set the speed of servo or PWM. This is the speed to move between positions.
The servo speed is a number between 0 (fastest) and 10 (slowest).
*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.
Example: ServoSpeed(D14, 25)
Once power is supplied to the servo for the first time and the EZ-B starts to communicate with that servo, the servo does not know what it's speed is set at or its position to begin with. Depending on the design of you robot, be it a Revolution to out or one you have built yourself, this initial fast sudden movement could possibly cause damage to your robot, so what is needed is a way to slow these servos down when they are first moved. This is where an "Init" script comes in. This will initiate the servo speed and position, then prime the servos for the speeds you wish to set.
So how is this done? There are two ways to do this and I will explain both. In the script examples, 7 servos will be used.
[b]The first way. [b]
1.) Open up your EZ-Builder project on your computer, and click on the little gear icon next to your EZ-B's IP address on the "Connection control" and this will open up the script editor.
2.) In the script editor, write or copy/paste the following script...
NB: Any body of writing in the following, or any script, with a # in front of it, is just text for explanation purposes and can be removed or changed if necessary.
# This will clear the servo speeds for initialization.
# The following will move the servos into desired starting positions.
# The following will now set the servo speed for these servos which will be
#used from now on.
3.) Click on "Save" to save the script and close the script edition, the click "Save" again to close the "Connection Control", menu.
There is one thing to keep in mind when using this servo speed "Init" script for servo speed and position. I'll give you a working example...
Your robot has a servo controlled head and you have it set at "90" in your Init script. When you power off your EZ-B, maybe the head servo is facing at "180". When you power on and connect your EZ-B to the EZ Builder project again, that servo will still go at full speed to the position back to the "90" you have set up as in your "Init" script.
One way to combat this is to do a reverse "Init" script. By this I mean a kind of Off button in EZ Builder that would be pressed when you are finished with your robot. This could be an EZ-Script control, or a button on the mobile interface. This is where you would use the same servo speed and position "Init" script to move the servos to their starting position, so when you turn it on again, the servo don't move.