Erroneous movement in Spirograph installation

Hello!

I have an installation in which it will draw a spirograph pattern. The motors are set up so motor 1 controls a shaft's yaw rotation, and the other controls the print heads distance down the shaft.

I have written code to generate a spirograph, and it works
See here: Scratch Project Demo for a graphical demo.
I have also written the arduino code, here:

uint16_t ar=30;//Circle A radius
uint16_t br=90;//Circle B radius
uint16_t hr=37;//Hole's distance from B's center
double ac;//Circle a's circumference
double bc;//Circle b's circumference
const double tau=2*PI;
bool reversed=0;
uint8_t resolution=100;
double aTheta=0;
double bTheta=0;
uint16_t maxDist;
uint16_t minDist;
void resetParams(){
  ac=ar*tau;
  bc=br*tau;
  maxDist=ar+hr;
  minDist=hr-ar;
  aTheta=0;
  bTheta=0;
}
void loopSpiral(){
  double x=ar*cos(aTheta)+hr*cos(bTheta);
  double y=ar*sin(aTheta)+hr*sin(bTheta);
  double theta=atan2(y,x);
  double r=sqrt(sq(x)+sq(y));
  gotoPos(map(theta,0,tau,0,800),r);//map(r,minDist,maxDist,0,1600));
  bTheta+=(reversed)?-tau/resolution:tau/resolution;
  aTheta=bTheta*(ac/bc);
}

(not all code shown here,
resetParams called in setup,
loopSpiral called in loop,
gotoPos just moves the motors, one theta axis and the other radius axis)

But, the motors move erratically.
One, the theta axis, makes a sweeping motion, from -200 to 200 steps repeatedly
The other, the radial axis, makes little movements back and forth.
I'm thinking that the code that is broken is the cartesian -> polar conversion, but I'm not sure. I know the spirograph code works, as it's copied directly into scratch (do remember that arduino is in rads, and scratch in deg)

Any help as to what's going on here?

uint16_t ar=30;//Circle A radius

Get your space key fixed.

uint16_t ar = 30; // Circle A radius

(not all code shown here,

Not all answer shown here, then.

Hi,
Welcome to the forum.

What are your motors and how are you controlling them.
And how are you powering the project?

We need all your code so we can see you input and output setups.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks .. Tom.. :slight_smile:

Hi!

You all seem to be SUPER set on me uploading the full thing, despite me having told you all that you need to know. But, attached is the full thing, if you so desire.

I did not see it necessary to attach them in the original, as it was a math question...

TomGeorge:
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

That's exactly what I did. Is it rendering incorrectly for you? Works for me...

Thanks for your replies!

Hi,
Sorry but no code, just what you have posted on your first post.

If you get a message about it being too many characters then, use REPLY rather than QUICK REPLY and it has an attachment facility, so you can post your sketch as an attachment, but try code tags first.

Tom... :slight_smile: