IPM Motor Simulation and FOC Software

Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

I'd like to move away from needing to change the gui whenever parameters change so am thinking about changing it so that the user can enter say any 10 parameters by name and then edit them from the gui.

The main issue with this is the sim would need to call the standard Openinverter param::change function whenever a value changes. Unfortunately this is currently in the same file as Openinverter's main and I doubt Qt will be very happy having two mains!

Would it be possible to move param::change into a param_prj.cpp file in the standard OI build to avoid this?
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1025 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Not a bad idea, want to PR?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Had a bit more of a think about this and have decided that the current gui could really do with a proper update, the fixed OI parameter fields were nitially quick to do but are now too inflexible and too easily broken by OI code changes. The above idea goes some way to fixing, and the param::change move will still be needed, but I think there is a better solution.

The plan now is to change the OI parameters section of the gui to show a collapsible tree view of the full OI parameter set in much the same way as the OI web interface. This will allow full access to any current or future parameters. The downside is it also exposes a lot of the parameters that are irrelevant to the simulator but the collapsible view should help with that. I'd also like to get the parameter description to show in tool tips if possible (if not it will go in an extra column).

While doing this I'll also add a json parameter import and export using the same format as the web interface functions to make it easier to transfer setups between real installs and the simulator configurations. Probably also make it so that it automatically loads the last json on startup to avoid having to edit the param_prj.h file too.

The last change will be to add import and export for the motor parameters, again using the json format, and the creation of motor files for the common motors (Leaf, Outlander, MGR, etc) to make it easier to switch between setups.

This is probably going to take a few weeks to get to though so in the meantime I suggest sticking with 5.24 for simulation.

Edit - Might not be as big a job as I first though, just had a quick play with the Qt QTreeView widget and it does most of what's needed (even the tooltips!) :
QTreeView.png
QTreeView.png (13.72 KiB) Viewed 7431 times
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

There is now a new build of the simulator on the "combined" branch. This supports both F103 and F405 builds so will hopefully simplify my life maintaining it in the future.

This should be a bit more robust to changes in parameter definitions in the OI project. Instead of having specific parameters bought out on the gui it now displays all parameters in a tree view, this means that the gui shouldn't be affected by OI parameter addition, removal or name changes.

The new interface looks like this:
SimV2.png
Any field can be edited but only the low level ones will affect the simulator (most of the Motor and Testing ones, a few from Inverter and throtcur).

The Vehicle and OpenInverter panes are now completely independent of each other.

The Vehicle fields, Torque Demand, Mode and Direction are still persisted between program runs.

The OI parameters are initialised from the OI project param_prj.h file on program start. Either edit this file to suit your defaults or use the new Load button to re-initialise them.

Buttons have been added to allow parameters to be saved or loaded.

The OI parameters buttons use the same format as the web interface so should be compatible (although warnings will occur if moving between different OI versions with different parameter sets).

The Motor buttons just load or save Lq, Ld, Rs and Flux Linkage. The idea is to generate files for each of the common motors but that will have to wait till another time.

@johu - at the moment Param::change is in a params_prj.cpp file in the Qt build directory. There are a couple of issues to sort out with the CAN class access so I haven't tried to integrate it into the OI build. Once that's done though it should be possible to just delete the Qt version of the params_prj.cpp file and use the one in the OI project instead.

This version will work with 5.24R but does need one line editing so for the moment if you want to simulate 5.24 stick with the main branch version of the simulator. The combined branch version of the simulator has been tested with 5.27R and will be pushed to main once the changes have been made to the OI firmware.
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

The lack of persistence on parameters was bugging me so now fixed - it saves all the parameters to a .paramPersist.json file on closing and then reloads them on opening.

While there I also made it remember the last path used for loading and saving json files and added persistence for the torque, mode and directions fields (somehow missed them before).

Have also added a subdirectory containing the motor parameters that have been found to date using the calculator viewtopic.php?p=52763#p52763

If anyone wants to post inverter parameter sets that they have found to work well with specific motors on the simulator I'll add them too.
User avatar
rstevens81
Posts: 353
Joined: Sun Dec 22, 2019 10:36 am
Location: Bristol, UK
Has thanked: 23 times
Been thanked: 92 times

Re: IPM Motor Simulation and FOC Software

Post by rstevens81 »

Really sorry pete .... idiot alert!!!

I'm getting the following error trying to compile ....
qt.png
i'm assuming i don't have a (string) module installed here are the modules i have installed any ideas which one it might be in.
qt1.png
qt2.png

Many thanks in advance on this, when we work out what it is ill update wiki :)

PS i know how much of pita this is.. all i can say is thank you for all you have done.
qt3.png
Rule 1 of EV Club is don't buy a rust bucket....
Which rule does everyone forget 🤪
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

No problem, thanks for testing it.

Think I might know what that is, saw something similar yesterday but the proper fix needed a few dozen references to an enum to be changed that conflicts with one defined in the libraries. Thought I'd found a quick workaround but obviously not!

Need to update my Qt version! Got a new SSD waiting to go in the PC so that I can put a newer OS but not got round to it yet :(
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Just pushed a fix up to github, let me know if it helps?

Should have done it that way to start with, far quicker to do than I expected!
User avatar
rstevens81
Posts: 353
Joined: Sun Dec 22, 2019 10:36 am
Location: Bristol, UK
Has thanked: 23 times
Been thanked: 92 times

Re: IPM Motor Simulation and FOC Software

Post by rstevens81 »

OK got it working....updated my qt whilst i was there ...

i got an error

Could not load the Qt platform plugin "xcb"

but managed to fix this following https://github.com/NVlabs/instant-ngp/discussions/300 (google is your friend)

if anyone else is running linux could they have a go... im one of the oddballs that like LTS OS' (debian) if its a repeatable error ill add a note in the wiki, however suspect it might be very os speciffic.

edit: yes code fixed it (first bug,second bug was qt)
Rule 1 of EV Club is don't buy a rust bucket....
Which rule does everyone forget 🤪
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Glad you got it working :)

Just to clarify did the code change fix the first bug and then the environment variable fixed another bug that was introduced when updating Qt?
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

just tried to build with current sim and current oi firmware, was hopping to simulate the different id and iq ki gains, but just get build errors like:

Y:\home\steve\IPMMotorSim\IPMMotorSim\mainwindow.cpp:141: error: 'curkp' is not a member of 'Param'; did you mean 'curki'?
..\IPMMotorSim\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
..\IPMMotorSim\mainwindow.cpp:141:65: error: 'curkp' is not a member of 'Param'; did you mean 'curki'?
141 | ui->CurrentKp->setText(QString::number(Param::GetInt(Param::curkp)));
| ^~~~~
| curki
Jacobsmess
Posts: 490
Joined: Thu Mar 02, 2023 1:30 pm
Location: Uk
Has thanked: 253 times
Been thanked: 65 times

Re: IPM Motor Simulation and FOC Software

Post by Jacobsmess »

Finally managed to get my old Linux partition running in the hope that I can get the simulator working on it as my Mac is too old....
When installing QT it seems the installer has changed from what it was when the guide was written. The options that seem closest to what is mentioned on the install guide are as pictured...
but it would be nice if this could be confirmed?
Also, given there are newer installation options, would it be beneficial to install one of these or is it best to stick with 6.4?


UPDATE: I went ahead and installed the above and compiled the GIT hub stuff, opened it in QT but it seems to throw up a couple of errors that won't allow the IPM simulator to run... I've attached a screenshot below
Thanks
Attachments
Screenshot from 2023-09-25 14-56-56.png
Screenshot from 2023-09-25 09-36-27.png
Post Reply