101 on Matlab/Simulink

It's all about the code!
Post Reply
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

101 on Matlab/Simulink

Post by AndreyB »

All I know about Matlab/Simulink is http://www.mathworks.com/products/connections/product_detail/product_35723.html

and http://www.edaboard.com/thread303493.html / http://www.edaboard.com/thread252497.html by @hameeds01

Anyone interested to write down an introduction to all this for dummies? Or maybe a teamviewer training session?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

This might be of interest if you are looking at doing math simulation stuff http://www.scilab.org/

Also http://wiki.scilab.org/MatlabToScilab
Welcome to the friendlier side of internet crazy :)
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

I see "Scilab for very beginners" here https://www.scilab.org/resources/documentation/tutorials

Why are you doing math simulation stuff?
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: 101 on Matlab/Simulink

Post by AndreyB »

kb1gtt wrote:Why are you doing math simulation stuff?
I am not doing math simulation stuff, I know nothing about it. I am interested in someone to tell me/us if/why we need to do math simulation as part of ECU logic, and show some prototype etc.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

I've been tempted to try to simulate an engine with scilab before, but haven't had the gumption to give it a try. I do feel it would be good to have such simulations available for experimentation and such. I can see how one could set parameters like stroke, bore, intake air flow resistance, ect and could simulate a engine that could be tuned to some extent.
Welcome to the friendlier side of internet crazy :)
polm
Posts: 7
Joined: Thu Dec 04, 2014 4:41 am

Re: 101 on Matlab/Simulink

Post by polm »

This can be helpful: http://en.wikipedia.org/wiki/MATLAB
I had a Matlab class in university. As far as I know, It is a high level programming language with many many built in functions and it is very good with algorythms. Some OEMs use Matlab/Simulink as the programming interface for their ecus. Simulink provides the graphical interface to Matlab, which means your entire tuning software could be run in Matlab directly. There are several similarities with C and Java.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

As an opensource near equiv of LabView, there is GRC http://www.joshknows.com/grc it allows blocks to be visually connected. Blocks are generally compiled FPGA or MCU code that gets loaded into a PCB to preform radio stuff. However it's just code so it doesn't have to be radio stuff. As well it may or may not be connected to a PC.
Welcome to the friendlier side of internet crazy :)
blundar
contributor
contributor
Posts: 141
Joined: Tue Jan 07, 2014 4:38 am
Location: Cincinnati, Ohio
Github Username: blundar
Slack: Dave B.
Contact:

Re: 101 on Matlab/Simulink

Post by blundar »

This gets down to architecture. Implicit in a lot of what you are doing is a model. Many ECUs use incredibly simple models. Many use incredibly complex ones, sometimes unnecessarily so.

Most of the time this ISN'T something that end users or people tuning ECUs think about in the forefront of their mind because it's no something that you can typically change.

A lot of "professionals" (i.e. OEMs) start in MatLab/Simulink/etc.etc.etc. They're not dealing with the CALIBRATION for a particular engine - they're dealing with trying to figure out ways of connecting inputs, internal states and outputs to achieve desired results. This sort of algorithmic modelling is a strength of these applications. (Disclaimer: I'm not a Matlab wizard) The whole point here is that a model (hopefully) derived from physics is implement in a series of math operations, table lookups and control loops in order to achieve a desired result. In Matlab,etc. these algorithms are not much more than a series of operations chained together.

Is there a NEED to use these kind of tools to develop and ECU? Probably not. Can they be helpful for sorting out algorithms and trying to improve the response of a system and decrease its error? Certainly.

I think the bigger thing is looking at the (typically) monolithic/hardcoded algorithm structure of most ECUs versus the dynamic algorithm structure available within Matlab. There isn't anything stopping an ECU from having a dynamic or at least flexible algorithm if the processes are modeled in a series of small, generic containers containing one or more inputs, one or more outputs and a piece of code to generate outputs from inputs.

just a thought.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

I've got a first stab at a PID, many things are wrong, but technically it does core functionality. See attached zip with brief video showing the steps to make it execute.
SciLab_PID_First.png
SciLab_PID_First.png (109.13 KiB) Viewed 13137 times
Attachments
rusEFI_PID_SCILab.7z
(1.75 MiB) Downloaded 390 times
Welcome to the friendlier side of internet crazy :)
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: 101 on Matlab/Simulink

Post by mck1117 »

I'm now extremely curious if you can get Scilab to compile your block diagram in to a program, or even to a "normal" script output. Because if you can, we can design the ECU in Scilab.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

I believe scilab can but I have no idea how to do it. I'm finding lots of of differences with how scilab handles code. I don't know why it's so hard to instanciate your variables. That is why I posted the video. I currently manually declare the vars so they can be used. As well it appears it only has global vars. You have to give you functional unique names. Lots of of differences. For now I'm just trying to make a PID model of the ETB.
Welcome to the friendlier side of internet crazy :)
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 101 on Matlab/Simulink

Post by kb1gtt »

This looks like someone used an Arduino as a real world physical interface for SciLab. They pulse a LED with it. It may show key bits about how to compile code with SciLab which could be used on a MCU.
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: 101 on Matlab/Simulink

Post by AndreyB »

Default emx_codegen Scilab Code Generator is working only while you are online and it's not self-contained - you rely on someone on the internet generating code for you :(

"emmtrix Technologies kindly provides the free web service to the code generator. Your submissions to the service may be accessible from any part of the world and any information they contain may be used by emmtrix Technologies and the public, both within and outside the country from which you posted. You understand that emmtrix Technologies does not guarantee any confidentiality with respect to any content you submit."

"For licensed code generator without these listed restrictions, feel free to contact team@scilab.io"
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK

Re: 101 on Matlab/Simulink

Post by Rhinoman »

I've done some work with Matlab and Scilab, Matlab is far superior and, if you have a proper licence, then the support is very good. Code generation with Scilab is not going to be good, you can however work on algorithms and then port them to C++. You will need a good engine model or a lot of data to perform any effective HIL testing.
Both Scilab and MATLAB suck when it comes to using 3rd party DLLs but MATLAB is usable, I've used the Vector CANAPe DLL/API for the interface to an ECU that used CCP.
Post Reply