Matlab App Designer Virtual Joystick via the change of image position from incoming data via ROS
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1113205/image.jpeg)
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
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
Respuestas (0)
Ver también
Categorías
Más información sobre Image Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!