I am working on using the debug stream to monitor my motor speed. I borrowed a fwcalculatespeed function from jpearman’s flywheel.c program like this:
void
FwCalculateSpeed( fw_controller *fw )// THis function calculates speed and passes ???
{
int delta_ms;
int delta_enc;
// Get current encoder value
fw->e_current = FwMotorEncoderGet();//assign e_current the current encoder count
// This is just used so we don't need to know how often we are called
// how many mS since we were last here
delta_ms = nSysTime - fw->v_time;
fw->v_time = nSysTime;
// Change in encoder count
delta_enc = (fw->e_current - fw->e_last);
// save last position
fw->e_last = fw->e_current;
// Calculate velocity in rpm
fw->v_current = (1000.0 / delta_ms) * delta_enc * 60.0 / fw->ticks_per_rev;
writeDebugStreamLine("Time: %d RPM: %d", fw->v_time, fw->v_current);
wait1Msec(30);
}
I am using turbo motors and the appropriate ticks per revolution. I expected to see rpm values at full motor power around 200-240 rpm. Instead, the values maxed out around 100 rpm. My debug stream data is attached. Am I wrong in thinking my output from the above calculation should be just short of a 240rpm no load speed?
//encoder counts per revolution depending on motor
#define MOTOR_TPR_393R 261.333//counts per rev for standard (torque) geared motor
#define MOTOR_TPR_393S 392 //counts pre rev for speed geared motor
#define MOTOR_TPR_393T 627.2 //counts per rev for turbo geared motor
After reading the documentation on the IME, looks like the counts per rev for torque and turbo need to be reversed.