Encoders - Arduino C programming


#1

Hi Everyone

Your experience, knowledge & advice is desperately sought. Which (in your opinion) is the best coding method to use to set the speed of encoder motors?

setMotorPwm ? or setTarPWM ?

They both seem to work OK in simple coding experiments, but which one is best - & why? - & is one method better than the other in different scenarios? Can anyone clearly explain the difference between them for me please?

In anticipation,

many thanks

Lindsay


#2

tech_support - any thoughts on this?


#3

Hi @CommandeR

If you have a look at MeEncoderOnBoard.cpp you’ll see that setMotorPWM() sets the PWM immediately, whereas setTarPWM() sets a target, and each call round loop() increased the PWM towards the target (whilst reading the current speed and position) so takes longer to reach the target and thus smoother acceleration, plus the opportunity to do other processing before the motors get to the selected speed (e.g. accelerate up to 250, but watch out for obstacles, or get some new speed input from a controller…)

That’s my take on it, others might have other ideas.

You could also look at runSpeed() which uses PID.

Some examples (for Auriga/Ranger) can be found in my document here: https://docs.google.com/document/d/1EpMWJo9pP2J_pstzXA-XHK8t00Z70SCZYwZ_Kl7VLuw/


#4

Hi Murray

Thanks for your kind response. This was just the information I was looking for. I read & absorbed (mostly) the concepts in your excellent and very useful document several months ago.

Lindsay


#5

Hi Lindsay

Thanks for the kind words. I was never quite sure of the difference myself and your question made me go look in more detail. I’ve added this information into the document now for future readers.

I just wish makeblock library developers had released any documentation for their code! I’m gradually unpicking it


#6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.