I made a function:
void drive(string direction, char speed)
{
if (direction == "forward")
{
motor[backLeftMotor] = speed;
motor[backRightMotor] = speed;
motor[frontLeftMotor] = speed;
motor[frontRightMotor] = speed;
}
if (direction == "backwards")
{
motor[backLeftMotor] = -speed;
motor[backRightMotor] = -speed;
motor[frontLeftMotor] = -speed;
motor[frontRightMotor] = -speed;
}
if(direction == "right")
{
motor[backLeftMotor] = speed;
motor[backRightMotor] = -speed;
motor[frontLeftMotor] = speed;
motor[frontRightMotor] = -speed;
}
if(direction == "left")
{
motor[backLeftMotor] = -speed;
motor[backRightMotor] = speed;
motor[frontLeftMotor] = -speed;
motor[frontRightMotor] = speed;
}
if(direction == "leftBack")
{
motor[backLeftMotor] = -speed;
motor[backRightMotor] = 0;
motor[frontLeftMotor] = -speed;
motor[frontRightMotor] = 0;
}
if(direction == "rightBack")
{
motor[backLeftMotor] = 0;
motor[backRightMotor] = -speed;
motor[frontLeftMotor] = 0;
motor[frontRightMotor] = -speed;
}
if(direction == "leftForward")
{
motor[backLeftMotor] = speed;
motor[backRightMotor] = 0;
motor[frontLeftMotor] = speed;
motor[frontRightMotor] = 0;
if(direction == "rightFoward")
{
motor[backLeftMotor] = 0;
motor[backRightMotor] = speed;
motor[frontLeftMotor] = 0;
motor[frontRightMotor] = speed;
}
if(direction == "stop")
{
motor[backLeftMotor] = 0;
motor[backRightMotor] = 0;
motor[frontLeftMotor] = 0;
motor[frontRightMotor] = 0;
}
}
}
I call the function here:
if(SensorValue[LeftEncoder] < 4927 || SensorValue[RightEncoder] < 4927)
{
drive(forward, 127);
}
else
{
drive(stop,0);
outtake(full);
wait10Msec(100);
outtake(stop);
wait10Msec(15000);
}
The code gives me the following errors:
Error:Undefined variable ‘forward’. ‘short’ assumed.
Error:Expression does not fit parameter. Call to ‘drive’. Parameter: ‘unsigned string & direction’ is ‘forward’ of type ‘short’.
Error:‘const’ expressions does not fit. Call to ‘drive’. Parameter: ‘unsigned string & direction’ is ‘“stop”’ of type ‘string’.
Error:‘const’ expressions does not fit. Call to ‘outtake’. Parameter: ‘unsigned string & speed’ is ‘“full”’ of type ‘string’.
Error:‘const’ expressions does not fit. Call to ‘outtake’. Parameter: ‘unsigned string & speed’ is ‘“stop”’ of type ‘string’.
I have tried to encapsulate my string inside of “quotes” and it didn’t help (like this
drive("forward",20);
I’m honestly not seeing the issue that the compiler is finding. I’ve declared both variables inside my function and when i called it.