control GUI slider with haptic device in Simulink external mode

  • Follow


Hello everyone,

I have a simulink block diagram that interfaces to a force-feedback haptic device:(http://www.sensable.com/haptic-phantom-omni.htm) in Simulink external mode. I can read position commands from this device and output force-feedback to this device (a block in my diagram does this, and it works fine). I can visualize the position signals on a simulink scope. In addition to that, I want to be able to use these position signals from the device to control a slider in my matlab GUI. 

I included a gain block in the path of the position signal and tried to use  add_exec_event_listener to register an event listener on its output. I understand that the callback registered by add_exec_event_listener is only executed when the corresponding block (in this case the Gain block) in the simulink block diagram is executed. I got errors when I tried to build this, since the diagram is running in external mode.

I found out that since in external mode, blocks are not executed inside simulink, but on the target processor, I cannot simply use add_exec_event_listener to register listeners. So I needed to get this Gain block out from external mode execution. I learnt that by creating an "atomic subsystem"  in my block diagram, I can make some blocks in my block diagram to run inside Simulink rather than in external mode. So I created an "atomic subsystem"  around this Gain block (there are also a few other blocks in this atomic subsystem), and I can now use add_exec_event_listener on the Gain block output. The diagram now builds and even runs without any errors. 

However,  add_exec_event_listener does not really work! The handle to the listener returned by 
h = add_exec_event_listener(blk, event, listener);
is empty (very sad)! 

If I try to edit the handle 'h' in the Matlab workspace by entering my updateGUI() function into it while the block diagram is executing, I can hit breakpoints inside the function. But this is of no use.

If I add a pushButton on my GUI that reads the current Gain block output and updates the GUI slider position (using runtimeObject), it works. But of course, I cannot click on this button at a rate of 500 Hz for a few minutes, which is what I want the listener to do. But it does not do that currently.

Extremely sorry for the long text, I just wanted to be clear enough. Any ideas on how one could solve my problem?

thanks and best regards,
Wetoo
0
Reply Wetoo 12/5/2010 8:06:07 AM

I am running Matlab R2009a on WinXp Pro - Don't know if that has a bearing on whether add_exec_event_listener is correctly operational or not...
0
Reply Wetoo 12/5/2010 8:20:07 AM


"Wetoo " <wetoo.cando@gmail.com> wrote in message <idfhvn$lqd$1@fred.mathworks.com>...
> I am running Matlab R2009a on WinXp Pro - Don't know if that has a bearing on whether add_exec_event_listener is correctly operational or not...

Hi Wetoo,

If you look at the code for add_exec_event_listener you will see that it attaches a handle.listener object to a Simulink.RuntimeObject. Simulink.RuntimeObjects only exist while a simulation is running. To test your model try get_param(gcb, 'RuntimeObject') with your gain block selected both with and without the simulation running. If the get_param returns empty then add_exec_event_listener will also return empty. You will need to write code that starts the simulation and then creates the listener.

Good Luck,

Donn
0
Reply Donn 12/8/2010 6:40:23 PM

Thanks very much for your helpful answer Donn!




"Donn Shull" <donn.shull.no_spam@aetoolbox.com> wrote in message <idojen$qm4$1@fred.mathworks.com>...
> "Wetoo " <wetoo.cando@gmail.com> wrote in message <idfhvn$lqd$1@fred.mathworks.com>...
> > I am running Matlab R2009a on WinXp Pro - Don't know if that has a bearing on whether add_exec_event_listener is correctly operational or not...
> 
> Hi Wetoo,
> 
> If you look at the code for add_exec_event_listener you will see that it attaches a handle.listener object to a Simulink.RuntimeObject. Simulink.RuntimeObjects only exist while a simulation is running. To test your model try get_param(gcb, 'RuntimeObject') with your gain block selected both with and without the simulation running. If the get_param returns empty then add_exec_event_listener will also return empty. You will need to write code that starts the simulation and then creates the listener.
> 
> Good Luck,
> 
> Donn
0
Reply Wetoo 12/12/2010 8:37:04 AM

Dear Wetoo,
I have similar problem.
I want to read a sensor's data in External mode of Simulink and show it in a bar graph in GUI. 
As you mentioned, I have used event listeners and every things look good in Normal mode but in External mode my graph does not update. If I run the updategui.m file each time, as you have mentioned, the bar will be updated but this method will not work!!!
I will be grateful if you could help me. I really need to solve this issue as soon as possible.
Thanks in advance for your kind reply.

"Wetoo " <wetoo.cando@gmail.com> wrote in message <ie21jg$89k$1@fred.mathworks.com>...
> Thanks very much for your helpful answer Donn!
> 
> 
> 
> 
> "Donn Shull" <donn.shull.no_spam@aetoolbox.com> wrote in message <idojen$qm4$1@fred.mathworks.com>...
> > "Wetoo " <wetoo.cando@gmail.com> wrote in message <idfhvn$lqd$1@fred.mathworks.com>...
> > > I am running Matlab R2009a on WinXp Pro - Don't know if that has a bearing on whether add_exec_event_listener is correctly operational or not...
> > 
> > Hi Wetoo,
> > 
> > If you look at the code for add_exec_event_listener you will see that it attaches a handle.listener object to a Simulink.RuntimeObject. Simulink.RuntimeObjects only exist while a simulation is running. To test your model try get_param(gcb, 'RuntimeObject') with your gain block selected both with and without the simulation running. If the get_param returns empty then add_exec_event_listener will also return empty. You will need to write code that starts the simulation and then creates the listener.
> > 
> > Good Luck,
> > 
> > Donn
0
Reply caspian.0233 (2) 3/5/2013 11:09:08 AM

4 Replies
369 Views

(page loaded in 0.167 seconds)

Similiar Articles:













7/23/2012 4:50:43 AM


Reply: