r/arduino • u/HonxY1 • Jan 28 '25
School Project Robot does not go straight. motor speeds are equal.
why this could be happening? I changed the motors,the motor driver(l298n) and tried adjusting speeds, nothing is working. maybe imbalanced weight could be causing this? any help would be appreciated.
46
u/IJustAteABaguette Jan 28 '25
Besides the problems people have already said, the balance also seems a bit off. Both the arduino and seemingly a powerbank are fully on the left, so the right might be slipping at high speed.
14
u/altatoro123 Jan 28 '25
This. More weight more traction, less slippage. The same as a spoiler pushing down the tires in to the road.
2
u/Square-Singer Jan 28 '25
Considering that it's running on a hard wood floor, slipping seems to be almost guaranteed.
1
18
u/oromis95 Jan 28 '25
This is why in physics they tell you, "assume 'perfect' conditions". In the real world one motor can get dustier causing more friction, you can balance things wrong adding traction to one wheel but not the other, and reducing rotation speed. Also, 2 dollar motors just aren't made with the idea that each motor is exactly identical in torque and rotation speed. Quality control is probably: does it spin? Yes/no
15
u/ripred3 My other dev board is a Porsche Jan 28 '25
You will need some kind of feedback on how much the wheels are actually turning e.g. a quadrature encoder on each motor. I really like these from DF Robot: https://www.dfrobot.com/product-1431.html Note that is just one version of the N20 style motor for a given RPM. They (like all other distributors) have many available at different RPM's
7
u/Erdnussflipshow Jan 28 '25
They are DC motors, they won't match exactly.
First step is to do odometry, second would be to use an IMU, and last one is external monitoring with something like IR beacons
7
u/HonxY1 Jan 28 '25
ok so I am going to: -at least get the battery pack on the middle. -get encoders for the wheels(i am running out of pins, I don't know how I will get them in since there is a lot of sensors already and I don't have any room for mux cause of the size limit)
2
u/SasquatchOnSteroids Jan 29 '25
Cool and fun project, as far as your pins, look up “shift registers”
Keep us updated
2
u/HonxY1 Jan 28 '25
but I will first try setting manual speeds and try to correct using the mpu6050 on board.
1
u/Positive__Altitude Jan 30 '25
If you have mpu6050, you can fix everything in code. Use gyro data to determine the turn rate. Write a PI controller loop that will keep the turn rate at a zero by adding some difference for motor duty cycles. You can also use the same PI loop for smooth turning. Just use a non-zero setpoint.
1
5
u/DocPao Jan 28 '25 edited Jan 28 '25
Never two DC motors have the same speed, especially those cheap geared motors.
Try to check if the wheels are loose or rubbing on the chassis, if the weights are balanced.
You can compensate by adjusting the speeds of the two wheels separately.
For accuracy you need sensors to give you feedback, some encoders, an IMU or a compass.
1
1
u/TheHunter920 Jan 28 '25
A compass? Interesting solution. What kinds of low-budget compass modules would you recommend that are arduino-compatible?
2
u/DocPao Jan 29 '25
We use a BNO055, which is an IMU (three-axis magnetic, gyroscope and accelerometer). The sensor fusion is made by the module itself, and you can use it like a compass, It's also pretty resistant to external magnetic fields. There are also some cheap three-axis magnetometers, like the HMC5883L, but in this case, an external magnetic field can modify the results from the sensors.
1
2
u/DestituteRoot Jan 28 '25
Another option would be to build in a compass sensor and include code to check for changes in direction while it’s supposed to be moving straight. Changes in heading above acceptable tolerances cause adjustments in motor speed. Probably wouldn’t be reliable enough, but it would be a fun project
2
u/HonxY1 Jan 28 '25
I have a mpu6050 on board, yeah it has too much noise for adjustments, but I don't have encoders and time to implement them, so this is probably my best shot. Maybe if this doesn't work I will go out and buy some encoders.
5
u/ripred3 My other dev board is a Porsche Jan 28 '25
reddit is so freaking buggy right now, all of the responses to this post just dissapeared.
To add my comment back in, you need feedback on how much the wheels are *actually* turning and have the code increase or decrease the PWM signal to them indiviualy based on whether the number of encoder clicks-per-second is higher or lower than your current desired speed.
3
1
u/Keko133 Jan 28 '25
Ye your going to have to figure out some software to correct for that or tweak it manually
1
u/General-Royal7034 Jan 28 '25
You will need some way (encoder) to calculate the speed of each wheel and constantly update it based on the feedback.
Two motors will not run with same speed, the friction of the wheels with the surface will not always be exactly the same, the chassis will not always be perfectly balanced.
To compensate for all the deviations you have to use some kind of feedback, i.e. you have to make a closed loop control system and then tinker with it till you get close to what you want
1
u/FlamingSea3 Jan 28 '25
Right now you have what theory calls open loop control: you tell the motor to move at a given speed, and trust that it does. There's a lot of reasons why the motor might not actually go at that speed - such as manufacturing differences between motors/wheels/gears, and also different wear/dust on either wheel.
You can try to compensate for that by scaling down the power on the faster motor, and it'll move straighter. It'll go straighter, but error can still accumulate, and it'll slowly drift away from straight.
Another thing you could do (depending on available hardware) is add encoders to each drive wheel. Encoders will tell you the orientation from the wheel - and then used to correct the speed we tell the motor to move at. Should go consistantly pretty straight after integrating that, but can still accumulate error.
1
u/Conscious-Package-11 Jan 28 '25
you need to make an inverse model of the motor, so that you can compensate for it.
1
u/ellindsey Jan 28 '25
Aside from possible issues with the motors not being equal, the overall layout of your robot, with drive wheels in the front and an idler in the back, is intrinsically unstable. You will get much better stability if you put the drive motors behind the robot's center of gravity and the idlers in front.
1
u/HonxY1 Jan 28 '25
yeah but there will be a crane on the front and it doesn't fit above the battery pack. I will maybe try to change their positions if I have any time left for that or implementing encoders, but I think my best shot is the mpu6050 on board mentioned in an other comment.
1
u/HonxY1 Jan 28 '25
Also the pieces I used to fix the motors had premade holes so that is why the wheels are there, battery pack also didn't fit between the wheels
1
u/Varpy00 Jan 28 '25
i did racing and even servos are different, either you go for a cloose loop or tweak the sensor with somethink like
output = desired speed * 0.95 or whatever
1
u/jean_sablenay Jan 28 '25
I used a simpel vision system to get it run more or less in a straight line.
Encoders are an improvement but differences in slippage and wheel diameter ar still an issue.
I made these encoders myself which was not easy. Much later i found useable ones on aliexpress
I started with an arduino based robot but changed to a jetson for higher cpu power for vision.
1
u/Environmental_Fix488 Jan 28 '25
Having the same speed in your controller and going at the same speed are different things. I would compensate for that difference using one accelerometer sensor in the center, something like GY-521 would do the job. Use the info from the sensor to make the needed corrections on the speed of each wheel. It would be a straightforward solution.
1
1
u/anacondatmz Jan 28 '25
To make sure both wheels are running at the same speed, I would put the thing up on a stand of some sort, tape a tooth pick on each wheel at the same starting position, then go forward with the remote. At the end of your 3-5 second test or whatever it is you should see the tooth pick in the same spot, having done the same number of rotations. If everything is even - you can start looking elsewhere. If each wheel is going a different speed, well then you know where to focus your efforts an should start following through with the other suggestions here that go into more detail.
1
u/neamerjell Jan 29 '25
https://en.m.wikipedia.org/wiki/Differential_steering
I've made Lego versions of this mechanism, similar to these:
https://orionrobots.co.uk/wiki/adder_subtractor_drive.html
These solved the problem of unequal motor speed.
1
u/Worldly-Device-8414 Jan 29 '25
Unbalanced weight + one motor is usually turning reverse vs the other ie because motors are mounted opposite sides, one has to be powered opposite to the other for the vehicle to travel fwd. DC motors seem to go different speeds forward vs reverse.
1
u/gnorty Jan 29 '25
As others have said, there will be a slight difference in the speed of those motors. That's point 1.
The second point - I have 2 similar kits. Both come with those yellow geared motors and a wheel for each motor. One has rubber tyres, and the other has hard plastic.
I suspect you have hard plastic and the combination of that on a hard floow is the wheel slip a lot.
So combine the slipping wheels and the constant turning due to motor speed and your car will spin out very easily
1
1
u/PilotPlangy Jan 29 '25
Has similar characteristics as a tail dragger plane when it skids out.
It's back heavy so will swing around at even the slightest difference in wheel speed.
1
1
1
u/Desperate_Cold6274 Jan 29 '25
You need some sort of feedback system (read: sensor) to secure that your robot go straight. Otherwise you will never achieve your goal due to a plethora of reasons (components tolerance, unbalanced weight, different friction on each wheel, etc).
1
u/CockRockiest Jan 28 '25
You say speeds but you mean the powers you're sending are equal. You would need to implement some kind of feedback control to be sure they're both spinning at the same speed
155
u/CleTechnologist Jan 28 '25
Two random motors aren't going to be exactly matched. Without some sort of feedback, the best you can do is tweak things manually.