Today some code we developed for the VESC platform was merged into the master branch, reaching thousands of current VESC users.
Motor simulation inside the firmware is a critical step in our path to having the greatest controller out there.
- It help us to develop new control algorithms. For example Field Weakening, MTPA (Maximum Torque Per Amp), new flux phase observers, etc, without risking to damage expensive hardware.
- It opens the door for deeper automatic testing. We are now a script away of being able to check that the code can actually run a motor. It sounds easy enough, but with many commits getting merged, and so many hardware configurations to support, this kind of hardware in the loop will detect problems way sooner, and way cheaper!
It runs in cpu time, you can halt the debugger, take a look, and resume operation. Or you can perform slow code coverage tests to ensure you have exercised all the lines in your code, often required by some industries.
Here is a screenshot of a motor startup being simulated:
The virtual motor is modelled as an IPM machine, and is engaged from the VESC Terminal inside the GUI.
More details in our Pull Request
The other piece of code we authored is Sin/Cos encoder support. These encoders provide absolute rotor angle feedback, no need to wait for indexes. They provide 2 sinewaves in quadrature, and by reading that signal the code can calculate the rotor angle.
Medium power motors are commonly using this kind of feedback. Zero bikes use them for example.
Here is the signal input:
And resulting phase measurement: