I used to play with that little Cybot project that came with the Eaglemoss publications "Real Robots" magazine.
Recently I got very board with it, so, being me, I ripped out its microprocessors, leaving only the sensory and motor control components, and introduced the beloved PIC!
I began with a program that would allow the robot to follow a black line on a white surface.
Check HERE and HERE for the schematics.
It's very simple, the pair of IR sensors feed into a comparator, the black line absorbs IR, the white reflects. When the robot is on the edge of the line, the result would be, one IR sensor at logic 1 and the other at logic 0. The comparator outputs logic 1 to the processor when one input is at logic 1 and the other is a logic 0, otherwise it will output logic 0.
I spend some time thinking about this one, and after a lesson on Fuzzy Logic in IT class at school I finally got it!
So here's how:
As you can see, its quite simple, Fuzzy Logic... If the processor is doing one thing, and an error occurs, fix it by doing the opposite.Code:'**************************************************************** '* Name : LineFollow.BAS * '* Author : CIT Systems (Darren Carter) * '* Notice : Copyright (c) 2009 CIT Systems (Darren Carter) * '* : All Rights Reserved * '* Date : 2009/02/02 * '* Version : 1.0 * '* Notes : Include in PIC-Bot Processor * '* : * '**************************************************************** 'Line Follow loop LineFollow: Lcdout $FE, $C0, "~~ LiNe FoLlOw ~~" ' Display current mode on LCD. Lcdout $FE, $94, "...Scan Line..." ' Tell user line is being followed. low RHF ' Stop right motor. low LHF ' Stop left motor. PWM LHF,60,18 ' Move slightly RIGHT. pause 100 ' Take a break. if linecom = 0 then gosub moveleft ' Check the line, if you no on it, adjust LEFT, otherwise, continue. low RHF ' Stop right motor. low LHF ' Stop left motor. PWM RHF,60,18 ' Move slightly LEFT. pause 100 ' Take a break. if linecom = 0 then gosub moveright ' Check the line, if you no on it, adjust RIGHT, otherwise, continue. gosub chkctrl goto linefollow ' Repeat the process MoveLeft: Lcdout $FE, $94, "Correct Left" ' Tell user, correcting LEFT. repeat low RHF ' Stop right motor. low LHF ' Stop left motor. PWM RHF,60,20 pause 100 ' Take a break. until linecom = 1 ' Do this until back on line. pause 50 ' Take a break, and get ready to move ahead by adjusting a little more LEFT. low RHF low LHF PWM RHF,60,18 return ' Go back to LineFollow loop. MoveRight: Lcdout $FE, $94, "Correct Right" ' Tell user, correcting RIGHT. repeat low RHF ' Stop right motor. low LHF ' Stop left motor. PWM LHF,60,20 ' Move a little RIGHT. pause 100 ' Take a break. until linecom = 1 ' Do this until back on line. pause 50 ' Take a break, and get ready to move ahead by adjusting a little more LEFT. low RHF low LHF PWM LHF,60,18 return ' Go back to LineFollow loop. end
I've tested this a couple of time, sometimes the robot does move off course and gets lost, but this just a matter of timing and sensitivity, i.e. the motors move too quickly or move the robot too far for the processor and IR sensor to react to change, and/or reaction from the input from the comparator is happens too quickly, so a kind of "debounce" might be necessary.
It's all a matter of trial and error, lots of time, and PIC flashing until it eventually reaches its 2 000 000 000 threshold, LOLbut that's what hobby robotics is all about.


but that's what hobby robotics is all about.


Bookmarks