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:

Here is the Pull Request, and the line of code that calculates the angle
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
How I can change simulate external force affecting virtual motor? I'd like my control loop see pos changing.
Are you sure? yes | no
Hi Axiom,
I'd like to write custom control loop for VESC FOC mode.
I'd like to start writing and testing my control loop using virtual motor. Please help me a bit with example of using virtual motor and custom control loop like here: http://vedder.se/2015/08/vesc-writing-custom-applications/
I have to set motor current depending on absolute motor position.
Thanks for any help.
Are you sure? yes | no