I'm running into 2 problems after I have created a working multistepper program that can scrape in a circular fashion.
Whenever the motor moves, either in a straightforward fashion or in a circle, they both move really slowly, like it takes a minute for the entire scrapping function that involved circular movement before it completed the entire circle.
I programmed the function to get the next circular coordinates before the motor moves accordingly, and with it, I made the function to do it at around 100 times before it reaches back to the starting position, however, it only reached up to 6 times before it reaches back to the original position, for in every loop, it just went to the next coordinate with a huge gap before it prints the next coordinates multiple times.
I have tried to use the sample code made by a guy create an idea as to how would I speed up the motors, but the explanations made are too winded and long. So I'm left clueless in the end.
while(i<num){
x = xCirc(i);
y = yCirc(i);
String a = "Next x in ";
String b = "Next y in ";
String c = " is: ";
String ara = a+i+c+x;
String bra = b+i+c+y;
Serial.println(ara);
Serial.println(bra);
plotting(x,y);
i++;
}
it looks as if the values for X and Y are calculated for every step - or perhaps for a small number of steps. The trig calculations on the xCirc and yCirc functions will be very slow on an Arduino. The Serial.print() functions won't help speed either.
Maths is not my strong point but I think there are more efficient ways to calculate the circle positions with sufficient accuracy - perhaps using look-up tables rather than the sin() and cos() functions.
If this was my project I would do all the hard maths on my PC and just send some integers to the Arduino for the motor movements.
Separately, It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
@pylon I'm using this code on an X-Y-Z machine with the holder in one end (and the one being moved) and the other end being the Grinder. I'm also using Raspberry pi for the img processing and an Arduino Mega
@Robin2 I'll keep that in mind, though I have to wonder as to how to speed up the calculations for the Arduinio y what you meant?
Also, I'm wondering as to why the circle only outputted 7 points instead of 100 points?
Remove all String variables from your code. String objects will clobber the RAM until a crash or similar bogus happens. Also use integral variables for the coordinate calculations.
I'm using this code on an X-Y-Z machine with the holder in one end (and the one being moved) and the other end being the Grinder. I'm also using Raspberry pi for the img processing and an Arduino Mega
What driver do you use for the motors? Is the delay really necessary? How fast can you pulse your driver?
Post the code you actually use for the tests. The posted code doesn't compile so it cannot be used for the results you got.
By some reason Your code, xyzpos, does not download.
I'm running a small CNC on an UNO and I have no problems calculating the next step in a circle, using sine and cosine. I have used a stepping rate as low as 5 degrees, possibly even less, without problems. The cutting needs time but if You move a pen around, I can understand You.
DrDiettrich:
Use Bresenham algorithms for lines and circles.
How do I implement this in Arduino? I transfer the formula into code, but for some reason, it gets all the plots from 4 corners simultaneously. Plus I wasn't able to see any code relating to the Bresenham's algorithm for Arduino in the internet.
DrDiettrich:
Remove all String variables from your code. String objects will clobber the RAM until a crash or similar bogus happens. Also use integral variables for the coordinate calculations.
I'll keep that in mind, will try to implement this. Though I still need some way to debug for me to see the coordinates being used.
pylon:
What driver do you use for the motors? Is the delay really necessary? How fast can you pulse your driver?
Post the code you actually use for the tests. The posted code doesn't compile so it cannot be used for the results you got.
I'm using 3 microstep drivers for all 3 of my stepper motors, which delay do you mean? I don't know how fast can I pulse mu driver.
Railroader:
By some reason Your code, xyzpos, does not download.
I'm running a small CNC on an UNO and I have no problems calculating the next step in a circle, using sine and cosine. I have used a stepping rate as low as 5 degrees, possibly even less, without problems. The cutting needs time but if You move a pen around, I can understand You.
How were you able to implement that with a 5 degree gap?
Study the Bresenham algorithm a bit longer. It contains a loop that produces a single step in X or Y direction. Now you have to slow down that loop, so that the steps fit the maximum frequency of your stepper motors - see BlinkWithoutDelay example.
For circles you have to evaluate each quadrant in sequence. The code you have seen may assume a display, where pixels can be set at random places, what does not apply to pen plotters or the like.