Re: Shooting ball With RPM

It appears that you posted the original thread in the official Vex Tech Support area, 9364F.
Anyway, the launch of a ball causes the flywheel’s rotational velocity to decrease (negative acceleration). Because acceleration is calculated as the difference between two velocities divided by time (time can generally be ignored for our purposes, assuming the Cortex doesn’t experience a lot of lag), compare the current velocity to the last sample. The code that makes this comparison would end up looking something like this:


if(speedRpmLast - speedRpm > threshold) {
  //Ball has been shot
}
else {
  //Ball has not been shot
}
int speedRpmLast = speedRpm;

Where would I get the threshold from?

Just testing. Start with some random number, and see if it works. You can increment a variable in your if ball shot block, and compare the number of shots the robot actually took to what it says it did. If the robot says it shot more than it did, then you need to raise the threshold, and if the robot says it took fewer shots than it actually did, then the threshold needs to be lowered. You can also save five samples to an array called, say, rpmNoShots[5], and then see what the difference between the samples is. This number, plus five, perhaps, can function as a starting point for your testing, and may actually work fine.

I actually just did this the other day. Here is the code I used to do it.


                oldReadingR = SensorValue[launchRE];
		oldReadingL = SensorValue[launchLE];
		wait1Msec(20); // this is the wait at the end of the while(true) loop
		newReadingR = SensorValue[launchRE];
		checkDiffR = newReadingR - oldReadingR;
		RPMR = (checkDiffR / 7.2) * 60;
		
		newReadingL = SensorValue[launchLE];
		checkDiffL = newReadingL - oldReadingL;
		RPML = (checkDiffL / 7.2) * 60;
		clearLCDLine(1);
		displayLCDString(1, 1, "L: ");
		displayLCDNumber(1, 3, RPML); // display left RPM
		displayLCDString(1, 8, "R: ");
		displayLCDNumber(1, 11, RPMR); // display right RPM
		SensorValue[launchLE] = 0; // reset encoders
		SensorValue[launchRE] = 0;

The only wait I used was the one put at the end of the while(true) loop, put after all the code. This also displays the RPM of the two sides on the LCD. Make a PID loop with the requested RPM’s for the target instead of a sensorValue.