In my code in robotc my robot keeps running one function. I am calling multiple yet it gets stuck in the first one. I tried using return; but it didn’t work. All the functions work by themselves.
Show us the code.
void autonDriveForwards(float distanceForwards)
{
SensorValue[frontRightEncoder]=0;
SensorValue[frontLeftEncoder]=0;
SensorValue[rearRightEncoder]=0;
SensorValue[rearLeftEncoder]=0;
while((abs(SensorValue(frontLeftEncoder))/360*3.1415926*3.25*1.5) < distanceforwards || (abs(frontRightEncoder)/360*3.1415926*3.25*1.5) < distanceforwards )
// divide by 360 to get rotations, times pi, times wheel diameter, times 1.5 for wheel type
{
if((abs(SensorValue(frontRightEncoder))/360*3.1415926*3.25*1.5) < distanceforwards)
{
motor[frontRight1] = 127;
motor[backRight1] = 127;
motor[backRight2] = 127;
}
if((abs(SensorValue(frontRightEncoder))/360*3.1415926*3.25*1.5) >= distanceforwards)
{
motor[frontRight1] = 0;
motor[backRight1] = 0;
motor[backRight2] = 0;
}
if((abs(SensorValue(frontLeftEncoder))/360*3.1415926*3.25*1.5) < distanceforwards)
{
motor[frontLeft1] = 127;
motor[backLeft1] = 127;
motor[backLeft2] = 127;
}
if((abs(SensorValue(frontLeftEncoder))/360*3.1415926*3.25*1.5) >= distanceforwards)
{
motor[frontLeft1] = 0;
motor[backLeft1] = 0;
motor[backLeft2] = 0;
}
}
return;
}
This line.
while((abs(SensorValue(frontLeftEncoder))/360*3.1415926*3.25*1.5) < distanceforwards || (abs(frontRightEncoder)/360*3.1415926*3.25*1.5) < distanceforwards )
is probably always true, can you figure out why?
That can’t be because the robot stops driving meaning (abs(SensorValue(frontLeftEncoder))/3603.14159263.25*1.5) is greater than or equal to distance forwards.
Thanks
Look at the other side
abs(frontRightEncoder)/360*3.1415926*3.25*1.5)
It seems like you have parenthesis instead of brackets for that piece of code, and you may not need all the multiplication stuff when you can just simplify it…
This should be all you need:
(abs(SensorValue[frontLeftEncoder])/5513.495013)
Another thing, you don’t have to make the calculation be THAT precise.
Actually what is wrong is that "SensorValue’ is missing from the second comparison, abs(frontRightEncoder) should be abs( SensorValue frontRightEncoder ] ).
RobotC is tolerant of the incorrect use of () on things like motor and SensorValue where ] should really be used.