So I had a face palm moment earlier this evening. ROBOTC includes PID for velocity control in V4.XX. It’s really intended for use on classroom robots to allow them to drive in a straight line, but (in theory) it should be possible to use this on flywheels. Here is an example program.
#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()
{
// 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 )
motor port2 ] = 50;
else
if( vexRT Btn8R ] == 1 )
motor port2 ] = 100;
else
if( vexRT Btn8D ] == 1 )
motor port2 ] = 0;
wait1Msec(20);
}
}
Four motors drive the flywheel, you can see I call a function called slaveMotor to slave three of the four ports to a master motor that has an IME. That motor has PID turned on the the motors & sensor setup dialog, now when you send values to the motor the actual motor power is controlled by ROBOTC. This works well for drive motors, I have not tested it on a flywheel, it does allow “headroom” so it may end up that the flywheel does not spin fast enough but perhaps a team with a working flywheel might like to give this a go.
The PID constants may still need tweaking, you will find them in the motors & sensors dialog as well (turn on menu level “super user” first).
Let me know if anyone has success with this.
Mote explanation of ROBOTC PID here.
http://www.education.rec.ri.cmu.edu/products/cortex_video_trainer/lesson/3-6IntegratedEncoders2.html