Controlling speed and acceleration of a servo motor.

Hello, newbie here.
I'm looking for help on starting this project.

Using rotary encoders:

Encoder 1-Sets the max speed (max PWM width?) to the motor. Like a governor.
Encoder 2-Set the amount of time it takes for the motor to reach max speed. Like a ramp effect of sorts.

How could I approach programming such functions using a Mega 2560, 5-6v continuous rotation servo motors, PCA 9685, and thumb rocker switch?

This would be under the assumption that all components work and are communicating with the Arduino.

Attached is a rough drawing of components and connections.

Thank you!



What's your code so far?

For a continuous servo the speed is set by the value you write to it. The only way you control acceleration to that speed is by writing successively larger values to it until you reach the maximum value.

You could have a look at the Sweep example in the IDE which does something similar. But that uses the standard servo library so you'll need to translate the commands into those used for the PCA9685.

Steve

Be aware that the electronics inside of a servo often make poor speed controls.
They are designed to provide positional control of the servo arm. When they are modified to be continuous rotation devices, the electronics do provide the ability to rotate the servo output shaft either direction and stop.
But the ability to control speed is iffy. Different brands and models of servo have different characteristics for speed control.
Some servos pretty much have 3 speeds; stop, full forward and full reverse.
Others have some speed control but the output speed is not linear with the input command.

This is the result when you use electronics designed for position control to handle speed.

Thanks for the feedback guys,

Would this be more viable with a stepper motor?
Just today I managed to get a hybrid stepper motor that was preforming this very task using a THB6128 driver. Of course this would mean I would have to source the driver and as well as find suitable libraries.

The end goal is a motor controller that can turn the zoom ring in a DSLR lens while being able to limit the amount of rotations (so it doesn't break the lens ring as zooms have a mechanical limit) and control the speed of those revolutions (so zooms can be super slow and super fast).

Robin2's simple stepper code tutorial may be of interest.

If you need high speed, acceleration will be necessary. The AccelStepper library does acceleration.

^ this!!!