Autonomous robot

I am building an autonomous robot for solving a labyrinth with PSoC 5LP, 3 sensors HC-SR04 and DC Motors. I tested the sensors and they measure the distance correctly, but i have troubles with controlling the motors with PWM. Even though the voltages are approximately the same for the 2 DC motors, the robot is not moving in a straight line causing problems when it has to turn left/right. I tried to implement a sort of controller based on the distances from left and right sensor in order to keep the robot on the center of the labyrinth but it doesn't work properly. Any ideas of what should i change/test?

by anna.c
6 days, 13 hours ago

You need TWO PWM outputs. Adjusting the PWM for each DC motor (if they are not steps-motor, that is) is a standard solution. Having less voltage, in average, that results in turning slower. It is also possible that it each side does not have the same grip, different possible causes, from weight distribution, motor variations, friction , ...so, you have to compensate with a test to get which PWM duty cycle is required on the left for a given PWM duty cycle given at the right.

If you use a dark line to identify the trajectory, then having multiple sensor tracking the position of the robot with respect to that dark line may allow a MCU to keep track on which side should increase or decrease its PWM duty cycle. That should "handle" the small trajectory errors on site. It is doable with sonar/laser sensors, but harder to implement (in corners and in intersections). But I don't know how your maze is built.

I assume that you are aware than one motor should turn clockwise and the other, anti-clockwise.

by vanderghast
6 days, 6 hours ago

Thank you for your answer! I already have 2 PWMs for the motors and I have adjusted the duties in order to have the same voltages, i even replaced the motor driver because sometimes there was a drop of voltage, but the problem is still there - the movement is not in a straight line. I will consider to use a dark line with an IR sensor, but as a last option because it will become a line following robot more than a maze solver one.

by anna.c
5 days, 9 hours ago

Even if the voltage (the average voltage that is) is the same, each motor allows variation in its construction so their couple can be lightly different. Furthermore, each wheel can also behave slightly differently, that is why you should not relay on the single criteria to have the same voltage, but on experimental full scale test to finally fine tune a different voltage for each motor (thorugh a different duty cycle). Sure, that fine tuning should work fine if both wheels are under the same road surface, versus a wheel on a dry surface and a wheel on a slippery surface. That last condition seems to required a precise 2D position acquisition (could also be a reparable fix point, like a sharp corner of an obtuse intersection of two walls, creating a sharp discontinuity in the distance, or reflection, as example, but that becomes heavy stuff).

by vanderghast
5 days, 7 hours ago

The problem is that the movement is not continuous straight, or a little bit to right/left. It can be 20 cm straight, than right, than straight again. It's probably because the voltage is not constant, there is a maximum of 100 mV on a motor and 40 mV on the other. I implemented a PID controller and it's better, but there are still cases when it hits the wall and i am looking for another solution.

by anna.c
4 days, 5 hours ago
Add comment...

Please sign in or create an account to comment.


No Answers

No answers yet. Contribute your answer below!


Your Answer

You must log in or create an account (free!) to answer a question.

Log in Create an account


Go Ad-Free. Activate your CircuitLab membership. No more ads. Save unlimited circuits. Run unlimited simulations.

Search Questions & Answers


Ask a Question

Anyone can ask a question.

Did you already search (see above) to see if a similar question has already been answered? If you can't find the answer, you may ask a question.


About This Site

CircuitLab's Q&A site is a FREE questions and answers forum for electronics and electrical engineering students, hobbyists, and professionals.

We encourage you to use our built-in schematic & simulation software to add more detail to your questions and answers.

Acceptable Questions:

  • Concept or theory questions
  • Practical engineering questions
  • “Homework” questions
  • Software/hardware intersection
  • Best practices
  • Design choices & component selection
  • Troubleshooting

Unacceptable Questions:

  • Non-English language content
  • Non-question discussion
  • Non-electronics questions
  • Vendor-specific topics
  • Pure software questions
  • CircuitLab software support

Please respect that there are both seasoned experts and total newbies here: please be nice, be constructive, and be specific!

About CircuitLab

CircuitLab is an in-browser schematic capture and circuit simulation software tool to help you rapidly design and analyze analog and digital electronics systems.