A question was asked about how to turn on and off the ROBOTC PID. For the example in post #1.
// Turn off PID
if( vexRT Btn7U ] == 1 )
nMotorPIDSpeedCtrl port2 ] = RegIdle;
// Turn on PID
if( vexRT Btn7D ] == 1 )
nMotorPIDSpeedCtrl port2 ] = RegSpeed;
However, although this works there is one small problem. When PID is turned off with the motors running, the master motor will immediately jump to the commanded speed you sent it. For example, lets say you sent it a value of 50, the PID may actually be sending a small pwm value to the motor, say 25, you can see these values in the motors debug window. As we had three slave motors in the original code they also would be getting the same pwm value. When PID is turned off for the master motor the slave motors will not be sent the last command you had sent to the master motor. Bottom line is that you need to resend the command to the master motor if PID control is disabled. Here is a revised version of the code in post #1 with PID enable and disable.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port2, , tmotorVex393HighSpeed_MC29, PIDControl, encoderPort, I2C_1)
#pragma config(Motor, port3, , tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port4, , tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port5, , tmotorVex393HighSpeed_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
int motorSpeed;
// Motors on ports 3, 4 & 5 will follow the motor on port 2
slaveMotor(port3, port2);
slaveMotor(port4, port2);
slaveMotor(port5, port2);
// Driver control loop
while(1) {
// Two different speeds.
if( vexRT Btn8U ] == 1 )
motorSpeed = 50;
else
if( vexRT Btn8R ] == 1 )
motorSpeed = 100;
else
if( vexRT Btn8D ] == 1 )
motorSpeed = 0;
// Enable/disable PID
if( vexRT Btn7U ] == 1 )
nMotorPIDSpeedCtrl port2 ] = RegIdle;
else
if( vexRT Btn7D ] == 1 )
nMotorPIDSpeedCtrl port2 ] = RegSpeed;
motor port2 ] = motorSpeed;
wait1Msec(20);
}
}