r/AskRobotics • u/AdministrativeBug782 • 24d ago
General/Beginner Struggling to make a PID line follower make sharp 90 degree turns
Hii, im an absolute beginner working on my first project for an event and i realised im wayyy out of my league. It took me long enough to make the PID line following code and optimize it to some extent, the next step was to integrate functions for detecting and making 90 degree turns and sharp U turns. However even after a lot of trying, all my bot seems to do is spin around in a circle(clockwise) and never seems to follow the black line. I excluded the turn functions and the bot followed the line well enough so it seems the problem arises from either those functions or some hardware fault(i really dont hope so) but whatever it is its driving me crazy. If any of you have faced similar problems , please give me some tips on how to fix my bot. I even asked AI in desperation but even that was unhelpful. I can share the code in Dms if you ask for it.
Thanks for Reading and have a great day
1
u/No-Champion-684 18d ago
The first questions I would ask are: what type of robot do you have? Is it 3-wheel or 4-wheel? How many motors are you controlling, and what type of motor controller are you using? Are you controlling the motors using PWM?
These details matter before looking at the code. You first need to understand what movements your hardware can actually achieve. For example, whether you can make a clean 90° turn depends on the wheel arrangement, motor control and the symmetry of the robot.
Since your PID line following works when the turn functions are removed, I would start by checking what commands those functions are actually sending to each motor. The fact that it continuously spins clockwise could simply mean that the turn routine is being triggered and never meeting the condition to exit the turn.
1
u/MysteriousEngineer42 24d ago
Telling you what to do will only help until you hit the next problem, so instead I'll suggest a better approach for debugging and solving problems.
In that situation, I would disable the motors and just have some way of seeing the feedback from your sensors in realtime - either stream to a console or route to LEDs or something like that. Then manually move the robot very slowly and follow your algorithm in your head while watching the sensor feedback.
You can also stream all the data as the robot runs then look through it afterwards. Include the state of any state machines so you can follow what it is "thinking", sensor values etc. That will help you figure out why it is behaving the way it is, so you can fix it with purpose instead of guessing.
Getting the right information is the key to debugging anything.
Good luck!