Monday, April 27, 2015

Light/Dark with Sciborg

Our last task with our sciborg was to get it to follow a white stripe using a brightness sensor. First, we had to do it using bang bang control, then proportional.

For bang bang control, we first tried writing a code that drove straight when it sensed it was on the light surface and turned back and forth when on a dark surface in the hope that it would find the light surface again and continue driving straight. Here is what the code for that looks like:
 

This code was unsuccessful however, because once on the dark surface, our sciborg was not able to reach the white line again. Or, if it did, it had gone in a full loop before reaching it again.

We then decided to use edge following, where turns right when on dark surfaces and left when on light surfaces. This worked very well and our sciborg was able to follow the track made by the white line. Here is our final code and  a video:

Next we tried to adjust our code so that our sciborg followed the line using proportional control. This was a difficult concept for us at first, because we couldn't figure out how to tell our sciborg how much it was on light or dark, we only knew how to tell it light vs. dark. However, after playing around with our code enough we found a way to implement proportional control by making the light value our "goal" and by calculating a reasonable gain. This way, we were able to create an "error" value based on how far our reading was from our goal value. We calculated an output equation using the gain and the error and set our speeds to output. After having to change our numbers several times and do many trials, this is what our final code looked like:


Notice that we put absolute value "bars" around our error function to account for our sciborg veering off the white line to the left or right. This ensures that our output is always positive. As a result of this adjustment, our sciborg did not zig-zag so sharply when following the line, instead making gentler adjustments to stay on track. Here is a video of our sciborg running the track using our proportional control code:



This completes our work with sciborgs and I will now be focusing my blog posts on my final project. 




No comments:

Post a Comment