Matlab App Designer Virtual Joystick via the change of image position from incoming data via ROS

6 visualizaciones (últimos 30 días)
I try to make a virtual joystick in Matlab App Designer with the help of images that I have added Image3 as main image and top of it, I have added the Image4 which it will move positions according to my joystick Axes1-Axes2 values from ROS subscriber topic.
I have written a main while loop to see all of the changes in real time on Matlab Appdesigner via drawnow() function at the of the main loop which it will help me to see the joystick image to move on the Virtual Joystick Panel in the picture below.
However, I get these errors:
Index in position 1 exceeds array bounds. Index must not exceed 1.
virtual_joystick_movement(app, double(app.stored_logitech1_axes1), double(app.stored_logitech1_axes1) );
updateGUIjoystick(app)
This is the function I wrote.
function virtual_joystick_movement(app, x_vr_joy, y_vr_joy )
% [left bottom width height]
default_imagePos = [183 215 143 133];
% Boundary positions for joystick can go as max and min
x_max = 225;
%y_max = 257;
x_min = 141;
%y_min = 173;
default_x = default_imagePos(1);
default_y = default_imagePos(2);
get_pos_x = app.Image4.Position(1); % Current Position of X for the joy image
get_pos_y = app.Image4.Position(2); % Current Position of Y for the joy image
new_pos_x = get_pos_x + x_vr_joy; % app.stored_logitech1_axes1
new_pos_y = get_pos_y + y_vr_joy; % app.stored_logitech1_axes2
%customPosition = app.Image4('Position', [left bottom width height]); % Current new position of image
%customPosition.Position = []; % define your new position for the image
customPosition = app.Image4('Position', [get_pos_x get_pos_y default_x default_y]);
%customPosition.Position = [new_pos_x new_pos_y default_imagePos(3) default_imagePos(4)]; % define your new position for the image
if x_vr_joy > 0 && customPosition(1) <= x_max && customPosition(1) >= x_min
customPosition.Position = [new_pos_x new_pos_y default_imagePos(3) default_imagePos(4)]; % define your new position for the image
elseif x_vr_joy < 0 && customPosition(1) <= x_max && customPosition(1) >= x_min
customPosition.Position = [new_pos_x new_pos_y default_imagePos(3) default_imagePos(4)]; % define your new position for the image
elseif x_vr_joy == 0 || x_vr_joy == -0
customPosition.Position = [183 215 143 133]; % define your new position for the image
end
end
I will be very glad if someone would guide me to show me the correct way to apply this virtual joysyick feature in Matlab Appdesigner.
  1 comentario
Dolon Mandal
Dolon Mandal el 21 de Sept. de 2023
Can you try the following code:
function virtual_joystick_movement(app, x_vr_joy, y_vr_joy)
% [left bottom width height]
default_imagePos = [183 215 143 133];
% Boundary positions for joystick can go as max and min
x_max = 225;
%y_max = 257;
x_min = 141;
%y_min = 173;
default_x = default_imagePos(1);
default_y = default_imagePos(2);
get_pos_x = app.Image4.Position(1); % Current Position of X for the joy image
get_pos_y = app.Image4.Position(2); % Current Position of Y for the joy image
new_pos_x = get_pos_x + x_vr_joy; % app.stored_logitech1_axes1
new_pos_y = get_pos_y + y_vr_joy; % app.stored_logitech1_axes2
% Update the position of app.Image4 directly
app.Image4.Position = [get_pos_x get_pos_y default_x default_y];
if x_vr_joy > 0 && app.Image4.Position(1) <= x_max && app.Image4.Position(1) >= x_min
app.Image4.Position = [new_pos_x new_pos_y default_imagePos(3) default_imagePos(4)];
elseif x_vr_joy < 0 && app.Image4.Position(1) <= x_max && app.Image4.Position(1) >= x_min
app.Image4.Position = [new_pos_x new_pos_y default_imagePos(3) default_imagePos(4)];
elseif x_vr_joy == 0 || x_vr_joy == -0
app.Image4.Position = [183 215 143 133];
end
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by