Setting Servo speeds and Initialization Script Tutorial
This tutorial will explain what an initialization script is and how to use them in your ARC projects. Initialization scripts, sometimes referred to as "Init" scripts are used to prime controls, devices, or existing scripts within your ARC 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.
Related Robot Skills
Step 1. Servo Speed Init, Part 1.
Some of you who are new to ARC 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 ARC 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.
The first way. [b]
[b]1.) Open up your ARC 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.
Code:# 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.
Upgrade to ARC Pro
Your robot can be more than a simple automated machine with the power of ARC Pro!
I tried to submit it in the tutorial but I got an error message and could't send it.
The tutorial I was reading is above "Setting servo speeds and Initialization Script Tutorial"
I am sending the information here so I don't need another thread.
I am having problems with my initiation script. I have found that when I set ServoSpeed(D3, 0) , and then add position Servo(D3, 90) and finally ServoSpeed(D3, 4), servo D3 runs as fast as it can to get to position given by Servo(D3, 90) startup position. I also found that if I insert ServoSpeed(D3, 4) in the line before Servo(D3, 90) it moves the correct slow speed to Servo(D3, 90) position.
The tutorial says not to set final speed until after setting position or you will have a problem. What am I missing?
a servo doesn’t have a position when power is applied. There’s no way to slowly transition to the initialization position because there is no previous position. so, you must set a position first, which initializes the servo and then set the speed. Once the speed is set, it’ll always have that speed for moving until speed is specified again.
The first initialization of servos will always move quick as they can to the specified position. It’s annoying, but it’s how servos work.
Now, if you’re hardcore and want to get around that issue. You can look up my hack on adding adc position monitoring. That way, you can know the position the servo is in and initialize at that position. Then, set the speed. There would not be any jumping if you did that
heres the plugin which has the video and details: https://synthiam.com/Products/Manual/PWM-Servo-Feedback-ADC-18047
If I do this, it doesn’t jerk into D3 position. D3 controls up and down movement of the head of the robot. Without the control the heavy robot head slams int position D3. I am afraid over time I will damage the servo and robot body. This is a five foot Robot called max. He weighs about 70 lbs. t will soon post a picture.
If it is working now, great, just be sure you are testing after first power up and not just running the script after you have already moved the servos before trusting it.