Borrar filtros
Borrar filtros

Connecting the movement of a cursor (controlled by data from encoders) while making a target move on the screen?

1 visualización (últimos 30 días)
Hi everyone,
I have two encoders which signals are acquired by matlab through an arduino board. And I have a function that makes the data acquisition through an infinte while loop.
Then I have a GUI (built with guide) that has an axes figure in which a target and a cursor should be moving once I clicked a push button in the GUI.
The target moves thanks to a for cycle that changes its position on the plot once every second.
Now, what I would like to do is to connect the encoders' signal to the cursor movement. The problem is that since I have basically two loops (one for the data acquisition and one for the target movement) I am not able to make the code running in the GUI because I have to wait that one of the two loops finishes before the other starts.
So basically the code is:
function EncodersData = read_arduino ()
%Read encoder data with a while cycle
%Compute the Cursor position in the while cycle
end
%In the GUI push button callback function
Cursor_Position = read_arduino();
%Change cursor position continuously somehow
for i = 1:60
pause (1)
%Change target Position
end
So in the code I just shared the Target position won't be updated in the plot becuase the while loop of the read_arduino function is infinite and it won't stop till I close the code.
So I need to be able to read the Cursor_Position continuously (not at the same velocity of the for cycle of the target) and update the cursor position continuously.
These are the solutions (that I was not able to make work) that I tried:
  1. Use simulink to pass the encoders' data to matlab (Problem: I wasn't able to read the data in real time from simulink)
  2. Use the Parallel computing Toolbox to run the read_arduino() function continuously and have a labReceive function to retrieve its data in the GUI (Problems: First, I tried and I am not able to define which Lab should do what; Second, I am not sure that this will sove the problem because if I put the labReceive command before the for cycle then I will never be able to read it and if I put it inside the for cycle then I am gonna read the value just once every second while I want the position of the Cursor to be updated continuously).
  3. Use a callback function in the GUI that runs continously and that can retrieve continuously the data from read_arduino() and hence update the cursor position (Problem: I am not sure matlab can do multithreading in this way even though with the function MoveMouse I am able to move the cursor basing its position on the position of the mouse without any dependance from the movement of the target, so the cursor is able to updates its position at a different velocity than the one of the target. So maybe I can do this but there is someting I am missing).
Does anyone know how can I solve this problem?
Thank you in advance.

Respuestas (0)

Categorías

Más información sobre Instrument Control Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by