Log in

View Full Version : Scaling


ForgottenSalad
27-03-2006, 02:37
Small question, as I've forgotten how to scale the PWM output for a half speed switch, quarter speed, etc. How would I have to modify the input assigned to the pwm for adjusting the speed?

By that I mean what I would have to add to the pwm01 = p1_y;

Thanks,
-Mike

Greg Ross
27-03-2006, 03:20
Small question, as I've forgotten how to scale the PWM output for a half speed switch, quarter speed, etc. How would I have to modify the input assigned to the pwm for adjusting the speed?

By that I mean what I would have to add to the pwm01 = p1_y;

Thanks,
-Mike
Try this:
pwm01 = ((int)p1_y - 127)/2 + 127

P.S.
I threw in the (int) because I don't remember if p1_y is defined as a signed or unsigned char. If it's unsigned, it wouldn't work without.

Cuog
27-03-2006, 10:05
I would do the same thing as above but i would use (signed char) instead of int in the casting since it will be less memory intensive and faster(yes im all about optimizing code)

SoftwareBug2.0
02-04-2006, 20:25
I would do the same thing as above but i would use (signed char) instead of int in the casting since it will be less memory intensive and faster(yes im all about optimizing code)
Wouldn't you need to change the 127's to 128's to make that work right?

TimCraig
02-04-2006, 21:57
By that I mean what I would have to add to the pwm01 = p1_y;


You need to provide a "transfer function" which will convert the joystick setting to PWM output for the Victor speed controller. It could look something like the following:

pwm01 = PctSpeedToPWM(p1_y);

Be advised that the response of the Victor speed controllers is HIGHLY nonlinear with respect to the PWM input values. From my tests, it's essentially exponential, that is, linear when plotted on semilog paper. The actual curve is dependent on robot weight, wheel friction, drive train friction, etc, so your mileage may vary. On our robot we get about 90% of speed at 44% of PWM range. I've attached a picture of the measured data.

On our robot, we use table of points forming a piecewise linear function that is interpolated. This allows much greater sensitivity under joystick control than using the straight IFI default code method you currently have. By playing with the transfer function, you can make the robot speed linear (or very nearly) with respect to the joystick. Biased so that it's less sensitive at low speed, for instance doing fine aiming in this year's game or tweaking putting a tetra on the goal in last year's game. Or it could be twitchy at low speed and have more sensitivity at high speed if you need it.

Joe Ross
02-04-2006, 22:08
Be advised that the response of the Victor speed controllers is HIGHLY nonlinear with respect to the PWM input values. From my tests, it's essentially exponential, that is, linear when plotted on semilog paper. The actual curve is dependent on robot weight, wheel friction, drive train friction, etc, so your mileage may vary. On our robot we get about 90% of speed at 44% of PWM range. I've attached a picture of the measured data.

The following thread goes into a lot about why the graph looks like that. http://www.chiefdelphi.com/forums/showthread.php?t=31903&highlight=victor+non-linear

The following graph shows the response of the speed controller when connected to a purely resistive load (and is linked towards the end of the above thread). http://www.saratogarobotics.com/php-nuke/modules.php?name=Content&pa=showpage&pid=1. The response of the Victor speed controllers is linear in the range that IFI designed it for: http://ifirobotics.com/forum/viewtopic.php?t=317. The problem is that you are driving a non-linear system.

TimCraig
02-04-2006, 22:27
We had intended to try the Victor with a purely resistive load but didn't have time before we had to go to "build" mode. :D Seeing that plot leads me to believe that the source of the nonlinearity is the back EMF from the motor. If your turn the shaft on a DC motor, it turns into a generator. When you drive it as a motor, it also acts like a generator, however, the sense of the voltage is inverse to the supplied voltage. This is why stall current is the maximum current the motor sees and then drops with speed. It could also be that speed is proportional to power and power it proportional to Voltage squared or Current squared.

I've also noticed a lag in seeing the motor start after an output is applied to the Victor and hence the motor. I've yet to do the experiments to determine if it's in the Victor repsonding to the input or if it's the rise time of the magnetic field in the motor.

KenWittlief
02-04-2006, 23:22
The following thread goes into a lot about why the graph looks like that. http://www.chiefdelphi.com/forums/showthread.php?t=31903&highlight=victor+non-linear

....

Joe - you are cruel! I read through all 5 pages of that thread from last year, and my head is still spinning :^O

I think I can summarize and answer TimCraigs statement concerning the linearity of the Victors:

1. The Victors output a constant 12VDC that is pulse width modulated. The frequency of this variable duty cycle square wave is 120Hz.

2. You cannot measure the DC equivalent voltage level with a standard DMM or analog voltmeter - you need a true RMS meter (like a Fluke 87). Many people who experiment with free energy motors and generators fall into this trap - they created PWM square wave power circuits and then measure the voltage with a standard (averaging) DMM, and think they have invented perpetual motion. Average voltage is only equal to RMS voltage with a perfect sine wave. For anything else you need a true RMS meter.

3. The speed of the motor is dependant on several factors, including the load. If you measure input command against motor speed, you will get very different results if the motor is unloaded or fully loaded (to its spec'd HP output). Part of the reason is the 12V square wave PWM drive from the victor. The short pulse acts like its kicking the armature for a fraction of a millisecond at low output values. If the motor is not loaded that short kick gives it enough inertia to keep spinning until the next kick (8mS later).

So the bottom line is: if you want to measure output voltage of the Victor you need a true RMS meter, and if you want to plot Victor PWM input against motor speed, the motor must be fully loaded to get the most accurate result.

The duty cycle, and therefore the RMS output of the Victors is linear with the input PWM values. The thing you are really controlling when you vary the PWM command to the Victor is not the speed of the motor, you are controlling its torque (rotational force). The resulting speed from that torque depends on the load.