April 23, 2011

Random Light Finder (Matlab version)

Today I found some time to play with the Lego NXT, and I wrote the matlab version of the random light finder. The matlab program is shown below. It works quite well. With matlab I can now easily implement more sophisticated algorithm.

The robot can now effectively avoid obstacles, and I don't need to help it get out of somewhere from time to time. The program can also plot the light sensor data while the robot moves around. It is very slow to find the light because it's a random walker just like the Euglena.

The code is here.

Most of the code are straight forward, there is only one line I need to put some more words.

abs(lightdata(step)-lightdata(step-1))<5 means the light intensity almost unchanged compare to the last step. This could because the Robot get stuck somewhere and can't move forward. It also could because it goes to a dark regime where the light is always very low therefore hardly changes. The robot should avoid both the situations, so I let the robot go backwards a little bit in these two cases.


No comments:

Post a Comment