Tuesday, September 29, 2020

Trash Kart Motor Controller Selection

In the last post I went into some detail about how I converted an automotive alternator into a motor for my go-kart project. The alternator was turned into a separately-excited 3-phase brushless motor and I needed to find a motor controller to pair with it. This ended up being quite a process so here's some things I’ve learned.

Requirements

I needed a 3-phase brushless motor controller to handle the current-switching for my kart. This type of controller is pretty commonly used for hobby projects like R/C cars, planes, and helicopters as well as larger human-scale things like mobility scooters and electric longboards. They are also used for much larger systems like cars and industrial equipment. Given how commonly this sort of a controller is used, it provided me with a lot of options for my application. Some of the requirements I had for my controller were:

  • Since the racing series I was entering put a $500 budget on the karts I had to be careful to keep my costs in line. I was looking for something that cost less than $150

  • Rated to handle 24 or 48 V to match the battery system I was planning to use

  • Rated at least 2 Kw continuous power rating and at least 5 Kw burst power rating to match the performance expected for a kart of this scale

  • 3-phase controller with active braking to match my motor and to relieve stress from my mechanical brake system. Ideally this would be a regenerative braking to push energy back into the batteries to extend life a bit.

The first controller

The first controller I tried was one that I found on HobbyKing (YEP 120A HV). It showed that it was capable of handling my target voltage and current and seemed pretty well reviewed. It met all of my requirements as I had decided them at this point. After soldering it up with battery and motor connections, this controller was able to spin up my motor pretty reliably when testing on a bench.

 

The first setup, with a sneak peak of the kart frame


Unfortunately this controller did not work as well once I had my kart moving. Once the motor had a large inertial load (my body) the controller started to have really serious issues with successfully moving the motor. I did some more research to try and find a solution and I learned that this motor controller was designed and tuned for propeller applications like planes and helicopters which have low inertia and low starting torque requirements. I found out that for traction applications like cars and scooters there were different motor controller and so a new requirement was born:
  • The motor controller should be designed for traction applications so that it can handle low-speed commutation well and provide consistent starting performance

 

Back to the internet for more research!

Enter the VESC project

I was tipped off to the VESC project by my friend Isaak who had encountered them in combat robotics applications. The VESC project is an open-source motor controller and configuration tool which is intended to provide a flexible platform for DIY projects needing a 3-phase motor controller. It was pretty commonly used by people building e-bikes and electric longboards, so it seemed like it would work for my kart and it met all my requirements so far. 

 

Since this is an open-source hardware platform there are genuine controllers that can be bought from Germany for $$$, and there are cheap Chinese clones that have dubious quality and much lower price tags. Since I was on a budget I went for a cheap clone, specifically the “FlipSky Mini FSESC 4.20” which is based off of hardware version 4.12 of the VESC project. This was basically the cheapest VESC clone I could find, but it’s pretty much hardware and software compatible with the reference controllers. 

 

Learning how to configure the VESC controller to optimize performance and get good input control is something that I’m still working on, but getting the controller working at a basic level is pretty easy. The configuration software has a lot of helpful information about every setting and button. As a bonus the VESC controller can be set to have both cutoff current and voltage limits, which can help protect batteries and also make sure I stay within the electrical power limits defined by the racing series. 

 

After wiring this controller into my system I was able to get the kart performing at a decent level for the first time. It was often able to get going from a stand-still without stalling, and I was able to get the kart all way up to its top speed (~20 mph) as long as I was easy on throttle. I ended up having an issue where the controller would fault and cut out if I pushed the throttle too fast and it would have to reset before moving the motor again. It seemed like I was tripping a current sensor or dropping too much voltage on a component, but I really couldn’t find the root of the issue. I figured that since the alternator was a lot larger than the sort of motors other people were usually using with these controllers I was probably just pushing it past its intended capabilities. I was pretty hooked on the configurability of the VESC at this point, so it was time to go for a more expensive version.

Make it bigger!

The VESC project has another common hardware version other than the 4.12; the VESC 6. This version brings a variety of improvements, but the big thing seems to be having current sensing on all three phases, instead of just two. The VESC 4.12 uses #math to estimate the current in the third phase, but the VESC 6 can directly measure it, which allows for improved control and higher current sensing limits. I figured that a new and improved version of the controller would help me out, so I purchased a cheap(ish) clone online.

 

This motor controller was quite a bit more expensive than the mini one I had been using, but if it solved my performance issues then I would be able to make it work for my budget. Just like before, I wired the new controller into my system and got it calibrated and programmed using the VESC software. On the first test runs this controller showed a great improvement in performance compared to the mini VESC; it was able to generally run at high performance without cutting out much. This was the first time I really got a feel for the acceleration that my kart was capable of, and it was FAST. 

 

I was still having some issues with startup on the kart, with the controller sometimes losing track of the motor position and squealing, or failing to start entirely, creating a “cogging” motion that is somewhat common for brushless motors.

 

 

Hall sensor addition

The go-to solution for startup issues on brushless motors is to add sensors. When running without sensors a controller uses the back-EMF to estimate the position of the motor. Back-EMF is generated by the motor when the magnets move past the coils, but by definition this only works when the motor is moving. To get a motor moving without sensors, the controller will dump a lot of current into the motor and try to force the magnets to start moving so that it can sense where they are, but this can lead to “cogging” where the motor doesn’t move enough for the controller to get a reading.

 

Sensors will tell the controller what position the motor is in at all times, allowing it to consistently start and provide maximum power at all speeds of the motor. The VESC supports the two most common types of sensors for hobby motors: digital encoders and Hall-effect sensors. I would be retrofitting my alternator with these sensors so I decided that adding Hall-effect sensors would be the easier integration. You can check my last post for more details about this installation!

 

After adding the sensors to the motor I was able to detect and calibrate them with the controller, and like magic my kart had excellent off-the-line acceleration and consistent low speed torque. I was able to stop on my driveway and then drive up it, without any problems! Now that performance was acceptable, I wanted to find a way to integrate a reversing functionality into my kart.

Writing custom firmware

Adding reverse to my kart was an important competitive feature; if I got turned around on the track or ran into a barrier, being able to get back in the race without dismounting from my kart is a BIG deal. And the VESC did have some built in control schemes which included reverse functionality.

 

Unfortunately there wasn’t an existing control scheme that gave me my desired control scheme. I wanted one throttle which would cause the motor to brake when released and accelerate when pulled, with a switch which would reverse the direction of the acceleration. There were similar features spread out amongst the control schemes but no single existing scheme that had all these features. Luckily this was an open-source project so I learned how to modify, build and save the firmware to the controller, and modify and build the configuration software to handle the new control scheme. All told it was probably 5 or 6 lines of code mostly copied from stuff already existing on the controller. It all seemed to work fine so I added pull requests on GitHub and I am now a contributor to the VESC project!

Releasing the magic smoke

About two weeks before my first race with the kart I drove it to work to give it a real stress test, and to show it off to my coworkers. This was in early June, and it wasn’t a particularly warm day but the sun was pretty intense. I ended up pausing for about 10 minutes on my way to work to give the components a chance to cool down mid-way. 

 

At work I charged my batteries back up, then took the kart out to the parking lot to let my coworkers take it for a spin. They were very excited and it was performing well, and then there was a puff of magic smoke and my motor controller was dead. It turns out that the VESC 6 variant I had purchased had an anti-spark circuit on it, which I had been bypassing, and after some extended use that system burned out. 

 

With a very short window to my race and no spare motor controller I had another one (with a real anti-spark switch) rush shipped to me. Once I got tracking information the delivery window was forecasting an arrival on the day that I had to leave for Kansas, so I started to scramble for another solution since that probably wouldn’t turn out.

Maybe smaller is good enough?

In desperation I turned back to the smaller, cheaper VESC 4.12 clone I had purchased earlier and then abandoned. Now that I had learned more about the configuration tool *and* I had added sensors to my motor, I was hoping that I would be able to get acceptable performance out of the smaller controller. I plugged everything in, and it worked! Mostly…


I set a lower current limit to help protect the smaller, cheaper motor controller. I also learned that the pins on the controller to switch from forward to reverse were in slightly different spots, so I had to make an adapter for my switch to shuffle the wires around. But the little controller performed admirably, almost meeting the expectations set by its next-gen brother. It still had some issues with cutting out occasionally, but it was good enough to get me moving and hopefully not burst into flames.

 

The replacement VESC 6 ended up arriving early the night before I was leaving, so I soldered and programmed it and threw it in my car along with the already-packed-up kart to be installed once I got to Kansas.

Bonus: powering the separately-excited rotor

My original plan with the alter-motor was to vary the current in the rotor in order to change its magnetic characteristics while driving. The idea was to create a sort of "shifter" like you'd find on a car, so that I could increase the magnetism of the rotor for low-speed torque and decrease it for an increase in top speed. 

The current controller. It's a pretty sizable chunk, but it's more reliable than everything else

This ended up being a fruitless idea for me. Perhaps as a whole research project of its own I could learn how to do it, but I found that when I tried to reduce the rotor current the motor controllers would have issues. I ended up buying a nice constant current controller for the rotor so I could set the desired current and then rely on it not to change as the batteries drained.