Go Down

Topic: moving dc motor with help of optical encoder data (Read 1 time) previous topic - next topic


I have written the code for getting the encoder data and have used it to give me the number of counts (ticks) of encoder and an algorithm to give me both angle and velocity of the motor shaft.

So, this might seem to be a silly question, but how do i actually use this data to move the motor at a specific angle and  velocity? I mean when i rotate the motor shaft with my hand, i am getting the number of counts , angle and velocity of motor shaft on the serial monitor. so please help me with the code for how to move the motor at specific angle and at specific velocity

I am still a noob so please help me with the code. I am using an arduino mega. I have attached the code below.

I am using the following dc motor and driver :

Encoder dc motor : https://robokits.co.in/motors/encoder-dc-servo/planetary-encoder-geared-motor-24v-1000rpm-100w?zenid=5prh047gko82nboffq5ptpo870

motor driver : http://www.nex-robotics.com/products/motor-drivers/dc-motor-drivers/hercules-series-motor-drivers/hercules-6v-24v-16amp-motor-driver-with-built-in-current-sensor.html


Feb 11, 2018, 05:56 pm Last Edit: Feb 11, 2018, 05:57 pm by jremington
how do i actually use this data to move the motor at a specific angle
If you mean "position the motor shaft to a particular angle", then you would use PID calculations.

Since the encoder is relative, you must have some way of specifying the "home" or zero angle position. People often use a slotted disk attached to the shaft and an optointerrupter to define zero upon program startup. Your program then has to keep track of the current position.


That's a heavy motor. Unless you have some good brakes, it will continue rotating after you have reached your angle. If that's not an issue, just provide power to the motor, follow the encoder counter. When it reaches the count corresponding the desired angle, stop providing power.

For setting a speed, do the PID thing. If the PID thing is too difficult, try something simple. Measure speeds at different powers and loads and create a table. Set some start speed according to your table. Measure the real speed. Calculate how much off it is from the desired speed. Say +12%. Take 12% off the power and measure again. Now you have two measured speeds for two amounts of power. Interpolate or extrapolate to get a new estimation for right power for desired speed. Repeat the procedure with the two last measurements. In the best of worlds, this will lead to narrowing down towards the right power for the desired speed.

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Go Up