Sunday, January 30

Line follower update 02

I have gotten far on my program, and will post a screen-shot for you now. Just a minute...     Ok, here it is:
First page out of three!
As you can see, the layout is quite messy.  I have too many global variables, most of which task DISPLAY() is using.  I think that I will turn DISPLAY() into a function that is called by the other two main tasks.  If you will notice, the screen-shot shows only one third of the code I have written.  That is too much code for a simple line follower, but as I get each part perfected, I hone it down.  For example:  The function MOTOR_CONTROL(), was at first a complicated task, but as I saw that I only wanted it to run after a certain part of task DATA_LOG(), I converted it into a function.  This conversion enabled me to eliminate a few global variables that were used only by MOTOR_CONTROL(), substituting them for parameters.

Well, that is all for now... I'd better get back to programming!

P.S. I recognize that by posting my code to the public, I have given you the permission to use, modify to any extent the said code.  But, this code may not be sold without permission from me, and I would appreciate it if you would give me credit if you do use this code.  Thank you!

Tuesday, January 18

Building a Line follower. Easy?

Ok, I guess that from my last post I sounded pretty much an expert on the whole line following thing... well ever since then I've been working on a follower myself, and I'll tell you what, it ain't easy.  I find myself in the lower end of  "the middle class of programmers"  which I established in my last post.  (Those who understand the basics and essentials of programming, but have not mastered the art.)  I finished the robot in a few hours, but I've made, and rejected, three complex programs each of which I spent considerable time designing.  I am now on my fourth,  I decided to do it in NXC because I was running out of file space on my NXT when using NXT-G.  So far, I haven't got quite as far as I did in NXT-G, but I had to overcome many obstacles and bugs (not being very fluent in NXC.)  I will be posting updates on my robot as well as code snippets as I get them finished.

Monday, January 10

Line Following

Continuous Line Follower
   Following a line...  An idea that to the extreme beginner and the expert seems easy, but to the middle class of programmers (those who understand the basics and essentials of programming, but have not mastered the art,) the task is quite complicated.  Most of the line followers I have seen on NXTLog and elsewhere follow continuous lines.  A few of them have the capability of traversing cross-roads and road split.  And one or two can cross breaks in the track and avoid obstacles in the way.  I have seen multiple light sensors on a single bot and have observed but one on a bot.
Four Light Sensors
 I think there are definite downfalls and gains to be had from either of the two; on the one hand, more sensors mean more accuracy but is more expensive; while on the other, when using only one light sensor, you don't need to buy extra parts but the robot will be slower and less accurate.
  There are many other alternatives to the methods of line following described above, one being to buy non-lego sensors for your robot such as the five sensor array below.  One alternative that I have thought of is to have a light sensor mounted on an arm or boom and swing back and forth in front of the robot.  The light sensor would detect the line edges and, depending on the position of the servo controlling it, the NXT could tell how hard to turn, and what direction to turn. 
   The algorithm used to decide the turn would run something like this.
   
#define RIGHT true;
#define LEFT false;

{  // when pointed straight ahead, the rotation sensor is at zero.
  int turnpct = degrees / 2;

  if (degrees > 0){ direction = RIGHT; }
  else if (degrees < 0){ direction = LEFT; }

 
RotateMotorEx(BC, 100, 90,
     turnpct, true, false);

}// I have not tested this algorithm.
  //I made it up as I was sitting here,
  //but it is something like that which you would use.

The GreyHound
I recently discovered a project on NXTLog that uses this mode of line following.  It is a simple bot named the GreyHound built by hydrogenhead.
  The main advantage of such a design is:
   Although a little slower than using multiple light sensors, the 'sweeping' method is much more accurate, providing the ability to get a reading on every degree that the motor controlling it is able to turn to. 
  For example, say that we have four different light sensors across the front of our robot similar to what we see in the third picture up.  We could get four readings. We could vaguely tell how wide the line is, and generally where it is in respect to the front of the robot.  Now let's say that the line our robot is trying to follow is wide enough to fit one light sensor.  The robot randomly picks one of the middle sensors (we'll call it Jared.)  Now on following the line, the robot tries to keep the line under the chosen sensor (Jared,) and when Jared losses the line, the two other sensors start checking for it in order to alert the NXT as to where it is.  On receiving information as to the direction the line has turned, the NXT gives the appropriate information to the drive motors who respond accordingly.  This sounds great, but there are two problems to this method.  If the line turns too sharply, the robot loses it, and upon adjusting the turn radius, the bot follows the line in zig-zags thereby considerably reducing its speed.
 
   If we use the sweeping method however, our results are much more promising.  The light sensor (we'll continue using the name Jared for familiarities sake,) goes back and forth across the line, stopping precisely at the edges so as not to get confused with any other lines that may be in the near vicinity.  Every time Jared gets to one edge of the line, he informs the NXT, who in turn, gets the motor degrees from the motor moving Jared.  After receiving two such motor positions, the NXT finds the average, ( the middle of the line, ) and adjusts the turn percent accordingly.  When our robot comes to a corner, it slows down so as to not overrun and get lost.

   To sum it all up, the sweeping method of line following is slower going in a straight line because of the time taken to move the sensor, but because of the added locations possible for the sensor to be in, the robots precision is greatly advanced and therefore the speed and smoothness in traversing curves surpasses greatly the performance of other robots.

Saturday, January 1

4 DOF mobile robotic arm

Have you ever tried to build a big robot, so big that you'd need multiple brains and definitely multiple power sources?  Well, up to now I have wanted to, but I did not have all the pieces, motors, and ways to control them.
  For maybe a year I have gotten close to big because of the amount of Legos I had obtained, but I still wasn't quite there.  This year for my birthday I received an Arduino and decided to use it for a second motor controller.  Since the Arduino can provide five volts only, I used it to manipulate the servos controlling the pneumatic switches.


  Now, this may seem great, but after putting it all together, the parts I still needed coming in the mail, I ran the quick test program I always do (to work out the last details,) and realized something important. Even though I had geared the motors down, they were not moving... the robot was just too heavy.  I decided to remodel using worm gears this time to see if I could get any movement at all.  Now that that is done, it is all moving smoothly, though extremely slowly. 
  After witnessing the extreme slowness produced by the heavy-ness of my machine, I decided to do a bit of  research on NXTLog to see if anybody had gotten a large and complex robot to go very fast at all.  It seems that nobody has... at least, I did not see any body getting a robot with as many motors and all in all weight as my bot to traverse with any speed to talk about.  Well that is interesting, I wonder if there are any other, more powerful motors for cheap that could be adapted for use in a Lego robot.

for more pictures of my Mobile Robotic Arm, click HERE.