I am using 2 driving motors in my line follower and an L298N motor controller to control them.
At the same PWM signal given to drive both motors one motor runs faster, hence preventing the bot from going straight.
I checked the voltages at all the pins also the PWM i/p to the controller is same but the Voltage output for the two motors is different.
This voltage is proportional to the PWM for both the motors but they have an offset
At full speed(255) the bot goes straight, i.e same voltage is given by the controller.
I am using Arduino Nano
12V power supply(Lead Acid)
12V motors(200RPM)
Not all motors are made equal.
Swap the motors on the bot, and see it it wonders off in a different direction.
You could map PWM value of one motor to a lower value.
Leo..
harshit3096g:
I checked the voltages at all the pins also the PWM i/p to the controller is same but the Voltage output for the two motors is different.
wawa is right. The two motors are the same model, but they will have physical differences, just like twin people will have physical differences.
One first-attempt fix to improve the situation is to add suitable 'offset' values to one or both motors.
The offsets for each motor (that you manually add in software) will usually be different values. The offset values can do 2 things for you. One thing is that they can alleviate dead-band issue....where the motor just doesn't move when not enough voltage is applied to it. So adding some kind of extra voltage (in advance) can often at least reduce this dead-band or dead-zone effect.
The other thing that the different offsets can do for you is to even-up the motor behaviours. So, after a lot of experimenting and tinkering ...... you may manage to find suitable offset values for each motor..... so that both motors can behave similarly for the an overall control input value.
In the above..... the input_value is an overall value you want to drive the motors with. And the offsets are automatically (and conveniently) added by your software. So at the end.... you can drive the motors (with offsets added) using PWM_A and PWM_B levels.
And later, if you want to take things further, and if you have them....... there are wheel encoders (like quadrature encoders) that allow you to measure angular velocity, or wheel speed. This can allow you to have more information about each wheel during operation. And the wheel velocity information could be used to equalise wheel speeds (when a suitable control algorithm is used).
OP states that when using a PWM of 255 (which translates to digitalWrite(somePin, HIGH) in the code of analogWrite) for both motors, the robot goes straight.
What I like to know is why it will not go straight at other values? I can understand that it has to overcome friction (and that might differ) but that friction would still apply at full speed. Anything electrical in the motor or the H-bridge?
I'm not planning to derail this thread, but just curious.
Hi there sterretje. It looks like everything is coming together at that operating condition to provide similar wheel velocities. It is certainly possible that the system is influenced by H-bridge etc. But for this case, looks like the nice thing is..... the wheel speeds are matching at those conditions.
On the other hand....if the system has no velocity measurement and velocity control to help automatically equalise wheel speeds..... then the straight line performance might not be as good as a system with velocity sensing.
Southpark:
Hi there sterretje. It looks like everything is coming together at that operating condition to provide similar wheel velocities. It is certainly possible that the system is influenced by H-bridge etc. But for this case, looks like the nice thing is..... the wheel speeds are matching at those conditions.
Not sure what you mean :snif: Why would a digitalWrite(somePin, HIGH) give the same wheel speeds but e.g. an analogWrite(somePin, 200) not. There must be something and I try to understand what it could be.
Southpark:
On the other hand....if the system has no velocity measurement and velocity control to help automatically equalise wheel speeds..... then the straight line performance might not be as good as a system with velocity sensing.
I agree that a system with feedback will always be better. It can also compensate for wheel slip if one wheel looses traction.
sterretje:
Not sure what you mean :snif: Why would a digitalWrite(somePin, HIGH) give the same wheel speeds but e.g. an analogWrite(somePin, 200) not. There must be something and I try to understand what it could be.
I was thinking of some non-linearity in the system.... or sub-systems.
I assumed that the OP was using PWM only.... like analogWrite. digitalWrite is like applying plain DC, right? On the other hand, PWM is a combo of AC and DC when the voltage levels are 0 and some positive value. If the PWM frequency isn't suitably chosen, the motor might not behave in the way we want.
sterretje:
I agree that a system with feedback will always be better. It can also compensate for wheel slip if one wheel looses traction.
Pins 5 & 6 give PWM at twice the frequency of the other 4, wonder if OP was using one of the 5-6 pair and another pin like 3? Motor inductance would come into play.
Wawa:
Not all motors are made equal.
Swap the motors on the bot, and see it it wonders off in a different direction.
You could map PWM value of one motor to a lower value.
Leo..
It went in the same direction again. The DC voltage output in the left block is more than the right one.
edgemoron:
Pins 5 & 6 give PWM at twice the frequency of the other 4, wonder if OP was using one of the 5-6 pair and another pin like 3? Motor inductance would come into play.
I am using pin number 3 and 6 on Arduino nano for the PWM signals for the two motors.
Should I not use pin 6
Could you explain the inductance part again? I would again try and explain my problem.
PWM to Left motor(Pin3) PWM to Right motor(Pin6) L298N o/p for Left motor L298N o/p for Right motor
255 255 10.64V 10.66V
230 230 9.80V 9.05V
200 200 9.41V 8.69V
150 150 8.45V 7.23V
110 110 6.99V 5.35V
Please note the offset is also not constant.
So I can not use the obvious solution of given an offset to the PWM signal.
Thank you for your response
They (designers) probably should have just made the PWM frequencies consistent on all pins. That would save time-wasting exercises for everybody. On the other hand, at least it looks like the behaviour is now going to be under control. But also looks like this is one of those cases where going through the tutorials for setting up PWM on a particular arduino board can come in handy.
edgemoron:
Pins 5 & 6 give PWM at twice the frequency of the other 4, wonder if OP was using one of the 5-6 pair and another pin like 3? Motor inductance would come into play.
I just want to thank you so very much for your valuable answer. We are participating in a robotics competition and had built our robot. But at the end we realised that it was not even going straight. We followed what you said and it is working perfectly now. We were on the verge of giving up as the deadline was approaching. We have spent 6 months on this robot and this means a lot to us. I cannot express how grateful I am to you. Your answer might have just changed our future.
Sujith19:
I just want to thank you so very much for your valuable answer. We are participating in a robotics competition and had built our robot. But at the end we realised that it was not even going straight. We followed what you said and it is working perfectly now. We were on the verge of giving up as the deadline was approaching. We have spent 6 months on this robot and this means a lot to us. I cannot express how grateful I am to you. Your answer might have just changed our future.
Good luck mate, let us know how you went.
Can you post a picture of your robot please?
Thanks.. Tom..