saving location with MATLAB

117 views
Skip to first unread message

ngol...@stevens.edu

unread,
Jun 3, 2014, 1:20:31 PM6/3/14
to velmex-...@googlegroups.com
Hello,

I am having trouble saving the location using MATLAB. I have spent hour trying to get this to work. Can you please help me?
Here is me code... (i know that I am connected to the device)


%save current location
send(port,'!');

%move to a new spot
move(port, 1,-1);

%display
send(port,'x');
if port.BytesAvailable > 0
x = fscanf(port, '%e', port.BytesAvailable)
end

Cliff

unread,
Jun 3, 2014, 1:47:14 PM6/3/14
to velmex-...@googlegroups.com
Hi,
I would need to see the rest of the code to tell but it looks like you
are sending the x while the motor is moving, so you will not get a
position back

Cliff

ngol...@stevens.edu

unread,
Jun 3, 2014, 2:00:46 PM6/3/14
to velmex-...@googlegroups.com, cl...@velmex.com
Here is my code, most of this I collapse in to functions so I do not have to keep writing it.


close all;
clear all;

%close all ports
if ~isempty(instrfind)
fclose( instrfind);
end

clc;

%Set up port
port = setPort(11,9600);
echoOff(port);
%%
cmd = ['C,I1M-6000,R'];
fprintf(port,cmd);

scan = '';

while ~strcmp(scan,'^')
%pause(1);
scan = fscanf(port,'%c',1);
display(scan);
end

while ~strcmp(scan,'R')
fprintf(port,'V');
scan = fscanf(port,'%c',1);
display(scan);
end

%%
fprintf(port,'!');
%%
fprintf(port, 'x')

VelmexControls

unread,
Jun 4, 2014, 3:01:10 PM6/4/14
to velmex-...@googlegroups.com, cl...@velmex.com, ngol...@stevens.edu
This is what I sent this morning, but not sure if it actually sent?

I am not all that great at Matlab code but I do see several problems in the code that you sent
I get this error when I try to run the code
??? Undefined function or method 'setPort' for input arguments of type 'double'.

Error in ==> TestCode at 12
port = setPort(1,9600);
 

I also see that you are sending a bunch of potential status commands after the VXM has completed its move

while ~strcmp(scan,'R')
    fprintf(port,'V');
    scan = fscanf(port,'%c',1);
    display(scan);
end
Which in essence could (most likely) overflow the buffer if sending a V constantly and not waiting for the reply.

Cliff

ngol...@stevens.edu

unread,
Jun 6, 2014, 4:17:35 PM6/6/14
to velmex-...@googlegroups.com, cl...@velmex.com, ngol...@stevens.edu
That error is because, I sent you code that involved a function that I forgot to put in the code that I sent you.

I think that main problem is the reading data. I keep trying to read the reply with no response or a there is a delay.

I have the system hooked up through serial to USB could this be causing my problem?

Cliff

unread,
Jun 6, 2014, 4:25:45 PM6/6/14
to ngol...@stevens.edu, velmex-...@googlegroups.com
Part of the problem is asking for a status request then immediately
wanting a response that is not there yet.
I would request once, then wait 100-250ms and then read the port and if
nothing their loop again but do not send another "V"

Cliff

ngol...@stevens.edu

unread,
Jun 6, 2014, 4:49:31 PM6/6/14
to velmex-...@googlegroups.com, ngol...@stevens.edu, cl...@velmex.com
Thank you I will try that.

I have another question. I am trying to read my current position.I read one of the other postings in the group and got the code:

fwrite(port,'X');
pause(.1);
if port.BytesAvailable > 0
scan = fscanf(port, '%e', port.BytesAvailable);
end

But I get the Error:
Warning: Unsuccessful read: Matching failure in format.

sup...@velmex.com

unread,
Jun 9, 2014, 8:17:04 AM6/9/14
to velmex-...@googlegroups.com, ngol...@stevens.edu, cl...@velmex.com

rob....@thermofisher.com

unread,
Jun 9, 2014, 8:36:35 AM6/9/14
to velmex-...@googlegroups.com, ngol...@stevens.edu, cl...@velmex.com
Cliff is right.  Positional commands sometimes take a while to complete.  And prompt responses (e.g., '^') don't happen until the move is complete.  So this can be a problem particularly if you command your motor to move a long expanse at a small speed.

In my own experience, the way I handled this programmatically was to set up an asynchronous serial trigger, which would be waiting for the prompt response right after commanding the move.  Then when the prompt comes in, you finally handle it.

Nathaniel Goldfarb

unread,
Jun 9, 2014, 2:34:16 PM6/9/14
to velmex-...@googlegroups.com
ok, I am not getting that error anymore. But I get a number with a bunch of 'R's in front of it. 


--
You received this message because you are subscribed to a topic in the Google Groups "Velmex Controls" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/velmex-controls/S96zUYMiIXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to velmex-contro...@googlegroups.com.
To post to this group, send email to velmex-...@googlegroups.com.
Visit this group at http://groups.google.com/group/velmex-controls.
For more options, visit https://groups.google.com/d/optout.



--
Thank you,
Nathaniel Goldfarb
Mechanical Engineer

sup...@velmex.com

unread,
Jun 9, 2014, 3:02:44 PM6/9/14
to velmex-...@googlegroups.com, ngol...@stevens.edu
Did you take out the status check?
If memory serves the Dll may be already doing that.

Cliff
You received this message because you are subscribed to the Google Groups "Velmex Controls" group.
To unsubscribe from this group and stop receiving emails from it, send an email to velmex-contro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages