Built-In PID and MoveMotorTarget()

I’ve been attempting to get our team’s auton more precise and the built-in RobotC PID control seems to be a great option to get to exact locations without long/complicated auton functions that would need optimization later on in the season. Searching through previous threads (and threads on NXT - not sure whether some functions carry over or not) and the RobotC Help docs then trying it out in some test programs, I haven’t been able to use MoveMotorTarget() to get my robot to move to a position correctly. So far I have:


void setPIDAll ( bool set = true )
{

	setPIDforMotor(L, set); //Is this the correct command? This is the most recent I could find in the documentation.
	setPIDforMotor(R, set);

}

void pidTest()
{

	setPIDAll( true ); //turn on PID

	setMotorTarget(L, 500, 110, true);
	setMotorTarget(R, 500, 110, true);

	setPIDAll( false ); //turn off PID

}

This code makes the robot drive backward indefinitely; Much further than 500 encoder ticks. We have our drive set up with both sides on a Y-Splitter using one IME on the front motor of each side.

Is there a better way to do this? Is MoveMotorTarget() correct or still supported?

Thanks you guys.

setPIDforMotor is a natural language function, it takes the motor port and either true or false as parameters to enable/disable SPEED based PID. There’s no need to use it for moving motors as you are trying to do.

setMotorTarget should move the motor to an absolute encoder position, moveMotorTarget should move the motor to a position relative to the current position, they should both still be valid. Make sure your wiring is correct and you have no black/red motor wire reversals. If the motors are on ports 1 or 10 the red wire should be on the inside towards the VEXnet key. These commands assume that positive motor controls values will make the encoder count upwards so correct wiring is necessary.

There is some difference in implementation for VEX EDR/VexIQ and Lego. I will verify that nothing is broken with the latest version of RobotC later this week when I’m back in the office.