Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to program the Arduino to make the servo do variable speed movement?

Status
Not open for further replies.

Justinli

Member level 4
Member level 4
Joined
Apr 29, 2021
Messages
76
Helped
0
Reputation
0
Reaction score
2
Trophy points
8
Activity points
413
I bought an Arduino controller online and bought several bus servos to make a quadruped robot. I want to use Arduino to control the servo variable speed movement and can show it on the LCD display in real-time.
I found that the control program given by the store can only realize the uniform motion of the servo mode, and I would like to ask how to program the algorithm to realize the variable speed motion of the servo bionic.
 


Hi

Do an internet search:
"How to control a model servo"
Then
"Arduino PWM"
Then
"Arduino server control"

It's all done before, all documented, even libraries and videos are available.
May I ask what you did to find the information on your own?

Klaus
 

From what I read in the data sheet for that servo (https://github.com/microrobotics/DS3235-270/blob/master/DS3235-270_datasheet.pdf) the PWM sets the angle (which is rather common for this type of servo) but the only thing that changes the rotation speed is the supply voltage (item 3-2 in the reference document) and that not by much.
Susan
So I need to change the speed of the servo by changing the supply voltage?
Is it possible to achieve variable speed by using delay.( )?
--- Updated ---

Hi

Do an internet search:
"How to control a model servo"
Then
"Arduino PWM"
Then
"Arduino server control"

It's all done before, all documented, even libraries and videos are available.
May I ask what you did to find the information on your own?

Klaus
But Aussie Susan said PWM is not controlling speed but the angle, most of the examples I searched are uniform speed, I don't know much about servos yet, so I'm sorry if this makes you feel unpleasant.
 

No, it is a kind of stepper; depending on the PWM width it moves 90, 180 or 270 deg. Common steppers are 1.8 deg (200 pulses per turn)

Program to set pwm for 90 deg step. Then set the gap between the pulses to control speed.

The movement will be jerky but that is the way it works!
 

Obviously servo supply will affect the maximum speed. Variable speed will be achieved by varying the set point in a ramp instead of hard steps. It's a basic programming problem that hasn't much to do with the specific servo type.
--- Updated ---

No, it is a kind of stepper; depending on the PWM width it moves 90, 180 or 270 deg. Common steppers are 1.8 deg (200 pulses per turn)
No stepper. A DC motor with position feedback and controller.
 

No stepper. A DC motor with position feedback and controller.

It runs on pulses, not DC. The motor has two wires, it is not a typical servo.

The datasheet calls it a servo but it does not report the position, much like a stepper.

The dead time is 2 us and it should be able to move fast. Max freq specified is 50-330 Hz; not great.

More similar to clock motors; but they call it "coreless digital servo", whatever that may mean...
 

Hi,

it is a standard servo for model cars. .. as far as I can see. Nothing special.
It has DC input and a PWM control line (3 wires in total) to control the angle.

Inside:
There is
* a DC motor (usually)
* a position feedback pot
* and a control electronic.
The electronic is a regulation loop. The setpoint is given by the PWM, the actual position by the pot and the electronics controls the motor in a way that it moves the servo mechanics to the desired position.

Klaus
 

Hi,

it is a standard servo for model cars. .. as far as I can see. Nothing special.
It has DC input and a PWM control line (3 wires in total) to control the angle.

Inside:
There is
* a DC motor (usually)
* a position feedback pot
* and a control electronic.
The electronic is a regulation loop. The setpoint is given by the PWM, the actual position by the pot and the electronics controls the motor in a way that it moves the servo mechanics to the desired position.

Klaus
Yes but my problem is that I want it to be able to do variable speed motion, not the angle.
If you know of some suitable examples please also write links in your reply, thank you very much!
--- Updated ---

No, it is a kind of stepper; depending on the PWM width it moves 90, 180 or 270 deg. Common steppers are 1.8 deg (200 pulses per turn)

Program to set pwm for 90 deg step. Then set the gap between the pulses to control speed.

The movement will be jerky but that is the way it works!
Do I need to follow your approach to programming? Do you have some programming examples of this?
 

Do I need to follow your approach to programming? Do you have some programming examples of this?
Simplest approach will be to take an existing working code and insert suitable delays in the PWM pulse train. The delay function commonly used in arduino standard library is interrupt inefficient (my knowledge is rusted) but you can insert in the pwm code very easily.

Why reinvent the wheel because it will add to debugging time and effort and nothing new to knowledge. The thin wire is connected to PWM??
--- Updated ---

The electronic is a regulation loop. The setpoint is given by the PWM, the actual position by the pot and the electronics controls the motor in a way that it moves the servo mechanics to the desired position.

Klaus
I see. Thanks for the clarification.
--- Updated ---

Yes but my problem is that I want it to be able to do variable speed motion, not the angle.
If you know of some suitable examples please also write links in your reply, thank you very much!
--- Updated ---


Do I need to follow your approach to programming? Do you have some programming examples of this?
You can get some hint at https://www.arduino.cc/en/pmwiki.php?n=Tutorial/SecretsOfArduinoPWM

First see that the overall frequency is within the specified limit: i.e., 50-330 Hz (this will be the PWM frequency output by arduino)

Select step size of the servo: 0.5 us, 1 us or 2 us (this will be the on time for the square pulse; look up the proper register for this.

You get a range of 6 fold (50-330Hz) speed range and 2 fold (90deg or 180deg per pulse)- total 12 fold speed

You can try values outside these range too.

By the way, the angle is like phase; 90 deg step per pulse means 1/4 turn and so on. Total RPM depends on the frequency * (1/4 for 90deg pulse or 1/2 for 180 deg pulse)
 
Last edited:

Select step size of the servo: 0.5 us, 1 us or 2 us (this will be the on time for the square pulse; look up the proper register for this.
You get a range of 6 fold (50-330Hz) speed range and 2 fold (90deg or 180deg per pulse)- total 12 fold speed
You can try values outside these range too.
You seem still to misunderstand the servo operation principle. The position of the servo is continuously controlled by a pulse width of 0.5 to 2.5 ms. In practice, the resolution is limited by the Arduino pwm register width as well as by the decoder inside a digital servo. As the datasheet tells, there's a 2 µs (1/1000 of total set point range) dead band, respectively the angle resolution is about 0.3 degree.
 

You seem still to misunderstand the servo operation principle. The position of the servo is continuously controlled by a pulse width of 0.5 to 2.5 ms. In practice, the resolution is limited by the Arduino pwm register width as well as by the decoder inside a digital servo. As the datasheet tells, there's a 2 µs (1/1000 of total set point range) dead band, respectively the angle resolution is about 0.3 degree.
It is entirely possible that I have misunderstood some points. If the servo cannot rotate full 360 deg (one complete turn), it may be only good for setting angles.

But the datasheet says that it can rotate in one direction (CCW) only. That may mean that the internal potentiometer is a 360 deg encoder.

May be it cannot move full 360 deg and I am wrong in that case.

Thanks for setting me on the right way
 

Hi.

Why servos in a quadcopter?
What are they used for?

Klaus
I'd like to take a servo motor simulation first, I guess maybe they are very similar, as long as the replacement small servo can operate that formal robot can also operate in this way. But I could be wrong and I might need more help from you.
--- Updated ---

You seem still to misunderstand the servo operation principle. The position of the servo is continuously controlled by a pulse width of 0.5 to 2.5 ms. In practice, the resolution is limited by the Arduino pwm register width as well as by the decoder inside a digital servo. As the datasheet tells, there's a 2 µs (1/1000 of total set point range) dead band, respectively the angle resolution is about 0.3 degree.
Thanks for your patient explanation, I don't know much about servo, maybe I need more help from you.
 
Last edited:

I'd like to take a servo motor simulation first, I guess maybe they are very similar, as long as the replacement small servo can operate that formal robot can also operate in this way. But I could be wrong and I might need more help from you.
A servo motor simulation .... only you know what this means.
They are very similar .... to what?
As long as the replacement servo ... I have no idea
that formal robot can also operate in this way ... what robot? Which way?

But I could be wrong and I might need more help from you. .... Without clear information I can't help.

I have no idea what you want to achieve.

Klaus
 

It is entirely possible that I have misunderstood some points. If the servo cannot rotate full 360 deg (one complete turn), it may be only good for setting angles.

But the datasheet says that it can rotate in one direction (CCW) only. That may mean that the internal potentiometer is a 360 deg encoder.

May be it cannot move full 360 deg and I am wrong in that case.

Thanks for setting me on the right way
Thanks for your enthusiastic reply too, maybe I need to learn a bit about how the servo works from the basics.
 

maybe I need to learn a bit about how the servo works from the basics.
I have internet. I can do internet search, like "how does a model servo work video". Thousands of hits.

May I ask why you don't do this on your own?

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top