Tracy type math question
Archiver
Posts: 46,084
Hi All,
Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has 48
steps per revolution. I am working on a turret style ultrasonic range
detector. What I want to do is figure out which direction (clockwise or
counter-clockwise) is the fastest direction to travel between point A and
point B. As an example, assume 12 o'clock is positon 0. If am at position
27, and I want to go to position 47, I obviously want to go clockwise to get
to the desired position in the least number of steps. I know there is a
tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
Thanks!
Jonathan
www.madlabs.info
Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has 48
steps per revolution. I am working on a turret style ultrasonic range
detector. What I want to do is figure out which direction (clockwise or
counter-clockwise) is the fastest direction to travel between point A and
point B. As an example, assume 12 o'clock is positon 0. If am at position
27, and I want to go to position 47, I obviously want to go clockwise to get
to the desired position in the least number of steps. I know there is a
tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
Thanks!
Jonathan
www.madlabs.info
Comments
Maybe the following code will work for you:
if actual_position < total_of_steps/2 then turn_anticlockwise else
turn_clockwise
Let me know the results.
Regard,
Klaus
--- In basicstamps@yahoogroups.com, "Jonathan Peakall"
<jpeakall@p...> wrote:
> Hi All,
>
> Me and math again. Ugh. I am using a 7.5 degree stepper motor,
which has 48
> steps per revolution. I am working on a turret style ultrasonic
range
> detector. What I want to do is figure out which direction
(clockwise or
> counter-clockwise) is the fastest direction to travel between point
A and
> point B. As an example, assume 12 o'clock is positon 0. If am at
position
> 27, and I want to go to position 47, I obviously want to go
clockwise to get
> to the desired position in the least number of steps. I know there
is a
> tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
>
> Thanks!
>
> Jonathan
>
> www.madlabs.info
if( 48 - A ) / 2 < 24 go CW
else go CCW
Dennis
Original Message
From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=AiclX4mB4c0gLmunNh_N62JmfWxueif1mf2ADhnVUxW3fkDYkh3Ss_iHDJwzvC8paUd7m46rV7XpoC1L]jpeakall@p...[/url
Sent: Saturday, March 20, 2004 2:53 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Tracy type math question
Hi All,
Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has
48 steps per revolution. I am working on a turret style ultrasonic range
detector. What I want to do is figure out which direction (clockwise or
counter-clockwise) is the fastest direction to travel between point A
and point B. As an example, assume 12 o'clock is positon 0. If am at
position 27, and I want to go to position 47, I obviously want to go
clockwise to get to the desired position in the least number of steps. I
know there is a tricky math solution to this, I'm just not smart enough
to see it [noparse]:([/noparse]
Thanks!
Jonathan
www.madlabs.info
Assume A is current position.
if( 48 - A ) < 24 go CW
else go CCW
Dennis
Original Message
From: Dennis O'Leary [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=OSNFAaVnJrqGRrihPx8E00yH1EQ0uI6a9K6vSgDmNXHCPCsv-AMc9a6unGfjmC3TxknW0V7Xh9o]doleary@u...[/url
Sent: Saturday, March 20, 2004 4:19 PM
To: basicstamps@yahoogroups.com
Subject: RE: [noparse][[/noparse]basicstamps] Tracy type math question
Assume A is current position.
if( 48 - A ) / 2 < 24 go CW
else go CCW
Dennis
Original Message
From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=alSwHatm7JVCDTa1Di_5qYtjnsrlJOUHxqQAxkjO2uI0NL6D_lxaWykgf0CDx2sUzC6R_K1RNLMFwVLP7A]jpeakall@p...[/url
Sent: Saturday, March 20, 2004 2:53 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Tracy type math question
Hi All,
Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has
48 steps per revolution. I am working on a turret style ultrasonic range
detector. What I want to do is figure out which direction (clockwise or
counter-clockwise) is the fastest direction to travel between point A
and point B. As an example, assume 12 o'clock is positon 0. If am at
position 27, and I want to go to position 47, I obviously want to go
clockwise to get to the desired position in the least number of steps. I
know there is a tricky math solution to this, I'm just not smart enough
to see it [noparse]:([/noparse]
Thanks!
Jonathan
www.madlabs.info
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
Assume A is current position. To go to B:
if( B - A ) < 24 go CW
else go CCW
Dennis
Original Message
From: Dennis O'Leary [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=pGx4CPNGIKBVAxWG-rSHYzPrfbXbnps-ogVDfMAaDagXvkNf-Qkm2UA8T1_FYF_yGGKTbnVk]doleary@u...[/url
Sent: Saturday, March 20, 2004 4:19 PM
To: basicstamps@yahoogroups.com
Subject: RE: [noparse][[/noparse]basicstamps] Tracy type math question
Assume A is current position.
if( 48 - A ) / 2 < 24 go CW
else go CCW
Dennis
Original Message
From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=_N-qWMBpB25w56Ku0SWGk1rGCJNXGxwQrLQt8biHSinzOrWDVx-eO5oDt0Gb0gJakxNl8_MpPdJYvuA]jpeakall@p...[/url
Sent: Saturday, March 20, 2004 2:53 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Tracy type math question
Hi All,
Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has
48 steps per revolution. I am working on a turret style ultrasonic range
detector. What I want to do is figure out which direction (clockwise or
counter-clockwise) is the fastest direction to travel between point A
and point B. As an example, assume 12 o'clock is positon 0. If am at
position 27, and I want to go to position 47, I obviously want to go
clockwise to get to the desired position in the least number of steps. I
know there is a tricky math solution to this, I'm just not smart enough
to see it [noparse]:([/noparse]
Thanks!
Jonathan
www.madlabs.info
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
Depressing that everyone else gets the answer so easy! Why am I left in the
dark ;-)
Thanks for the help, should work great! I'll try it out to-morrow.
Jonathan
www.madlabs.info
Original Message
From: "Dennis O'Leary" <doleary@p...>
To: <basicstamps@yahoogroups.com>
Sent: Saturday, March 20, 2004 4:41 PM
Subject: RE: [noparse][[/noparse]basicstamps] Tracy type math question
> Yikes! This is my last attempt:
>
> Assume A is current position. To go to B:
>
> if( B - A ) < 24 go CW
> else go CCW
>
> Dennis
>
>
>
Original Message
> From: Dennis O'Leary [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=PkegZIpnJeULNAOtZ4kkQpexMuieqjD6vuf7EOeal51EKdWq4KkGkpxo8cp6luePFsiciave_NY]doleary@u...[/url
> Sent: Saturday, March 20, 2004 4:19 PM
> To: basicstamps@yahoogroups.com
> Subject: RE: [noparse][[/noparse]basicstamps] Tracy type math question
>
>
> Assume A is current position.
>
> if( 48 - A ) / 2 < 24 go CW
> else go CCW
>
> Dennis
>
>
Original Message
> From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=6uhqhHasH69FZxq_oW7svxRcoduP4cMIwTPUfHIkUMLqIm5pIsECnEQfT23yRBEEE-P3leTnoJBBtrZapA]jpeakall@p...[/url
> Sent: Saturday, March 20, 2004 2:53 PM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Tracy type math question
>
>
> Hi All,
>
> Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has
> 48 steps per revolution. I am working on a turret style ultrasonic range
> detector. What I want to do is figure out which direction (clockwise or
> counter-clockwise) is the fastest direction to travel between point A
> and point B. As an example, assume 12 o'clock is positon 0. If am at
> position 27, and I want to go to position 47, I obviously want to go
> clockwise to get to the desired position in the least number of steps. I
> know there is a tricky math solution to this, I'm just not smart enough
> to see it [noparse]:([/noparse]
>
> Thanks!
>
> Jonathan
>
> www.madlabs.info
>
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject
> and Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
<jpeakall@p...> wrote:
> Denis, Klaus,
>
> Depressing that everyone else gets the answer so easy! Why am I
left in the
> dark ;-)
>
> Thanks for the help, should work great! I'll try it out to-morrow.
>
> Jonathan
Seems that this would not work when one is at pos 7 and wants to go
to pos 47.
( 47 - 7 ) = 40
40 < 24 = false = go CC
compare a different 8 step seperation
17 - 25 = -8
====================================
Am I correct on this ? or am I missing somethng ?
Dave
Drat! You are correct. Any ideas how to do this?
Jonathan
www.madlabs.info
Original Message
From: "Dave Mucha" <davemucha@j...>
To: <basicstamps@yahoogroups.com>
Sent: Sunday, March 21, 2004 8:15 AM
Subject: [noparse][[/noparse]basicstamps] Re: Tracy type math question
> --- In basicstamps@yahoogroups.com, "Jonathan Peakall"
> <jpeakall@p...> wrote:
> > Denis, Klaus,
> >
> > Depressing that everyone else gets the answer so easy! Why am I
> left in the
> > dark ;-)
> >
> > Thanks for the help, should work great! I'll try it out to-morrow.
> >
> > Jonathan
>
>
>
> Seems that this would not work when one is at pos 7 and wants to go
> to pos 47.
>
> ( 47 - 7 ) = 40
>
> 40 < 24 = false = go CC
>
> compare a different 8 step seperation
>
>
> 17 - 25 = -8
>
> ====================================
>
>
> Am I correct on this ? or am I missing somethng ?
>
>
> Dave
>
>
>
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
correct solution for all cases is to use 2 conditional tests instead of
one to keep results positive.
Let A = current position.
Let B = next position.
if A > B
if (A-B) < 24 go CCW
else go CW
else
if (B-A) < 24 go CW
else go CCW
Dennis
Original Message
From: Dave Mucha [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=XjUiByUVhmT82ZGKnZ6AqLEQJRdS4cjzcaHIY9ohDU9l8AzGb4T7rlflpb_-z7LdFr6oQ4XkZ5ivtXs]davemucha@j...[/url
Sent: Sunday, March 21, 2004 8:16 AM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Re: Tracy type math question
--- In basicstamps@yahoogroups.com, "Jonathan Peakall"
<jpeakall@p...> wrote:
> Denis, Klaus,
>
> Depressing that everyone else gets the answer so easy! Why am I
left in the
> dark ;-)
>
> Thanks for the help, should work great! I'll try it out to-morrow.
>
> Jonathan
Seems that this would not work when one is at pos 7 and wants to go
to pos 47.
( 47 - 7 ) = 40
40 < 24 = false = go CC
compare a different 8 step seperation
17 - 25 = -8
====================================
Am I correct on this ? or am I missing somethng ?
Dave
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
Your magic number is 24
NP = New Position
CP = Current Position
THEN
If NP = CP then DO_NOTHING
If NP > CP then State1
goto State3 'Because NP < CP
:
:
State1: If NP < CP+24 Then State2 ' less than 24 step away CCW
Clockwise 'Else CW
GOTO DO_NOTHING
State2: Counter Clockwise
: GOTO DO_NOTHING
:
State3: If 100 + CP < 124 + NP Then State4 ' CP < NP +24 means NP is
' closest CCW NOTE: 100
' arbitrary number to avoid
' negative numbers
Clockwise ' Else closest CW
goto DO_NOTHING
State4: COunter Clockwise
goto DO_NOTHING
DO_NOTHING: ' Continue
How's this look?
CAT
--- In basicstamps@yahoogroups.com, "Jonathan Peakall" <jpeakall@p...>
wrote:
> Hi All,
>
> Me and math again. Ugh. I am using a 7.5 degree stepper motor, which
has 48
> steps per revolution. I am working on a turret style ultrasonic
range
> detector. What I want to do is figure out which direction
(clockwise or
> counter-clockwise) is the fastest direction to travel between point
A and
> point B. As an example, assume 12 o'clock is positon 0. If am at
position
> 27, and I want to go to position 47, I obviously want to go
clockwise to get
> to the desired position in the least number of steps. I know there
is a
> tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
>
> Thanks!
>
> Jonathan
>
> www.madlabs.info
correct, but the State3 test is over complicated. I originally did a
subtraction and switch things to do an addition so the 100 shift is
no longer necessary.
NP = New Position
> CP = Current Position
>
> THEN
>
>
> If NP = CP then DO_NOTHING
> If NP > CP then State1
> goto State3 'Because NP < CP
> :
> :
> State1: If NP < CP+24 Then State2 ' less than 24 step away CCW
> Clockwise 'Else CW
> GOTO DO_NOTHING
State3: If CP < 24 + NP Then State2
Clockwise 'Else CW
> GOTO DO_NOTHING
> State2: Counter Clockwise
> : GOTO DO_NOTHING
> :
>
> DO_NOTHING: ' Continue
>
--- In basicstamps@yahoogroups.com, "catgirldo" <catgirldo@y...> wrote:
> I THINK you need a double check on each side of the equation.
> Your magic number is 24
> NP = New Position
> CP = Current Position
>
> THEN
>
>
> If NP = CP then DO_NOTHING
> If NP > CP then State1
> goto State3 'Because NP < CP
> :
> :
> State1: If NP < CP+24 Then State2 ' less than 24 step away CCW
> Clockwise 'Else CW
> GOTO DO_NOTHING
> State2: Counter Clockwise
> : GOTO DO_NOTHING
> :
> State3: If 100 + CP < 124 + NP Then State4 ' CP < NP +24 means NP is
> ' closest CCW NOTE: 100
> ' arbitrary number to avoid
> ' negative numbers
> Clockwise ' Else closest CW
> goto DO_NOTHING
> State4: COunter Clockwise
> goto DO_NOTHING
> DO_NOTHING: ' Continue
>
>
> How's this look?
>
>
> CAT
>
>
>
> --- In basicstamps@yahoogroups.com, "Jonathan Peakall" <jpeakall@p...>
> wrote:
> > Hi All,
> >
> > Me and math again. Ugh. I am using a 7.5 degree stepper motor, which
> has 48
> > steps per revolution. I am working on a turret style ultrasonic
> range
> > detector. What I want to do is figure out which direction
> (clockwise or
> > counter-clockwise) is the fastest direction to travel between point
> A and
> > point B. As an example, assume 12 o'clock is positon 0. If am at
> position
> > 27, and I want to go to position 47, I obviously want to go
> clockwise to get
> > to the desired position in the least number of steps. I know there
> is a
> > tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
> >
> > Thanks!
> >
> > Jonathan
> >
> > www.madlabs.info
Thanks a ton for all the help! I will try both methods posted tonight, and
see how it goes. Sitting here doing it on paper it looks good. Mind you, me
saying a math equation looks good means very, very little ;-)
Thanks to all!
Jonathan
www.madlabs.info
Original Message
From: "catgirldo" <catgirldo@y...>
To: <basicstamps@yahoogroups.com>
Sent: Monday, March 22, 2004 1:14 AM
Subject: [noparse][[/noparse]basicstamps] Re: Tracy type math question
> Darned! Never program late at night. I think the statements ARE
> correct, but the State3 test is over complicated. I originally did a
> subtraction and switch things to do an addition so the 100 shift is
> no longer necessary.
>
>
> NP = New Position
> > CP = Current Position
> >
> > THEN
> >
> >
> > If NP = CP then DO_NOTHING
> > If NP > CP then State1
> > goto State3 'Because NP < CP
> > :
> > :
> > State1: If NP < CP+24 Then State2 ' less than 24 step away CCW
> > Clockwise 'Else CW
> > GOTO DO_NOTHING
> State3: If CP < 24 + NP Then State2
> Clockwise 'Else CW
> > GOTO DO_NOTHING
> > State2: Counter Clockwise
> > : GOTO DO_NOTHING
> > :
>
> >
> > DO_NOTHING: ' Continue
> >
>
>
>
>
> --- In basicstamps@yahoogroups.com, "catgirldo" <catgirldo@y...> wrote:
> > I THINK you need a double check on each side of the equation.
> > Your magic number is 24
> > NP = New Position
> > CP = Current Position
> >
> > THEN
> >
> >
> > If NP = CP then DO_NOTHING
> > If NP > CP then State1
> > goto State3 'Because NP < CP
> > :
> > :
> > State1: If NP < CP+24 Then State2 ' less than 24 step away CCW
> > Clockwise 'Else CW
> > GOTO DO_NOTHING
> > State2: Counter Clockwise
> > : GOTO DO_NOTHING
> > :
> > State3: If 100 + CP < 124 + NP Then State4 ' CP < NP +24 means NP is
> > ' closest CCW NOTE: 100
> > ' arbitrary number to avoid
> > ' negative numbers
> > Clockwise ' Else closest CW
> > goto DO_NOTHING
> > State4: COunter Clockwise
> > goto DO_NOTHING
> > DO_NOTHING: ' Continue
> >
> >
> > How's this look?
> >
> >
> > CAT
> >
> >
> >
> > --- In basicstamps@yahoogroups.com, "Jonathan Peakall" <jpeakall@p...>
> > wrote:
> > > Hi All,
> > >
> > > Me and math again. Ugh. I am using a 7.5 degree stepper motor, which
> > has 48
> > > steps per revolution. I am working on a turret style ultrasonic
> > range
> > > detector. What I want to do is figure out which direction
> > (clockwise or
> > > counter-clockwise) is the fastest direction to travel between point
> > A and
> > > point B. As an example, assume 12 o'clock is positon 0. If am at
> > position
> > > 27, and I want to go to position 47, I obviously want to go
> > clockwise to get
> > > to the desired position in the least number of steps. I know there
> > is a
> > > tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
> > >
> > > Thanks!
> > >
> > > Jonathan
> > >
> > > www.madlabs.info
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
Delayed response due to weekend camping! Since I'm typecast in the
question (hehe), here is a little program for edification. It runs
through all the combinations of the 48 start and finish angles, and
shows which way to rotate and by how much. Since this is a problem
involving a circle, you can expect to find the Stamp's // operator.
'{$STAMP BS2pe}
'{$PBASIC 2.5}
' rotation planner, circle with 48 steps
' tracy@e...
a VAR Word ' starting step 0--47
b VAR Word ' move to step 0--47 by shortest angle
x VAR Word ' +/- 24 steps
FOR a=0 TO 47
FOR b=0 TO 47
DEBUG CR,"a:",DEC a,TAB,"b:",DEC b,TAB
SELECT b-a+48//48
CASE 0
DEBUG "stay"
CASE <24
DEBUG "cw"
CASE >=24
DEBUG "ccw"
ENDSELECT
x=b-a+72//48-24
DEBUG TAB,SDEC x ' this many steps
NEXT
NEXT
In the SELECT statement, it is (b-a+48//48) that does the work.
Adding 48 to the difference of the angles is needed, because the //
operator does not calculate well with negative numbers. In general,
(b-a) could land anywhere between -47 and +47. Adding 48 assures
that the result is positive, from 1 to 95. The // operator then puts
that back into a 48 unit circle. Values of (b-a) from -47 to -25 and
from 1 to 23 merit a cw rotation, while values of (b-a) from -24 to
-1 and from 24 to 47 merit a ccw rotation. The value 24 is really a
tossup, as it is the same number of steps to go either cw or ccw, but
I arbitrarily put it with ccw.
The formula x=b-a+72//48-24 tells the whole story. It gives the
number of steps, with + for cw and - for ccw and of course zero for
"already there".
-- Tracy
>Hi All,
>Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has 48
>steps per revolution. I am working on a turret style ultrasonic range
>detector. What I want to do is figure out which direction (clockwise or
>counter-clockwise) is the fastest direction to travel between point A and
>point B. As an example, assume 12 o'clock is positon 0. If am at position
>27, and I want to go to position 47, I obviously want to go clockwise to get
>to the desired position in the least number of steps. I know there is a
>tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
>Thanks!
>Jonathan
>www.madlabs.info
Does it hurt being that smart ;-)?
Thanks a ton. Your solution is slick. A student and I came up with another
method using the ABS function, but yours calcualtes the number of steps as
well, which is nice. Goes to show there are a number (pun intended) of ways
to skin this cat. Funny, as it seems on the surface a pretty easy problem.
Thanks again! And to all that replied.
Jonathan
www.madlabs.info
PS Hope you had fun camping. It's that time of year!
Original Message
From: "Tracy Allen" <tracy@e...>
To: <basicstamps@yahoogroups.com>
Sent: Tuesday, March 23, 2004 9:09 PM
Subject: Re: [noparse][[/noparse]basicstamps] Tracy type math question
> Hi Jonathan,
>
> Delayed response due to weekend camping! Since I'm typecast in the
> question (hehe), here is a little program for edification. It runs
> through all the combinations of the 48 start and finish angles, and
> shows which way to rotate and by how much. Since this is a problem
> involving a circle, you can expect to find the Stamp's // operator.
>
> '{$STAMP BS2pe}
> '{$PBASIC 2.5}
> ' rotation planner, circle with 48 steps
> ' tracy@e...
> a VAR Word ' starting step 0--47
> b VAR Word ' move to step 0--47 by shortest angle
> x VAR Word ' +/- 24 steps
> FOR a=0 TO 47
> FOR b=0 TO 47
> DEBUG CR,"a:",DEC a,TAB,"b:",DEC b,TAB
> SELECT b-a+48//48
> CASE 0
> DEBUG "stay"
> CASE <24
> DEBUG "cw"
> CASE >=24
> DEBUG "ccw"
> ENDSELECT
> x=b-a+72//48-24
> DEBUG TAB,SDEC x ' this many steps
> NEXT
> NEXT
>
> In the SELECT statement, it is (b-a+48//48) that does the work.
> Adding 48 to the difference of the angles is needed, because the //
> operator does not calculate well with negative numbers. In general,
> (b-a) could land anywhere between -47 and +47. Adding 48 assures
> that the result is positive, from 1 to 95. The // operator then puts
> that back into a 48 unit circle. Values of (b-a) from -47 to -25 and
> from 1 to 23 merit a cw rotation, while values of (b-a) from -24 to
> -1 and from 24 to 47 merit a ccw rotation. The value 24 is really a
> tossup, as it is the same number of steps to go either cw or ccw, but
> I arbitrarily put it with ccw.
>
> The formula x=b-a+72//48-24 tells the whole story. It gives the
> number of steps, with + for cw and - for ccw and of course zero for
> "already there".
>
> -- Tracy
>
>
> >Hi All,
> >Me and math again. Ugh. I am using a 7.5 degree stepper motor, which has
48
> >steps per revolution. I am working on a turret style ultrasonic range
> >detector. What I want to do is figure out which direction (clockwise or
> >counter-clockwise) is the fastest direction to travel between point A and
> >point B. As an example, assume 12 o'clock is positon 0. If am at position
> >27, and I want to go to position 47, I obviously want to go clockwise to
get
> >to the desired position in the least number of steps. I know there is a
> >tricky math solution to this, I'm just not smart enough to see it [noparse]:([/noparse]
> >Thanks!
> >Jonathan
> >www.madlabs.info
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>