Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   heres the code. y this not working (http://www.chiefdelphi.com/forums/showthread.php?t=27357)

omega 31-03-2004 14:18

Re: heres the code. y this not working
 
ya uh we need more help then that

thz anymore

DKolberg 31-03-2004 15:18

Re: heres the code. y this not working
 
/* Add your own autonomous code here. */

Navigate();

if(rc_dig_in01 ==1 )
{
pwm13 = 137;
pwm14=100;
}
else
{
pwm13 = pwm14 = 140;
}
if(rc_dig_in02 == 1)
{
pwm13 = 100;
pwm14 = 137;
}
else
{
pwm13 = pwm14 = 140;
}



This code will ignore the rc_dig_in01 as the if(rc_dig_in02 == 1) overwrites the values. You need to create 4 states for this or at least determine what you want to happen for each of the 4 states that can happen with two digital inputs:

rc_dig_in01 == 0, rc_dig_in02 == 0
rc_dig_in01 == 0, rc_dig_in02 == 1
rc_dig_in01 == 1, rc_dig_in02 == 0
rc_dig_in01 == 1, rc_dig_in02 == 1

I assume here that these are the inputs from a light sensor that indicates which light is seeing the tape, depending on how far away each sensor is it may not be possible to get both on at the same time. Then you are down to only 3 states. For simplicity lets define

Left == (rc_dig_in01 == 1);
Right == (rc_dig_in02 ==1);

Now:
if (Left)
{
turn right
}
else if (right)
{
turn left
}
else
{
go straight
}

if both left and right can be on at the same time then check for that first
if (Left && Right)
{
}
else if (Left)
{
}
else if (Right)
{
}
else
{
}


Hope this helps,

Dave
SBotz


All times are GMT -5. The time now is 18:17.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi