Import MATlab data for stepper motor demand

I am fairly new to Arduino and I have created a polynomial for the motor demand in MATlab and I was wondering how I could import this data to the Arduino to control the motor. Any help would be much appreciated (:

I was wondering how I could import this data to the Arduino

Step 1: Get MatLab to send the data. I can't imagine what good a polynomial curve is going to do the Arduino though, or how the curve relates to motor demand (whatever that means).

Step 2: Explain how the Arduino is supposed to use the data that MatLab sends.

The polynomial is the plot of desired motor speed that I have just stored as an array. I using a stepper motor and I want the arduino to take the desired motor speed and tell the motor to spin at that speed.

Is the polynomial a 2D curve? What do the two axes mean? speed (rpm) and time?

Are you planning to send the coefficients of the curve to the Arduino, and have it evaluate the polynomial? Based on what?

yes speed and time. I was planning on sending the whole array for desired motor speed to the arduino and then looping through each element to send to the motor. I have no clue if this is a valid approach and if creating the polynomial in the setup part of the arduino code was a better approach I would do that.

I was planning on sending the whole array

What whole array? A polynomial is defined by coefficients. How many coefficients are there? Is it the (array of) coefficients that you are talking about?

Over what time domain is the curve defined?

the whole polynomial I have created it form its 6 coefficients in MATlab it is defined over 500 elements representing times form zero to 0.5 seconds where the value of each element is the desired motor speed.

hhornby:
the whole polynomial I have created it form its 6 coefficients in MATlab it is defined over 500 elements representing times form zero to 0.5 seconds where the value of each element is the desired motor speed.

I'm not following that. I think that you are saying that you have a polynomial whose equation is defined by 6 coefficients, and that you have broken that polynomial into 500 pieces.

Given that the 500 points cover 500 milliseconds, that implies that you have a speed for the motor that changes every millisecond. Do you really think the motor can change speed that quickly?

Sending 500 bytes (or 1000, if the values are greater than 255) per second is going to prove difficult.

Okay poor example using 500 the number of pieces I break it into is flexible, I chose 500 arbitrarily but obviously from what you have said it is not practical. But your description is what I have done. So I basically have a polynomial spanning 0 to 0.5 seconds that I wanted to split into pieces and use the pieces for the desired motor speed.

Can you get MatLab to send the "pieces" to the serial port? In what format? What, specifically, is a "piece"? An int? A byte? What is the range of values being sent? ASCII or binary?

What is to happen after the 1/2 second period is over? Is the data to be collected and used in setup()? Or, in loop()?

Thats what I was hoping to do but I have a .mat file saved with the data and I haven't figured out how to send it to the serial port. Its currently a long. I think stepper motors take speed commands in rpm so the data values would range from 0 to 60 rpm. The desired motor speed starts at zero rises then falls to zero at 1/2 a second so after half a second I would want the motor to stop as it has completed its task. I was thinking of using it in loop by looping through each piece to set the motor speed but again I don't know if this is a valid approach.

Its currently a long.

When it contains values in the range 0 to 60?

The desired motor speed starts at zero rises then falls to zero at 1/2 a second so after half a second I would want the motor to stop as it has completed its task.

You realize that the "task" of a stepper motor is to step, right? The "task" of a stepper motor is NOT to run at a constantly varying speed. How many steps is the motor supposed to take in this half second window?

The “polynomial” phrase is what threw me initially. What you have is a profile of motor speed verse time. The fact that you generated it with a polynomial is irrelevant. Is this profile dynamic? Do you have to download it to the micro-controller every time? Or is it static?

If static, why not just format it properly and copy-paste it into your .ino (or .cpp) file? Add the appropriate commas, curly braces, etc and use it as an initializer to a const array.

I’ll leave the discussion of appropriateness of a stepper motor for this application to you and PaulS.

Sorry double. Sorry I think I misinterpreted an example set online when the speed for a stepper motor is set. But I can easily find the polynomial for the displacement by integrating and using those coefficients which leaves me with the same problem. It will have to take about 60 steps