# Motor Control with Image Processing

#1

Hi,

I am working on making a self-driving GoPiGo. The first step is to implement lane maintenance. I have been using Python and OpenCV to achieve this.

I start with the image processing. Using a continuous feed from the PiCamera, I crop the bottom half of the image (where my lanes are). Now, I use thresholding and Hough lines to separate the lanes from the rest of the image. This works great so far. I have even gone so far as to be able to tell whether I am veering to the left or right.

The problem is when I attempt to actuate the motors to correct the course. The motors do not run, and I am confused as to why. I have a snippet of my code here:

``````                if (xval &lt; 70 and x2_avg != 0) or (x1_avg == 0):
print &quot;moving to the right&quot;
else:
if (xval &gt; 110 and x1_avg != 0) or (x2_avg == 0):
print &quot;moving to the left&quot;
state_dir = -1
else:
if (xval &gt;= 70 and xval &lt;= 110 and x1_avg != 0 and x2_avg != 0):
print &quot;maintaining lane&quot;

``````

So far, I have been using a sheet of paper with two black lines to mimic a road with lanes. I show this to the camera, and move the sheet of paper (thus making it veer off course). The Pi then prints whether it is moving to the right, left, or maintaining lane. I have tried to use the fwd(), increase_left_speed(), and increase_right_speed() commands right after my print statements above, but they have not worked. What am I doing wrong? Thanks in advance for the help

#2

Hey,
I am not really sure how you are controlling the GoPiGo. Can you past a link or a file to the entire code. Just a few pointers. If you decrease the speed too much, the motor will stop moving and if the voltage is too low then also the motor will stop moving.

-Karan