Searching \ for 'Drawing Circles & Spirals' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/io/serial/spis.htm?key=spi
Search entire site for: 'Drawing Circles & Spirals'.

Truncated match.
'Drawing Circles & Spirals'
1999\03\17@054949 by

Hi PICkers,

I have a PIC controlling 2 stepper motors connected to a light source.

I need to move the light source in a circle and a spiral.

Does anyone have PIC / 8031 based algorithm to draw circles ?

Thanks

Pailoor

================================================
For Embedded Controls Solutions and Custom Designs
------------------------------------------------------------------------

CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore
INDIA
Email   : chiptechvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th Feb 1999 )
================================================

I'm assuming you have one stepper in for each axis (say X and Y).
A simple way to generate the circle would be to move the light cource to
the position given by:

X=A cos wt
Y=A sin wt

where: A is a constant which controls amplitude of motion
w is a constant wich controls the speed of rotation.

To control the light source, it would be simply a matter of generating
sin and cos waves  (or two sine waves 90 degrees out of phase).
Obviously, you can extend this idea to make squares (from square waves)
and other results from other signals.

I've never delt with stepper motors so maybe someone else with more
experience can be of more help.  Sorry about the typos, it's late here.

Regards,

Vincent Deno

{Quote hidden}

--------------
Vincent Deno
Design Engineer
Theta Digital Corp.
denovjemail.uc.edu
_____________
| ____   ____ |
|/| | | | | |\|
| | |/| |\| | |
| | | | | | | |
| |_/ | | \_| |
| |   | |   | |
|_/  /___\  \_|

r=(x^2+y^2)^.5

use a table to store x & y values for 0 to 90 degrees in your minimum
step size. if accuracy is important and table size is small then you
must interpolate values inbetween table entries.

use the microchip application notes to do the maths.

quadrants after 0 to 90 degrees can be easily calculated by negating of
y(90 to 180), x and y(180 to 270), x(270 to 360(0)) values.

Alternativly...

connect the servo motors to match the axis used ie rotation servo,

regards,
Graham daniel.

Ravi Pailoor wrote:
{Quote hidden}

--
Steam engines may be out of fashion, but when you consider that an
internal combustion engine would require recovery of waste heat by
transfer just before top dead centre then fashion becomes rather
redundant, USE STRATIFIED HEAT EXCHANGERS ! and external combustion.

You heard it first from: Graham Daniel, managing director of Electronic
Product Enhancements.
Phone NZ 04 387 4347, Fax NZ 04 3874348, Cellular NZ 021 954 196.

On Thu, 18 Mar 1999, Graham Daniel wrote:

> r=(x^2+y^2)^.5
>
> use a table to store x & y values for 0 to 90 degrees in your minimum
> step size. if accuracy is important and table size is small then you
> must interpolate values inbetween table entries.

PTM: You don't need y -table at all. Use x table backwards:

--------------------------------------------------------------------------
PTM, ptmustautu.fi, http://www.utu.fi/~ptmusta                 OH1HEK
Lab.ins. (mikrotuki) ATK-keskus/Mat.Luon.Tdk                    OI7234
Lab.engineer (PC support) Computer Center
Mail: Turun Yliopisto / Fysla,  20014 Turku
Pt 02-3336669, FAX 02-3335632 (Pk 02-2387010, NMT 0400-555577)
--------------------------------------------------------------------------

Do a web search for Bresenham's algorithm. (I have only got one in C)
Bresenham was responsible for integer line algorithims for plotters. His
techniques were then used to produce integer algorithims for circles.

Theses algorithms are designed for x-y plotters and use no floating
point calculations.

Ravi Pailoor wrote:
{Quote hidden}

--
Peter Williamson | Phone: +61 15 898934
Waybeat Pty Ltd  | Email: peterwwaybeat.com.au

Thanks PIClisters, I will try out the suggestions and tell you the result.

Regards

Pailoor

================================================
For Embedded Controls Solutions and Custom Designs
------------------------------------------------------------------------
CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore
INDIA
Email   : chiptechvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th Feb 1999 )
================================================

On Wed, 17 Mar 1999 06:11:10 -0500 Vincent Deno <denovjEMAIL.UC.EDU>
writes:
>I'm assuming you have one stepper in for each axis (say X and Y).
>A simple way to generate the circle would be to move the light cource
>to
>the position given by:
>
>X=A cos wt
>Y=A sin wt

Avoid complicated math by essentially calculating the sine and cosine
terms iteratively.  Observe that the derivitive of cos(x) is -sin(x) and
the derivative of sin(x) is cos(x).  So if you have two numbers that are
the sine and cosine of some angle, you can find the sine and cosine of
some slightly larger angle this way:

S = S + k*C
C = C - k*S

Where k is some constant much smaller than 1 (if the largest values of S
and C are 1).

It can be directly applied to drawing circles.  Start with X = r and Y =
0, then use these equations to step around the circle:

Y = Y + k*X
X = X - k*Y

Similar simple equations could be done to make spirals.  Will these make
a spiral?  I'd have to try it.

X = X - k*Y + j*X
Y = Y + k*X + j*Y

___________________________________________________________________
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

Actually, I was simply giving an idea on how one might approach the
problem.  To implement this, I might simply use a lookup table to find the
appropriate value (for the given time).  And yes, the same lookup table
could (and should) be used to get values for both sin and cos functions.

Making the spiral is easy from the given info... simply decrease the
amplitude with time.

Regards,

Vincent Deno

> On Wed, 17 Mar 1999 06:11:10
-0500 Vincent Deno <denovjEMAIL.UC.EDU> > writes:
{Quote hidden}

--------------
Vincent Deno
Design Engineer
Theta Digital Corp.
denovjemail.uc.edu
_____________
| ____   ____ |
|/| | | | | |\|
| | |/| |\| | |
| | | | | | | |
| |_/ | | \_| |
| |   | |   | |
|_/  /___\  \_|

At 16:22 03/17/99 +0530, Ravi Pailoor wrote:
>I have a PIC controlling 2 stepper motors connected to a light source.
>
>I need to move the light source in a circle and a spiral.
>
>Does anyone have PIC / 8031 based algorithm to draw circles ?

i assume you have the step motors controlling the x and y directions
linearily, right? then you need a sine function. scott dattalo has one at
http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html

for a circle, x and y are 90¡ shifted in their phase.

ge

1999\03\17@134756 by
> At 16:22 03/17/99 +0530, Ravi Pailoor wrote:
> >I have a PIC controlling 2 stepper motors connected to a light source.
> >
> >I need to move the light source in a circle and a spiral.
> >
> >Does anyone have PIC / 8031 based algorithm to draw circles ?

All in the nature tend to a simple solution.
It depends on if you need to move the light source or just the light
beam.

1) Moving the light beam:

Keep the light beam source fixed, projecting the beam over a rotating
mirror, will create a projected circle.
Just use a small mirror attached to the motor shaft. The mirror (1 or 2
inches diameter) needs to be "glued" at 90¡ to the shaft, less the
generated rotational cone angle.

The general formula is:
DPC = DP x TAN(Ax2)
where DPC: Diameter of Projected Circle
DP : Distance from the mirror to the Projection Screen
A  : Mirror Angle (from the perpendicular 90¡)

If you glue the mirror at 85¡ at the motor shaft, if the screen is at 30
inches from the mirror, it will project a circle with a diameter:   2 x
30 x Tan((90-85)x2) = 10.57"

I did something like that with laser, and to adjust the mirror angle, I
just used a tick wire (big paper clip) 1/2" long, as an intermediate
connection between the motor shaft and the mirror, so you can bend the
wire with a pliers and adjust it to the correct angle you want,

To generate a spiral this mirror need to has a convex surface and the
second motor with another mirror will control the position of the beam
over this convex mirror.

It not only creates a spiral but very interesting effects mixing up with
the motors speed.

2) Moving the light source (lamp).

Forget about to use a x/y positioning table if you want simplicity, just
use a translation system from the first motor, as a mechanical lever
which one side of this arm will be attached to the side of a wheel in
the shaft of this motor (like an old locomotive wheel), while the lamp
will be at the other extreme of this arm (lever).  The pivot of this arm
is a movable pin connected to the second motor shaft wheel, in a linear
movement construction. As the second motor moves this pin towards the
lamp, the rotation diameter reduces, as it moves towards the first
motor, it increases, so you can control the spiral this way.

In any case there is no sine calculations to do, just a linear control
over the motor position. Im both cases the second motor will do a
maximum of half rotation to control the spiral, while the first one will
do a full rotation to each lamp apparent rotation.  The spiral number of
loops will be some relation between the steps from the first motor to
the second.  If you rotate the second motor in complete circles, you
will have spirals going in and out in a endless loop.

In this second case, the lamp needs to have enough movable flex wires,
but the lamp doesn't rotate itself, since it is fixed at the end of the
arm.

If you want challenge, for for the x-y encoding table.  Remember that
you have several ways to build that.

Wagner

Ravi Pailoor wrote:
>
> Does anyone have PIC / 8031 based algorithm to draw circles ?

and then Gerhard Fiedler replied:

>
> i assume you have the step motors controlling the x and y directions
> linearily, right? then you need a sine function. scott dattalo has one at
> www.interstice.com/~sdattalo/technical/software/pic/picsine.html
>
> for a circle, x and y are 90¡ shifted in their phase.

thanks for the plug, but then Peter Williamson suggested:

> Do a web search for Bresenham's algorithm.

So I did and found this:

http://www.robots.ox.ac.uk/~awf/graphics/bres-ellipse.html

Bresenham's algorithm would be the preferred method for 'drawing
circles' in most systems. (This was discussed not too long ago, BTW.
However, I couldn't find the thread in the archives). However, if you
use mine or Eric Smith's sine tables, I think you'll find that it's
faster to generate circles using sines and cosines (especially for unity
radius :]) on a pic. I'm not sure if there is even a Bresenham algorithm
for spirals...

The equations for a circle, ellipse, or spiral can all be expressed
similarly:

x = r1(t) * cos(w*t)
y = r2(t) * sin(w*t)

for a circle, r1 = r2 and are constant.
for an ellipse, r1 != r2, but both are constant.
for a spiral, r1 = r2 and are functions of time.

You can also get elliptical spirals by making r1 != r2.

If you wanted a circular spiral that spiraled inward:

r1 = r2 = R_max - k*t   for k*t < R_max

You can make logarithmic spirals by varying r1 and r2 exponentially (or
logarithmically).

It wouldn't be too hard to extend these concepts to generate lissajous
patterns or cycloids (e.g. spiral-graph).

Scott

Hi PICkers,

The light source is fixed, Wagner. I have a mirror fixed to a stepper
motor
M1. The other stepper motor M2 moves M1.

I have received more than  8 suggestions which I need to consolidate.
I have to convert all the formule to PIC code and come up with the best
solution. Once I am successful ( if I am ) , I will post the code for
others to
use.

Thanks a lot PICkers.

Regards

Pailoor

================================================
For Embedded Controls Solutions and Custom Designs
------------------------------------------------------------------------
CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore
INDIA
Email   : chiptechvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th Feb 1999 )
================================================

|Bresenham's algorithm would be the preferred method for 'drawing
|circles' in most systems. (This was discussed not too long ago, BTW.
|However, I couldn't find the thread in the archives). However, if you
|use mine or Eric Smith's sine tables, I think you'll find that it's
|faster to generate circles using sines and cosines (especially for unity
|radius :]) on a pic. I'm not sure if there is even a Bresenham algorithm
|for spirals...

Actually, if you have a sine/cosine function/table you can generate
variable-sized circles without any multiplication:

just plot (for variable t and fixed Q)

x=cos(t)+cos(t+Q)
y=sin(t)+sin(t+Q)

If Q increases or decreases while you're running the plots, you'll get
shapes that spiral in and out.  If you want to be able to get a specific
radius of circle, you'll need a table to translate the desired radius
into the Q value.  Note that the function for converting Q into radius
is:

radius = sqrt ((1+cos(Q))^2 + sin(Q)^2)
= sqrt (1 + 2cos(Q) + cos(Q)^2 + sin(Q)^2)
= sqrt (2 + 2cos(Q))

so it's probably easiest just to use an R->Q table.

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...