Estimating 269 Motor Current based on H bridge models

This should probably go under the existing thread “Estimating motor current” but it contains some information on the effect of different motor controllers on the Vex 269 motor speed. It includes data generated by Excel and Labview H bridge analytical models which were tuned to match scope data posted in the Jpearman thread mentioned above.

See Vamfun blog post.

PS: I attached a prototype function that will calculate 269 average current based upon my H bridge model. Hopefully, Jpearman et all will get a chance to see how it performs.
hbridge current estimate.c (3.77 KB)

Chris

This is very interesting and I will need to read your explanation several times, as well as the original Chief Delphi thread, before I will be able to understand the details.

One thing I see you mention towards the end is the PWM frequency, you imply that a higher frequency will be able to provide a linear response. This is something that can certainly be tested at some point, perhaps even on the cortex by hacking some of the EasyC code, but probably more simply on another controller board. Although I understand the reasoning I still feel that alternative control of the H-Bridge at lower frequencies may be able to produce a linear response, my reasoning is based on some tests I did using the VEXpro controlling the same 269 motor. The data for this was posted here, the PWM frequency is somewhere around 1500Hz so not much higher than an MC29. My theory was that the VEXpro was controlling the H-Bridge differently during the pwm off phase (I mentioned some of this in the “estimating motor current” thread) but I have not proven this, too many other distracting projects.

There is also lots of information at this site H bridge secrets but it’s still not clear to me what the underlying mechanism is.

Anyway, thanks for working on this, it’s nice to know there is at least one other mentor as OCD as me.

Edit: I’ve been reading some of the CD thread from 2009, many smart people posting over there, I have a lot to learn.

I edited the post to add my RobotC current model.

Thanks for the reference. I wish I had it 3 years ago. Anyway, I scanned it enough to learn his terminology.

Based on the Vex curves I see and other FRC controllers I think they would be
his Async Sign Magnitude which uses the catch diodes in the OFF phase of the PWM cycle. This is the model I have been using. For some reason, I have a catch diode fwd voltage of 1.2 volts left over from my JAGUAR analysis. I look at your traces and it seems to be around 1 v but the scale is too coarse to read it very well. Maybe you can help hone in to the correct value.

It is the catch diode that causes the nonlinearity. It can clamp the current to zero for a portion of the PWM off cycle. Any scheme that eliminates the diode from the current path will usually result in a linear steady state speed with duty cycle. Using a PWM period that is very short with respect to the motor time constant L/R effectively does this because the OFF phase current doesn’t have enough time to decay to zero for almost all duty cycles inputs.

As I recall, the JAGUAR is a high side switcher, the Victors are low side switchers. Not sure about the Vex. Doesn’t really matter.

393 data?
I would like to get an estimate of the 393 motor inductance. Do you have the .5 duty, stall curves for that? If not I can estimate it by assuming it is proportional to motor resistance and scale it from the 269 inductance.

OCD is right!!! I have spent too many hours trying to figure out why motors don’t behave as the standard current models would predict. Most of my control studies require a good model and any derived optimal gains are usually off by a factor of two due to motor nonlinearities. I resorted to non-linear models to deal with saturation effects…but even then the motor theory was inadequate. So I think I now have a handle on how a controller changes the standard DC model.

Thanks again for your magical scope work. It sure beats my old AC Heathkit O scope. I am learning a lot from you tireless efforts.

I don’t have this data yet, I only picked up a couple of 393 motors last week and was more interested in comparing them to the data IFI had posted regarding the PTC performance. The motors belonging to our team are all at school, I have no access to them during the summer or any other VEX parts, hence the limited testing of motors under load. I did do a quick comparison of control value against unloaded speed and found it to be very similar to the 269, I would expect the other waveforms for the 393 to also be similar.

Here is the graph of control value against speed for the two motors.

motor_speed_comparison.jpg

I will make more measurements but its going to have to wait for a few days as I’m spending some time in Yosemite next week.

I also read some of the Chief Delphi threads today, interesting reading but I was disappointed that everything was theory with very little in the way of practical tests and measurements. It would have been fun to participate but I guess I’m 3 years late to the party (which looked like a good one with plenty of beer and nautical excursions involved). Here for the benefit of the VEX forum are links to a couple of the most interesting threads.

vamfun’s original thread from 2009.

http://www.chiefdelphi.com/forums//t/cost-benefit-of-third-party-gyros-and-accelerometers/24278/1

and a follow up about 15 months later.

http://www.chiefdelphi.com/forums/showthread.php?t=86733

They reference the Jaguar controller often in these threads which was originally created by Luminary Micro. Texas Instruments bought Luminary in 2009 and sell the Jaguar motor controllers as reference designs, full information for these controllers is available, including the schematics, for anyone interested.

Tan Jaguar
Black Jaguar

Look in the user guide for the schematics.

This datasheet also has some explanation of the different H-Bridge control modes.

Allegro A3941

One of my plans is to purchase a different motor controller that I can test the various types of H-Bridge control that was discussed on CD as well as different PWM frequencies. I will probably use something like this Pololu High-Power Motor Driver 18v25 CS and drive it from an FPGA eval board or something similar.

I will run and compare your code to my earlier simple algorithm, again it will have to wait a while until I’m back from vacation.

Chris, we live in the same town, you are welcome to use my (well technically Panavision’s) equipment if there is anything you want to test.

I did take a quick look at vamfun’s code. I have not compared the computed current to actual current yet, will do that in a few days, however, I did compare to the linear model I had previously used for calculation to the new model.

This graph shows the difference under two conditions, the black line is when the motor is stalled and command value is changed from 0 through 120, the red line show the same thing but with a simulated 50% load, ie. I set the rpm for the simulation to be 50% of the maximum possible speed for the commanded value. The simple current model is the solid line, the revised model the dotted line. I’m not going to draw any conclusions from this yet other than the simple model is overestimating current.

current_estimate_models.jpg

The other thing I did look at was the computational time for the new current_calc_269 function, any time I see calls to “exp” or “log” in embedded code I start to worry as these can be very computationally expensive depending on the processor. It turns out that they are not too bad, the “exp” function executes in about 47uS and the “log” function in about 20uS (self timed using 10000 iterations of a loop, ROBOTC does not optimize this type of test luckily). The complete function executes in 440uS (about 0.5 mS) so if called every 20mS it would be about 2.5% of the processing time available. It can be optimized but as a start its ok as is.

We commonly get the question regarding the relationship between Speed controller switching frequency and the linear or nonlinear output of a speed controller. Switching frequency has a very minor effect on the output linearity.

PWM time period is linear with respect to output duty cycle ,but not linear with output power. The reason our victor and motor controller 29 have nonlinear outputs is that our firmware in those micro controllers did not account for this nonlinear relationship. Newer versions of these controllers will have linear output power vs PWM input when we change the firmware for the next processor production run.

The model that I proposed has a steady state response with the general shape of the test data but key points are not matched with these figures. Specifically the 269 test data shows the maximum speed of around 112 vs the spec 100 rpm. Second is the duty at rpm =0. The test data shows a command or around 8 or 9 counts (duty = .069 to .071) versus a model duty of 15 counts (duty = .12).

There are several parameters that can be adjusted in the model to more closely match this test data.

  1. lamda = T/(L/R) can be increased to more closely approach the Victor 884 curve.
  2. Reduce V_diode 1.2 volts from to 0 volts.
  3. Increase the Battery voltage from 7.2 to 8 volts.
  4. Reduce i_free from .18 to .06 amps while maintaining motor ke constant. This is equivalent to reducing the motor friction while keeping the electrical parameters at spec. n

The waveform test data posted on the estimating motor current thread (duty = .5,stall and duty = .25 non stall) don’t match if 1,2 and 3 are done. In addition to the waveform mismatches also :

  1. changes the shape but not the max speed
  2. Matches the duty at rpm=0 but not the maximum speed
  3. Changes the max speed but doesn’t match the shape .

So this leaves 4).

Attached is the figure and data for the model run with i_free = .o6. This matches the test day very well. It also seems possible that the motor drag tolerance can vary from motor to motor.
Data points are:
CMD DUTY RPM
7 0.059 0
10 0.075 10
11 0.090 20
14 0.107 30
16 0.125 40
18 0.146 50
22 0.172 60
26 0.206 70
33 0.257 80
44 0.346 90
77 0.603 100
127 1 112

So question to jpearman: What battery voltage were these curves generated with? Do you have an average current reading at any point?
vex 269 steady state speed vs duty (i_free = .06 amps).jpg

Not sure I understand this comment relative to your present controller steady state speed vs duty. Althought we don’t have the circuit, it has all the characteristics of a catch diode return path during the OFF phase of the waveform. This leads to a strong sensitivity with frequency as seen by our testing of many controllers of this nature. If you are speaking about the current vs duty, I am with you… the main nonlinearity occurs near the lower currents near the i_free area. My model work confirms the phenomonen. BTW, if anyone is interested , I finally got around to documenting the equations in a recent post:
Derivation of formulas to estimate H bridge controller current (Vex, JAGUAR,Victor) Draft

.

Based upon jpearmans look at the Vexpro… I suspected that you would be changing your controller firmware.

Maybe a bit premature, but are you planning to have two controller types in the field or will you be offering some type of exchange for the 29 controllers.

Any chance you will give us access to controller current in the cortex ports??

We all look forward to the updates.

PS… Looks like I have done a lot of calculations which will become obsolete in the future:) Well, I learned a lot!

We know a little about the circuit.

In this post jgraber has given us the part numbers for the MC29, I confirmed that the FETs are the same ones used in the cortex. So we have P-channel FET (FDS4935BZ) and N channel FET (AO4818B), data sheets are available on the web. The cortex and MC29 drive the pwm pulse to the low side FET (presumably the N-channel), the datasheet shows the diode forward voltage as typically 0.75V (max 1v).

The curves for an unloaded motor would have been done using a small bench supply set to 7.5V. As the bench supply only has a 2A capacity the stalled curves would have been done using a normal 3000mAH VEX NiMH battery. To be honest, i was not concentrating much on the supply voltage as it was just considered to be a constant and not part of the test comparisons.

Not sure how the cortex will be able to be upgraded, the low side FETs are driven by timer4 channels 1 through 4, the high side FETS are driven by port D outputs 3,4,7 & 8 (may have that backwards, need to double check). Don’t see how shoot through can easily be avoided as it’s really needs a uS or two between ending the pwm ON phase and turning on the FET to allow current to flow in the OFF phase. The VEXpro handles all this using the Xilinx FPGA. Anyway, we shall see, perhaps ports 1 & 10 will not be upgraded.

I have some preliminary results from testing vamfun’s code. First of all, this is a difficult thing to measure, using a meter to measure rms current is not sufficient and grabbing waveforms while noting test conditions is really a job for more than one person. Anyway, I will post some results, there will be more later as I’m still working on it.

Test conditions.

I’m using a bench power supply rather than a battery to keep input voltage constant. The PSU is set at 7.3V, due to voltage drop in cables and other places the cortex measures this as 7.21 and I measure 7.2V over a resistor used in place of the motor. The PSU is capable of driving 20A.

I have a motor controller 29 in port 9 of my cortex and I’m using the same 269 motor that I used for previous tests.

First test was to determine the real frequency of the pwm output. As far as I can tell this is 1150Hz (a little lower than the 1250 from the code posted).

Next was to determine what control value would give me a 50% duty cycle from the MC29, as discussed before the MC29 uses a slightly different scaling to ports 1 & 10 of the cortex. Closest I can find is a value of 45, there is quite a bit of jitter on the pwm output so duty cycle varies between perhaps 48% and 52%.

So lets compare the measured current with the 269 stalled with this 50% duty cycle. I had created a spreadsheet to check the calculations and updated the code with the 1150Hz. I have also dropped the diode voltage to 0.75V as this more closely matches the datasheet information.

Theoretical value for current is 1.119A

Here is the first capture

269_50_RPM0.jpg

The yellow trace is current, the blue is the control voltage on one side of the motor wrt gnd. The white overlay is my theoretical curve cut and pasted from the excel spreadsheet and scaled to match the yellow waveform. The scope can measure the average current and shows 1.12A, pretty good !

to be continued…

Some more results.

I was not happy with results from the simulation yesterday, the shape of the measured response does not match the simulation, the current seems to drop more quickly than the simulation would suggest it should. I played around with some of the variables and, although I can not get a good match in every case, I have modified the following

stall current 2.88A (this is more in line with the latest real world measurements)

the new stall current give a motor resistance of 2.5 ohms (yes that’s deliberate), my motor measures at 2.4 ohms.

motor inductance 650uH, down a little from our first guess.
system resistance 0.3 ohms.

Yesterdays 50% duty cycle, stalled condition now calculates to be 1.136A, still close.

using these values I have the following additional results.

75% duty cycle under load (bemf = 3.8V)
calculated current 651mA
measured current 653mA
(ignore the CH2 width measurement, it’s wrong)

Also don’t forget this is low side switching of the H-Bridge so the blue voltage going low is the on phase, the dotted blue cursor is the nominal battery level and you can see the diode voltage slightly above that.

269_75_ex1.jpg

25% duty cycle stalled.

calculated current 484mA
measured current 494mA

269_25_ex3.jpg

25% duty cycle under load (bemf = 3.0V).

calculated current 174mA
measured current 252mA

269_25_ex2.jpg

A little off in that last example but it may also be the scope calculation that is in error. In general I think these numbers are reasonable, the motor does not behave exactly as the model in other respects, sometimes the current waveforms are quite distorted due to mechanical factors. The motor obviously has brushes and a commutator and disturbances can be seen due to these. Here is another example with the motor at 75% duty cycle as in my first example.

269_75_ex4.jpg

Quite different with the current measuring as 847mA, same test conditions just captured on the oscilloscope a few seconds earlier.

And a final example to highlight the current disturbance due to (presumably) the brushes and commutator.

motor running with a 90% duty cycle. I show the simulated waveform in white, the measured current is in yellow.

269_90_ex5.jpg

Final words on this for today.

I took a quick look at the 393 motor, here is a comparison of the 393 and the 269 with 50% duty cycle and stalled.

393_269_50_RPM0.jpg

Fairly similar but the 393 has about a 1A offset (ie. I_0 is 1A in the calculation), I put some solid lines to show the 0A reference for both motors.

I found that that I could get reasonable results with the following numbers in the simulation. There are some issues with the motor PTC changing resistance slowly with higher currents but we can discuss that another day.

motor resistance 1.5 ohms.
motor inductance 750uH

More traces

393 - 25% duty cycle, stalled.

393_25_RPM0.jpg

393 - 75% duty cycle, stalled.

393_75_RPM0.jpg

And the code for the 269 (a simplified version) I was using today with vamfun’s algorithm.

Now back to the Olympics :slight_smile:
motorCurrentCalcV.c.zip (2.1 KB)

I think you just won the gold in the scope olympics!!

Thanks for your dedication to the modeling problem. I’m digesting the data as you post it and will reply after things have settled in my mind.