Audio output in Simulink Real Time with Windows

9 vues (au cours des 30 derniers jours)
D B
D B le 7 Jan 2021
Réponse apportée : Swathi le 13 Sep 2022
Hello,
I'm currently using a Target machine which connects to my computer and also via CAN to a robot. I am using Simulink (version 2019b) in external mode (fixed step auto solver, target file slrt.tlc, inherited) to run C-code on the target machine. A user manipulates the robot and our model determines whether or not a specific task is achieved. When the task is achieved I need the Simulink model to output any noise (a beep, a ding, a gong) to let the user know they achieved their goal without the experimenter interacting with them. At the moment I have a Simulink model with a Stateflow chart which has the output of 1 when the task is achieved and the sound should be played. Is there any way to output a sound over my computer's audio hardware when I use the external mode in Simulink?
I tried struggeled using an S-function which just beeps on the host and is not compiled. How do I have to write this function? And how can I tell Simulink to continue to run on the host?

Réponses (1)

Swathi
Swathi le 13 Sep 2022
I discern that the objective was to output a sound (audio response) over the computer's audio hardware (while connected with the Real-Time Windows Kernel), whenever the output of the Simulink model is 1 as an indication that the task has been achieved.
The intent was to use the audio output (a beep/ding/gong, or a popular song) to serve as an automated acknowledgement to the user by avoiding experimenter interaction(s). It is noted that using the ‘To Audio Device’ block and the ‘MATLAB Function’ block yields the expected output only while not communicating with the system using the external mode.
The reason an audio output (‘beep’ for instance) cannot be received from the compiled real-time code is mainly because the ‘real-time kernel’ of Real-time Windows Target will not have access to the audio device connected to the system/computer. This is since the real-time kernel and the host OS (Windows) are two distinct environments that run on the same system/computer but are mutually exclusive.
However, it is possible to have a ‘beep’ output on the host by any one of these methods -
  • Writing a MATLAB Level 1 S-function without any outputs, such that it triggers a beep in response to an input condition. Such an S function will not be subjected to real-time compilation and continually run on the host. As a result, it can contain any suitable MATLAB function/code that supports the beep audio output.
  • Deploying a Level 2 S-function without any outputs, while ensuring that theSetSimViewingDeviceFlag is set beforehand.

Catégories

En savoir plus sur Code Generation and Deployment dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by