Hey, my name is Marshall from team 11761B, and I am an all around person… but at the moment I am programming. My teammates are being to slow for me to test out my programs, and I am fairly new to robotC… so I was wondering if anybody could see any major errors besides the fact that none of the motors or sensors are assigned due to the fact that I don’t know what port they would be connected to yet. If anybody could help me out that would be great… thanks in advance!!!
P.S. The plan in the program was to make some functions so future programming would be easier!
#define abs(X) ((X < 0) ? -1 * X : X)
void driveForward(float inches, int power)
{
SensorValue[rightencoder] = 0;
SensorValue[leftencoder] = 0;
int drivegoal = (inches * 49.9109902106);
while(abs(SensorValue[rightencoder] < drivegoal || SensorValue[leftencoder] < drivegoal))
{
motor[rightmotor] = power;
motor[leftmotor] = power;
}
{
motor[rightmotor] = 0;
motor[leftmotor] = 0;
}
}
void driveBackward(float inches, int power) //New
{
SensorValue[rightencoder] = 0;
SensorValue[leftencoder] = 0;
float drivegoal = (inches * 49.9109902106);
while(abs(SensorValue[rightencoder] > drivegoal || SensorValue[leftencoder] > drivegoal))
{
motor[rightmotor] = -power;
motor[leftmotor] = -power;
}
{
motor[rightmotor] = 0;
motor[leftmotor] = 0;
}
}
void Turn(void direction, int degrees, int power)
{
SensorValue[rightencoder] = 0;
SensorValue[leftencoder] = 0;
float turngoal = (degrees * 6.09777777778)
switch(direction)
{
case right:
greaterthan = leftencoder;
lessthan = rightencoder;
negative = rightmotor;
positive = leftmotor;
break;
case left:
greaterthan = rightencoder;
lessthan = leftencoder;
negative = leftmotor;
positive = rightmotor;
break;
default:
}
while(abs(SensorValue[greaterthan] > turngoal || SensorValue[lessthan] < -turngoal))
{
motor[negative] = -power;
motor[positive] = power;
}
{
motor[leftmotor] = 0;
motor[rightmotor] = 0;
}
}
// if(direction == Right)
// {
// while(abs(SensorValue[leftencoder] > turngoal || SensorValue[rightencoder] < -turngoal))
// {
// motor[rightmotor] = -power;
// motor[leftmotor] = power;
// }
//
// {
// motor[leftmotor] = 0;
// motor[rightmotor] = 0;
// }
// }
//
// if(direction == Left)
// {
// while(abs(SensorValue[rightencoder] > turngoal || SensorValue[leftencoder] < -turngoal))
// motor[rightmotor] = power;
// motor[leftmotor] = -power;
// }
//
// {
// motor[leftmotor] = 0;
// motor[rightmotor] = 0;
// }
// }
//}
void move(void xdirection, float amount, int power) //New
{
switch(xdirection)
{
case forward:
driveForward(amount, power);
break;
case left:
Turn(xdirection, amount, power);
break;
case right:
Turn(xdirection, amount, power);
break;
case backward:
driveBackward(amount, power);
break;
}
}
task main() //Use move(direction, amountif direction = left/right degrees, if direction = forward/backward use inches)
{
//Put code in here
}