Saturday, August 29, 2020

VESC (motor controller)

In a new attempt at Field Oriented Control, a VESC (Vedder Electronic Speed Controller) drove the Firefly's motor wheel for the past 500 3000 or so km.  As before, wiring up the new controller took some effort, but this one is more satisfactory.

Positive:
  • Software and firmware are open source.  It was easy to add automatic "cruise control" that saves thumb strength.  After 7 seconds of holding the right throttle high, it stays high until brake is applied.  The system is experiment-friendly.
  • The right throttle drives forward.  The left throttle brakes and drives backward. [customized code from district9prawn].  Now there is a good balance between left and right thumbs.
  • Custom features can be programmed such as a limp-home mode in case of throttle / brake-sensor failure.  Safety checks (i.e. full engagement of the attachment clamps) can also be requested through the phone app before enabling higher speeds (some programming required).
  • Torque-control is sweet.  No more annoying braking due to minor unintentional throttle movements.
  • FOC is super smooth.
  • No violent synchronization jerk when reengaging the throttle after coasting.  This may stop has stopped self-loosening of the axle nuts.
  • The phone app logs data from the controller, inertial unit, and phone GPS (10 Hz rate).
Notable:
  • Parameter settings and speed display are through Bluetooth and a phone app (screenshot below).  This allows for nice graphics and on-the-fly adjustment, but sunlight readability is low. The controller also runs fine without the phone. 
  • The VESC 6 is spec'd for 60 V max, which doesn't allow for common 48 V (13S) e-bike batteries.
    Update: A 48 V (13S) battery does work.
  • No headlight connection.  I had already been using a Cateye AMPP800 that is brighter than the stock headlight (which I removed).
  • The VESC firmware code is complex and only sparsely documented.
Issues to be addressed:
  • Weatherproofing.  As is, the controller is unlikely to survive a rainstorm and needs a protective enclosure.
  • At above-normal speed (e.g. descending a hill), the motor brake can kick in very hard, possibly blowing the battery fuse and causing other damage.  I can probably avoid this by modifying the firmware.  For now I have to avoid the motor brake when coasting fast downhill.
  • No odometer.  This is important for periodic maintenance.  I keeping a spreadsheet that adds up individual trip distances added this feature to the code.  


The VESC (which has threaded mounting holes) attaches to the battery base via two M5 screws after drilling matching holes in the base's metal bottom plate.  After a bunch of wire splices, the motor connects to the Z910 cable and the Firefly signal harness to a hard-to-find 9-pin JULET connector (JL-F-Z911AT, Thanks Mr. Wen!).  By keeping the original JULET connectors, I can easily swap back the stock controller which sits in a different battery base.  For VESC, the battery connects through yellow anti-spark XT90 connectors (I still got occasional sparks).  On top is the Bluetooth comm unit with dangling gray antenna.

 


October 16, 2020 Update:

A sturdy clear lid with overhang now protects from rain and shows LED status.  The other main ingredients were an L-bracket that clamps to the VESC via the threaded M5 holes (lucky fit), and longer M6 screw for the fork.  Some cable junctions and the Bluetooth module can still get wet, but at least the main controller is shielded.  As they say, the perfect is the enemy of the good.







Wednesday, August 19, 2020

Disc brake

Alas, sometimes we must stop.  The disc brake has good strength, but often caused strong brake judder that seemed to get amplified by a resonance.  At times, it felt like riding a washing machine full of bricks during spin cycle.
😰
A long-ago attempt at improvement involved swapping the stock brake caliper with an Avid BB7 MTB, but that just made the brake noisier.  Women would turn because they thought someone was whistling at them, but it was just brake squeal. 
😗
More recently, I replaced the brake rotor (140 mm diameter) with a $10 "ZENO" part.  This rotor, together with new "Resin Organic Semi-Metal Brake Pads" make the brake smooth and quiet.  After installation, I bedded-in the new pads and disc.  Now there's no more judder or brake squeal!
😇
The original disc was a little warped, and I suspect it had periodic variations in braking friction that got amplified in a flexing resonance.  The resonance seemed to get worse with front tire deflation.

Thursday, June 4, 2020

Field weakening

The Firefly's wheel speed is limited by the voltage produced as the permanent magnets move across the motor coils (Faraday's law of induction).  The faster it spins, the larger is the induced voltage, which eventually equals what the battery can produce.  Then current and torque drop to zero, and the maximum speed has been reached.  For this reason, a fully charged battery with higher voltage can go faster than a depleted one.

I have been experimenting with Field-Oriented Control which, among other advantages, can use the motor coils to generate fields that counteract the fields of the spinning permanent magnets.  The technique is known as Field Weakening.


My tests with TI boards (LAUNCHXL-F28069M and BOOSTXL-8323RS) show a speed-up of up to 38 % compared to the original motor controller.



Original data where Kv0 = 10.46 rpm/V is the measured speed of the original controller:

VsupplyIsupply
(A)
Speed
(rpm)
Kv
(rpm/V)
Kv/Kv0Field
weakening
(A)
32.230.9135010.861.0380
32.230.97371.111.511.1002.5
32.231.24394.612.241.1705
32.231.67422.213.11.2527.5
32.231.75431.613.391.2808
32.231.944113.681.3088.5
32.232.3546614.461.3829.0
The data were taken on a stationary test stand, where the wheel just spins in air.  It's not ready for vehicle testing yet.


Monday, May 18, 2020

Attaching the Firefly

I consider the Firefly's levered attachment mechanism a marvel of mechanical engineering, but it took a while to find a way to engage it without assistance.  Here are my steps, which use the front and rear brakes simultaneously to hold the wheelchair front up without needing to constantly push.  This makes it easier to flip the attachment levers.
  1. Roll up to the Firefly, which is standing upright in a corner with its parking brake set.
  2. Grab the handlebar and release the parking brake.
  3. Roll the Firefly back towards the chair while centering the attachment hooks on the pins. 
  4. When the hooks are well-centered, which takes some experience, engage rear wheel locks.
  5. Push handlebar forward all the way to lift front casters into the air* and further engage the hooks.
  6. Squeeze the Firefly brake.  If the brakes are tight enough, the wheelchair and Firefly will hold the raised-front position, even if you stop pushing the bars.  If the front of the wheelchair doesn't stay up, tighten the front or rear brakes, or inflate rear tires.
  7. With the right hand squeezing the front brake, use the left hand to flip the left attachment lever forward.
  8. Set the parking brake, switch hands, and flip the right attachment lever.
  9. Release the brakes and push the handlebar forward to make the attachment pins seat all the way into the hooks.
*Sometimes, the wheelchair front does not lift very far in Step 5, and I have to recenter the the front wheel/hooks and try again.

These steps apply to the 4-pin attachment mechanism (two on each side of the wheelchair).  They can be adapted to a Firefly without parking brake.

Thursday, April 23, 2020

3000 km, KT-LCD3 display, etc.

Spring flowers are blooming, the sun is shining, and I've started putting distance onto the Firefly again.  It's important to get outside, despite the many warnings about COVID-19 from politicians and public health busybodies.  Their science is tentative and fraught with conflicts of interest, and their claims - hypocritical as they may be - of valuing safety above all else do not reflect my values.  Fear, i.e. focusing on worst-case-scenarios, is a choice that I reject.  Life is for living.

I'm using a new KT-LCD3 display, which works as a drop-in replacement for the original KT-LCD5 after setting the various parameters.  The LCD3 shows power in Watts, which maxxes out at about 550 W for me.  I really wanted to know the maximum power.  The display also shows ambient and motor temperature, but unfortunately the motor field does not measure anything, and the ambient value is inaccurate.

Update: After this post I reverted to the original LCD5 display and spooled the LCD3 odometer distance onto it, using the documented communications protocol.



Together, the old (2730.5 km) and new (273.6 km) odometers add to 3004.1 km and 286.1 hours for the following statistics:
  • 2 years ownership
  • Several hundred trips enabled by the Firefly
  • Scores of friendly compliments
  • 10.5 km/h (average speed)
  • 3 worn out front tires (current one seems like a winner)
  • 2 significant mechanical issue:
    • Loose axle nut
    • Shims for the wheelchair frame attachment are slippery.  If used, inspect regularly and check bolts for tightness.
  • 3 tip-over accidents (sideways)
    • Turning onto an uphill ramp.  Too much speed and off-camber.  Kind bystanders tipped me back up.
    • Riding up a steep and narrow temporary ramp, losing traction near the top, fishtailing backwards, and tipping over the side.  Relying on momentum rather than traction to get up steep slopes is dangerous.  The result of not reaching the top can be an extended loss of control, because sliding friction is less than static friction.  Rear wheel braking could help, because the rear wheels have a lot more traction (but engaging them while moving backwards could make the vehicle flip).  Reversing up steep slopes can be safer.
    • While going around an illegally parked truck.  Always cross drop-offs at a perpendicular angle, even when annoyed.
  • 1 empty battery (later replaced with a larger one)
  • 1 flat rear tire (from a thumb tack)
  • 1 flat front tire
  • 0 collisions
Tip-over accidents are a recurring theme, because any safety gains due to skill and experience seem to be cancelled out by higher speed and reduced caution.

Tuesday, September 24, 2019

New motor controller

The Firefly's motor controller (pictures below) energizes the motor coils in the right sequence to move the wheel according to the throttles.  It sits in the battery base and appears to be a variant of the S06 controller (schematic here) with second (reverse) throttle input.


For the past 65 km, I've been testing the more advanced Baserunner controller from GRIN and ASI in Canada.
Firefly with Baserunner taped to the side of the 11.6 Ah battery.  The rat's nest of wires near the bottom allows it to function (no speed display, headlight, and brake cut-off though) and the toggle switch between the handlebar and LCD selects forward/reverse direction.

The Baserunner is a lot smoother than the original controller due to its Field-Oriented Control algorithm, which the physicist in me appreciates.  FOC also allows about 15 % higher speed, and the Baserunner can integrate with higher voltage batteries to go even faster.

Other impressions:
  • Makes the motor nearly silent, but the controller emits a slight high pitched whine.
  • Torque-mode control is nice.  
  • While maintaining speed at low torque, there is often a bit of chatter between zero and a little torque.  Perhaps my thumb is unsteady on the throttle.
  • Sometimes the motor stutters when starting to move.
  • Re-engagement is much smoother.  The old controller often gave a nasty kick when re-engaging the throttle after coasting (while still moving), but Baserunner re-engagement is silky smooth.
  • I disabled regenerative braking and just use the mechanical brakes.   The efficiency cost is minimal, and this will be easier on the axle and dropouts, because motor torque reversal is much less frequent.  I dislike how the original controller applies motor braking for every little throttle decrease, because I generally want the Firefly to  pull forward (or push backward) when pressing the throttle and will pull the brake levers to slow down. 
Although the Baserunner has a Z910-type connector that the existing motor plugs into nicely, the rest of the Firefly doesn't connect so easily.  I obtained a special 9-pin JULET connector pigtail (JL-F-Z911AT, Thanks Mr. Wen!) to interface the Firefly signal wiring harness with the Baserunner's modular connectors, but there is only one throttle input and an extra toggle switch is needed to reverse direction (this reverse signal required customization at ebikes.ca because standard Baserunners do not expose it).  The Baserunner also doesn't communicate fully with the handlebar LCD and has no headlight connection or brake cut-off.  I've been customizing a microcontroller to address these shortcomings (and add new features), and will update the blog when there is more.

Update (10/30/2019): The Baserunner expects an extra 4th Hall sensor (that the Firefly motor doesn't have) to output speed information.  I'm moving on, to try a different Field-Oriented Controller (controller & driver).

Wednesday, July 10, 2019

RPM measurement

I wanted to check motor speed (revolutions-per-minute or RPM) independently of the built-in speedometer.  For this, the Firefly can be laid horizontally on a bench with the wheel free to move.  A video camera records the movement and white tape around half of the wheel eases analysis.


Video processing (via Octave) yields a graph of the speed:
The raw signal is the average pixel brightness in a rectangular region covering the tire, for each video frame (60 Hz frame rate).  This signal is shifted to have near-zero mean (blue curve), and the zero-crossings (red dots) are found.  Two zero crossings correspond to exactly one wheel rotation, and their time-difference determines motor speed (RPM). For 36.0 V the no-load speed is 383.7 rpm.

During this test, the battery produced 36.0 V, and the display showed 21.8 km/h.  This implies a wheel circumference of 21800/383.7/60 = 0.947 m, which is only one percent less than my measurement of 0.958 m.  Conclusion: The built-in speedometer is accurate.

Analysis code

The motor (probably a high-RPM, 12" wheel version of the Q100 at BMS battery) contains 16 poles (8 pairs) and has a reduction gear ratio of 8.2.  Confirming these numbers is that parameter P1 = 131 in the LCD setup (8.2 x 16 = 131.2). Therefore, the commutation speed or eRPM for a fully charged battery is 8*8.2*383.7*41.8/36=29200.