View Single Post
  #14   Spotlight this post!  
Unread 31-03-2004, 15:18
DKolberg DKolberg is offline
Mentor Iron Giants
AKA: David Kolberg
FRC #5069 (Iron Giants)
Team Role: Mentor
 
Join Date: May 2002
Rookie Year: 2000
Location: South Bend
Posts: 44
DKolberg has a spectacular aura aboutDKolberg has a spectacular aura about
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