Use Callback 'stop_fcn' in a xpc-target application
Show older comments
Hi!
I have a problem with an actuator that I am using in my real-time environment:
If the actuator is still moving while I stop the model, it continues at the current speed that it had when the model stopped. As it is a linear actuator it normally destroys something when I don't react quick enough and turn it off.
The Actuator is controlled by velocity input and I realized a Positioning control (propotional) in the Simulink model I use. My Simulink model writes a speed and recieves the momentary position.
My Idea for stopping the Motor when the model stopps was the following:
As I know from other non- real time simulimk models that do not have to work on an xpc, there is the possibility of defining a Callback stop function in the model properties. I have a m-file which sets a certain parameter in the running xpc to another value. (I have a simple Gain Block with the value of 1 which I set to 0 with the M-file). With the gain of the control set to 0 the actuator stops immediately. When I include this M-FIle in the callback stop_fcn it does not work when I run the compiled model on the xpc.
Does anyone know a possibility to send a single parameter or start a m-file upon termination of the model on the xpc??
I would be greatful for some ideas for how to solve this problem
Thanks! Niko
Answers (1)
Kaustubha Govind
on 28 Nov 2011
0 votes
Since the model that runs on the xPC Target is actually a binary generated from the model, I don't think the concept of a StopFcn callback exists there. However, the right solution in your situation seems to be that the driver block for the Motor (or whichever actuator needs to be stopped) should have a Terminate function that performs the appropriate action. If you have access to the driver source code for the actuator, I would recommend that you add this to the generated code. Otherwise, you could try performing a similar action by inserting relevant C code in the Terminate function section of the Code Generation>Custom Code pane.
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!