How to suppress error notification with "Joystick Input"-block if user doesnt have gamepad connected?

조회 수: 8 (최근 30일)
Hi,
I am useing the "Joystick Input"-block in my simulink model. But the model stops working without a gamepad connected. Error: "Error reported by S-function 'joyinput' in '...': Joystick not connected". This is very bad, because I want to accieve just an optional usage of the gamepad. Does anyone konw how to solve this problem?

답변 (1개)

Jan Houska
Jan Houska 2015년 8월 31일
You can put the Joystick Input block into an Enabled Subsystem. Then, you can control the behavior using the Enable input. When the subsystem is not enabled (Enable input is 0), the block inside the subsystem does not execute and if the joystick device is not present, no error is reported. Then, after you connect the device, you can just enable the subsystem by changing the Enable input to 1.
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 8월 31일
Is there a way to query to see if the joystick is detected, with the result to be used as the Enable input?
Jan Houska
Jan Houska 2015년 8월 31일
The following code should work:
joystickpresent = false;
try
vrjoystick(1);
joystickpresent = true;
catch ME
end
If joystick is not connected, ME.identifier is 'sl3d:vrjoystick:notconnected', so this should be probably checked to avoid confusion by other possible errors.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by