line seeking help needed

I have this and i know it works but i have 3 digital ins that are set as inputs
rc_dig_in01
rc_dig_in02
rc_dig_in03
they are all optical sensors, i know the optical sensors are working properly becuase i get on and off lights on the operator interface. I just cant seem to “word” the way to get all 3 sensors to work together.
roughly i want tit to work like this

if dig in 1 is on then it should turn left
if dig in 2 is on both motors should dturn equally
if dig in 3 is on then it should turn right

PWM01= left side drive
PWM02= right side drive

… but how do i get the sesors to all work together.
I cant seem to think on how to get them to all work together i tried a switch statement and stacking else if 's i just cant think of how to get it to work.


if (rc_dig_in02 == 1) {
    pwm01= 200;
    pwm02= 200; 
}
else {
    pwm01= 127;
    pwm02= 127;
}

i think what you are trying to do is


if (rc_dig_in01 == 1) ||  (rc_dig_in02 == 1) {
    pwm01= 200;
}
else {
    pwm01= 127;
}
if (rc_dig_in02 == 1) ||  (rc_dig_in03 == 1) {
    pwm02= 200;
}
else {
    pwm02= 127;
}


jerrw w

Our head programmer suggested:

if (rc_dig_in02) {
	pwm01 = 200;
	pwm02 = 200;
} else if (rc_dig_in01) {
	pwm02 = 200;
	pwm01 = 127;
} else if (rc_dig_in03) {
	pwm02 = 127;
	pwm01 = 200;
}else {
        /* No line found.... */
}

Thank you both for your fast reply I will test both of those now and let you know when I get my results. THANK YOU SOOOOOOOO MUCH!!! and best of luck to both of your teams.

Heres the code i ended up using:


if (rc_dig_in02) {
	pwm01 = 200;
	pwm02 = 200;
} else if (rc_dig_in01) {
	pwm02 = 200;
	pwm01 = 127;
} else if (rc_dig_in03) {
	pwm02 = 127;
	pwm01 = 200;
} else {
    pwm01= 127;
    pwm02= 127;
}

and it works perfectly thank you for your help

Hey Mister, just a suggestion, the more sensors you have on your robot for line following, the more accurate, and the faster you can run it. We’re using 9 sensors and we can run at almost full speed with about a 95% of the time staying on the line.

Wowser, and to think originally some of my team wanted to only do two and we had to convince them three was better. Thanks for the information Catastrophy I’ll probably try and work somethign like that during the offseason but right now with the little time we have left we will probably stick with three unless a miracle happens. Thanks for the info though, I would love to try something like that.

P.S. if you are at Nats do you think me and one of my other programmers could swing by your booth to check it out? P.M. me

I don’t think 9 is necesary, but trim the positions of the sensors based on the width of the line. I think 5 would be good:


    |   |
1  2| 3 |4  5
    |   |

1,5- perimeter, just to make sure your bot doesn’t get lost.
2,4- if these hit the line, turn that way.
_ 3- Keep this on the line.

ps-the code was just to get a fixed-width font.

Heres a tip if your having problems staying on the line, make it go in reverse if no line is being read. Heres a picture of the temp configuration (gonna have a metal plate for final all neatly up under the hood. and holes in chasse for beam to get out.)) and a video of this year’s sensors on last year’s bot. The video is kinda bad example of how the code’s working, the video is 15 sec, but it usually only take 7-11 seconds to get to the ball stand

http://home.comcast.net/~Catastrophy/picture.jpg
http://home.comcast.net/~Catastrophy/movie.avi

Here’s the code tweaked for our bot if anyones interested.


		if (dig12 == 1 && dig18 == 1){
			pwm14=76; 
			pwm16=76; 
		}
		if (dig18 == 1 && dig1 == 1 &! dig12 == 1 &! dig6 == 1){
			pwm16=96;
			pwm14=115;
		} 
		if (dig18 == 1 &! dig1 == 1 &! dig12 == 1){
			pwm16=86;
			pwm14=115; 
		}
		if (dig1 == 1 &! dig18 == 1 &! dig6 == 1){
			pwm16=76; 
			pwm14=178; 
		}
		if (dig12 == 1 && dig4 == 1 &! dig18 == 1 &! dig10 == 1){
			pwm16=96; 
			pwm14=115; 
		}
		if (dig4 == 1 &! dig12 == 1 &! dig10 == 1){
			pwm16=178;
			pwm14=76; 
		}
		if (dig12 == 1 &! dig4 == 1 &! dig18 == 1){
			pwm16=115; 
			pwm14=86; 
		}
		if (dig1 == 0 && dig4 == 0 && dig12 == 0 && dig18 == 0 && dig8 == 0 && dig10 == 0 && dig6 == 0){
			pwm14=155;
			pwm16=155;
		}
		if (dig6 == 1 &! dig1 == 1){
			pwm14=204;
			pwm16=50;
		}	
		if (dig8 == 1){
			pwm14=127;
			pwm16=127;
		}
		if (dig10 == 1 &! dig4 == 1){
			pwm14=50;
			pwm16=204;
		} 

for those that actually have this working on the 2004 bot, what times are you getting to track the complete line?

This looks excellent, after sitting around looking out our programmers figure out nothing last night this is a breath of fresh air. I personally am not a programmer, but I am going to try to implement this tonight after the Suffield Scrimmage. We were using two sensors, and something didn’t seem right about it, does anyone have any reccomendations, when using three sensor, on how to make the robot go backwards if its not seeing the line. I have a very limited knowledge of C, and I feel our programmers are uncomfortable with the platform this year. so…

If you guys can help me make this work, there will be Krispy Kreme’s at Hartford (or Atlanta) for you, on me.

Thanks a Bunch!
Jamie

Catastrophy might have a more advanced solution, but basically, if you don’t see the the line with any of your sensors, reverse. Something like this:


if(rc_dig_01 == 0 && rc_dig_02 == 0 && rc_dig_03 == 0)
{
   pwm01 = 0;
   pwm02 = 0;
}

You would, of course, have to add the code for actually following the line, but that is basically all you have to do to reverse if you don’t see anything on the sensors.

PS the digital inputs are your sensors and the pwmXXs are the drive motors.

PPS Nine banners. Crazy. :slight_smile:

Our team is actually going with two custom built analog sensors, we like analog because its not just a 1 or a 0, it brings back a range as it slides on and off the line, so you can actually program for it to follow a line quite fast with only one sensor as opposed to having 3 - … 9 sensors :ahh:

Our sensors have a potentiometer on each that allows us to adjust the sensitivity and they each have their own LED light, so they could even follow a line if it were in a dark room. (not that following lines in the dark is useful for the competition, but its something its capable of)

If anyone has any questions on line following please feel free to PM me or IM, i’d be happy to help with what I can.

P.S. I extremely recommend using atleast 3 sensors for line following, with 2 the bot will not act right at all, will be very jittery.

P.P.S the more banner sensors you have the better it will work. I’ve learned from personal experience.

The ultimate engineering attitude: “Why? 'cause we can.” Why not? :slight_smile: