I have a piece of hardware and a DLL that can be used to control it. This is essentially a motor controller that I have used from C/C++ and MATLAB. I havetried to create a SIMULINK model using the DLL and I can't seem to get it to spin the motor.
The Simulation Target is set to include the header file and DLL. The Model Properties-> callbacks include MATLAB functions to initialize the DLL and hardware. The model includes a C Caller block that should call the DLL function to set the motor speed.
When I run the simulation, I can see the initialization code being executed, the motor never starts spinning. At the end of the simulation, the cleanup function is executed.
I have two thoughts about this. First, the C Caller block doesn't support sending commands over the serial link. Second, the initialization and cleanup code are MATLAB scripts. Is it possible that the MATLAB initialization is not recognized by SDIMULINK? That is, do I have to call the DLLs init function from the model directly (I'm not sure how to do this, but a WAG would be to embed other C Callers, with the required functions).
Related
I've been handed a simulink model. I'd like to use simulink's code generation features to compile it into a binary and then run it on an embedded system (a beaglebone black). From there, I want to query it for output as a stand-alone component of a more complicated system.
I am having trouble finding where to specify the interface behavior to the compiled model.
I want to start the simulink model (with a python os.system() call, probably) with some default arguments (like starting parameter values for the model blocks), and then capture its output, which should be the values reported at each outport at each tick (the model has an internal clock and reports values at given intervals).
I have been able to blindly compile it into an *.elf binary and deploy it to the embedded device, and it runs, but the only thing that happens is i get the string **** model running **** on STDOUT.
What's the easiest way to specify command line arguments into this compiled binary?
If the answer is "generate the code and then edit it by hand to pass arguments in", how do I persist the hand edits between re-generations of the code when the simulink model changes?
How do i make simulink outports report on STDOUT ?
I'm using Simulink to build a subsystem, which will then be built up using Simulink Coder to get an executable. I want to include this executable into my main function that is not necessarily written using Matlab. The main function is to implement a non-real time, desktop deployed feedback loop, i.e., (1) read out the output of the subsystem, (2) calculate a new input based on the reading, (3) send the new input to the subsystem.
I've managed to build-up a desktop deployed executable of the subsystem using RSim target. But in the main function (for test purpose, I am using Matlab to write the main function), the executable is one-off executed, where I can't read its output or assign new input during its running.
Thanks & Regards.
Yes
If you want to do a closed loop simulation, you most certainly need access to the simulink solver internal step() function. This can be achieved when you build a dll file and then include it via the header files etc. in your other simulation engine. But to be able to do this you need an embedded coder license. use the ert_shrlib.tlc target.
I am currently using Matlab Simulink with a Raspberry Pi. I have been using the S-Function Builder block to generate an S-Function that I am using with the S-Function Block. However, I always need to keep a copy of the S-Function builder that I need to build at the first start, as Simulink otherwise tells me :
"Error in S-function 'read_accelerometer/S-Function': S-Function 'sfun_read_adxl345' does not exist"
I am keeping the .c and the wrapper.c file, as well as the mexw64 and the tlc files. But that does not matter - I still have to rebuild the S-Function using the Builder block every time I reload my model.
How to circumvent this issue?
Ok, this is kinda sad that I am answering my own question ...
I had a startup script that messed with the mexw64. So, always keep the mexw64 file, even if it is not needed. (recompilation on Raspberry Pi)
Also, specify the generated wrapper function as a module in the S-Fun block.
I have a simulink model connected to my hardware and I am able to see the response on my scope when I change the setpoints in my model etc. But I will like to save this data from the scope so that later I can plot it.
I have read some documentation online but I am still confused. Can someone give me a step by step method on how to plot this data from the scope used in external mode.
Kind Regards
There is a write data to workspace block in simulink. You can put that block in the same bus as the scope and save the data to Matlab. If you want it automatically save into the disk, then I recommend to write a small .m script that takes this variable and saves in disk using save(). You can automatically run this .m file after the Simulink model is stopped (or some other condition you prefer) going to Properties->Callbacks and choosing the appropriate function callback.
I have a simulink model and I generate the code using simulink coder for Generic Real-Time target.
I then copy the generated files (*.c and *.h) into my project in MPLAB.
Here I have the main.c file and here I use MdlStart() for initializing the model one time and then in infinite loop I use MdlOutputs() and MdlUpdate() for running the model. Everything works fine.
Now actually I want to speed the execution of the model and therefore I want to split my model into sub-systems and execute the sub-system only when required (e.g. I want to execute some sub-systems everytime and some only every few ms instead of everytime). I could split the model into subsystems and also made every sub-system atomic so that I get the different function for every sub-system. Now these different sub-system's functions are called from MdlOutputs() and MdlUpdate(). So they execute everytime the model is executed.
Actually I want to use some timer in my MPLAB project and then execute few sub-systems lets say at every 100ms. I also do not want to modify the auto-generated *.c and *.h files.
So instead of executing these sub-system's functions everytime through MdlOutputs() and MdlUpdate(), Is it possible to call the sub-system's functions from my main.c file without touching the auto-generated *.c and *.h files?
I hope that I have explained it well.
waiting for your help.
You should try to model everything you are trying to do with subsystems inside Simulink. For example, you can use "Enabled subsystems" or "Triggered subsystems" to create subsystems which run only on some time steps. I am not sure what kind of timer you are referring to. If it is Simulink time then you would need to run different subsystems at different sample rates which would give you a multirate model. If your timer is just another external source, then try triggered or enabled subsystems. That is the best way to avoid modifying generated files.
Doc for these subsystems are at http://www.mathworks.com/help/simulink/conditional-subsystems-1.html.