Setting Servo speeds and Initialization Script Tutorial

Description

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.

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.

User-inserted image

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.

ServoSpeed(D1, 0)
ServoSpeed(D2, 0)
ServoSpeed(D3, 0)
ServoSpeed(D4, 0)
ServoSpeed(D5, 0)
ServoSpeed(D6, 0)
ServoSpeed(D7, 0)

# The following will move the servos into desired starting positions.

Servo(D1, 90)
Servo(D2, 40)
Servo(D3, 90)
Servo(D4, 90)
Servo(D5, 38)
Servo(D6, 82)
Servo(D7, 40)

# The following will now set the servo speed for these servos which will be 
#used from now on.

ServoSpeed(D1, 2)
ServoSpeed(D2, 3)
ServoSpeed(D3, 1)
ServoSpeed(D4, 2)
ServoSpeed(D5, 1)
ServoSpeed(D6, 3)
ServoSpeed(D7, 2)

3.) Click on "Save" to save the script and close the script edition, the click "Save" again to close the "Connection Control", menu.

User-inserted image

User-inserted image

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.


ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

#1  

What I have found is that when I set to 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 into startup position. I also found that if I insert ServoSpeed(D3, 4) in the line before Servo(D3, 90) it moves slowly to startup position. The tutorial says not to set final speed until after setting position or you will have a problem. What am I missing?

#2  

Sorry for the last comment.  It was sent by accident.

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?

PRO
Synthiam
#3   — Edited

I believe what the tutorial is trying to convey is initialization of a servo position. That means the very first time a servo is moved or set into position

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

#4  

Is there a problem with adding ServoSpeed(D3. 4) code in the line before Servo(D3. 90) line .

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.

PRO
Synthiam
#5  

I’m surprised that works, but if it does then yeah go for it. Really if anything does work, keep doing it:)  as the phrase goes, don’t fix it if it ain’t broke

PRO
USA
#6  

Quote:

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
I want to revisit this on my robot heads. They could uses an init, that could read head positions from the dynamixels, then move them to a beginning state. Not sure how I missed this use case!

#7  

Quote:

I’m surprised that works, but if it does then yeah go for it. Really if anything does work, keep doing it:) as the phrase goes, don’t fix it if it ain’t broke
Yeah, I thought servo speed only worked after an initial servo movement.  Never fully understood why, but just dealt with it.  The new HD servos make it easy because they pretty much hold their last position when shut down.  On robots without HD servos, I have a "safe" position I try to remember to go to before shutting down as long as I get to it before the battery dies.

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.

Alan