Go Down

Topic: Erroneous movement in Spirograph installation  (Read 76 times) previous topic - next topic

Fuzzyzilla

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:
Code: [Select]

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?

PaulS

Code: [Select]
uint16_t ar=30;//Circle A radius
Get your space key fixed.

Code: [Select]
uint16_t ar = 30; // Circle A radius

Quote
(not all code shown here,
Not all answer shown here, then.

TomGeorge

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.. :)
Everything runs on smoke, let the smoke out, it stops running....

Fuzzyzilla

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...

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!

TomGeorge

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... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy