04-01-2009 09:31 AM
I have made a VI that works correctly. The problem is I want it to repeat until the entire spreadsheet has been read and written.
A little background: I will be having labview outputting a signal to 4 motors, which will perform the motion prescribed to each. Only two are hooked up right now, so in the text document /1 refers to motor 1, and /3 refers to motor 3. /_R tells the motors to execute both commands simultaneously.
When I tried to loop this, I was unable to have the VI wait until each motion was complete before sending the next command. Currently it works if I sit at the computer and press run once the motions are finished, but the goal is complete automation and this can't be that difficult. I have attached the motor commands and the VI.
Please someone help me!
04-01-2009 10:08 AM
Team23,
Can your motor controller send a confirmation message after a command is finished executing? If so you could write the command and then wait for the reply before sending the next command.
04-01-2009 10:11 AM
Some options that I can think of:
1. You will need to find out if the device outputs anything when the motion is completed so you can read that and only then start the next iteration of the loop or maybe there is some sort of register on the device that you can poll.
2. How long does each motion take? Maybe you can use some sort of timing to start the next motion.
04-01-2009 10:17 AM
When you place something on the serial port for something else to read, it is difficult to determine if it had read anything at all unless there is a response. The motor may be sending an "OK" or even better "ALL DONE" message back to you after each command. I would try using a terminal program (like hyper-term or...better) and communicate with the motors and observe what their output is back to you. Serial port stuff can be tricky and take a lot of tinkering. Using a terminal program helps troubleshooting tremendously.
Other than that...you may need to figure out what a resonable amount of time is for each operation and then add a column in your spreadsheet for that. So when that command is passed to the motor, your input for "wait ms" VI comes from your spreadsheet.
As for restarting after done with the first run, do you want to re-initialize your serial port or something like that? There is the "First Call" function that is true on the first iteration of a loop since program execution and false thereafter.
04-01-2009 10:22 AM
Thank you both for the replies.
Wayne - the motors can send a confirmation message (I believe). the problem is that any messages I have received from the motors are a bunch of jibberish that make no sense, so programming the VI to respond to these is difficult. Is there a way to have the VI run once it receives a message, regardless of what the message is?
Adnan - The motors will be set into a massage chair, so each motion will probably have different timing. I have actually set up the VI to run through once, wait 30 seconds, then run again. This setup works but is somewhat primitive for my goals.
04-01-2009 10:38 AM - edited 04-01-2009 10:39 AM
Team23,
Can you post link to communications manual for motor control? All jiberish is after all just a bunch of 1's and 0's
One reason to read the reply from the controller is to make sure the controller is not trying to send you an error message.
04-01-2009 12:20 PM
I doubt the instrument is sending you 'jibberish'
Since you cant read it, I'm assuming it isnt ASCII.
It could be Binary or Hexadecimal. Try reading in the raw data and test converting it to different formats unitl you see one that makes sense.
They probably have the instrument send messages for a reason.
04-02-2009 01:00 PM
The control board sends back a series of letters and numbers and symbols. If I send a simple command like /1?T (asking the control board the current motor position), the output is this (copied and pasted directly from hyperterminal):
/1?T
/0b0
that symbol at the end if it doesn't show up is a heart.
Also, the board sends back these messages when it receives a command, not when it completes one.
I am officially changing the goal of this topic. I have decided that reacting to a response from the control board is a misguided goal, and I would like the VI to read a timing file and input that into a "wait (ms)". When I try this I get problems with data type, inputing an array into the wait doesn't work.
I have tried using a read from spreadsheet file outside of the for loop and inputting the timing into the wait using auto-indexing but it does not work.
Ideas?
04-02-2009 01:32 PM
Hey Team23,
To help focus this thread to your latest question. What output of the "Read From Spreadsheet File.vi" are you using to input your timing data into your "Wait (ms).vi" By default the 'Read From Spreadsheet File.vi' reads the data from your file in outputs a 2-D array. So if you wire the 2-D into a For Loop with indexing on, the 2-D array is broken into a series of 1-D arrays and is not a valid input for the Wait (ms).vi. There are a couple choices, you could wire the 1-D array into another For Loop to just have elements. Or, you could simply use the index array to get the actual value you want.
However, if your text file simple has a bunch of numbers in a single row, you could use the Read From Spreadsheet File.vi's "First Row" output and wire that into your For Loop with indexing on and then into your Wait (ms).vi.
Hope this helps
-Ben
04-02-2009 02:04 PM - edited 04-02-2009 02:07 PM
Team23,
Reacting to responses is not misguided. Its a simple matter of telling the motor to move and then checking it current position until it has reached its destination. Hard coding delays is just asking for trouble.
If you will give me some info about your controller I can help you write a vi to read the responses.