the problem with that is if your batterys gets low then you have to reconfigure and that get very time consuming some times. i figured it out
if you have two shaft encoders then you do 3 if statments like this.
if(sensorvalue(R_left) == sensorvalue(R_right)// going straight
{
motor[Motor_L] = 50;// ajust these ratios depending on how fast you
motor[Motor_R] = 50;//want to go 80 is about as fast as you can go without gearing
}
if(sensorvalue(R_left) > sensorvalue(R_right)//driffting to the right
{
motor[Motor_L] = 50;
motor[Motor_R] = 55;
}
if(sensorvalue(R_left) < sensorvalue(R_right)// drifting to the left
{
motor[Motor_L] = 55;
motor[Motor_R] = 50;
}
and thats it
if you want to put it in a sub routine to go a cirtan distance
void DriveStraight (int distance)
{
while(sensorvalue(R_left) != 7 /*change this value depending on what the diamitor of you whelle is mine was 5" this is the number of ticks per inch. you figure the cercoumfrence and divide it by 100. that gives you your ticks per inch*/ *distance)
{
if(sensorvalue(R_left) == sensorvalue(R_right)// going straight
{
motor[Motor_L] = 50;// ajust these ratios depending on how fast you
motor[Motor_R] = 50;//want to go 80 is about as fast as you can go without gearing
}
if(sensorvalue(R_left) > sensorvalue(R_right)//driffting to the right
{
motor[Motor_L] = 50;
motor[Motor_R] = 55;
}
if(sensorvalue(R_left) < sensorvalue(R_right)// drifting to the left
{
motor[Motor_L] = 55;
motor[Motor_R] = 50;
}
}
}
and your done
and if you need help with turning email me at
core2extremist2@gmail.com