Rotary encoder 'virtual spring'

Thread Starter

daxliniere

Joined Aug 7, 2021
52
I picked up a really nice quadrature optical rotary encoder without detents and I have a project I want to use it on.

The project is a controller for a DC motor and I want 2 modes. Mode 1 where rotating the encoder increases and decreases the speed. This is straight forward.
Mode 2 is trickier and acts a bit like a jog command. Turning the encoder slowly will advance the motor slowly for a short time, turning it fast will advance the motor quicky, but also for a short time. It's like by turning the encoder you are fighting against gravity/friction.

The idea I had for Mode 2 was to implement a virtual 'spring' which effectively fights against you by reducing the speed value (that you increased by turning the encoder), always returning it to zero.
I thought this 'force' could be simulated with time using the **millis** command, but I have no idea how to go about it. Or even if there is a rotary encoder library that already offers this functionality.

Any help would be greatly appreciated.

Thanks in advance,
Dax Liniere
 

ericgibbs

Joined Jan 29, 2010
19,017
hi dax,
Consider this option for Mode #2.
Push button, capture the Encoder steps and the Time period while the button is pressed.
On the release of the button, drive the motor with the stored simulated step count, for the stored Time period.

E
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
Hey @ericgibbs, thanks for the suggestion, but unfortunately I wouldn't be able to see how far it's going to move. I basically want to make the rotary encoder operate like a single-axis joystick that always returns to centre position (zero speed), but with much greater precision.
 

Gorbag

Joined Aug 29, 2020
13
Why not look at the acceleration of the encoder and then apply a negative acceleration against it? Use that factor to control the motor's acceleration.

Best,
 
Top