# [CentralOH] State The Problem Simply

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Sun Dec 8 23:06:01 CET 2013

```State your problem simply.

On Sun, 8 Dec 2013 16:10:09 -0500, Louis Bogdan <looiebwv at gmail.com> wrote:

> I see that there are some questions about my explanation of what I'm trying
> to do.  Would it clarify things if my explanation read as follows:
> num(-1) denotes right-hand most digit of num in index position notation
> num(-2) denotes the 3rd position digit of num in index position notation.

All the talk about picking out digits and doing things depending
on which digit has which value is an awkward way of stating your
problem.

> I don't know how to say it in computer language, ...

So say it in engunearing English.

The following is an example of how to simply state a problem.

I have stepper motors with a given resolution.

For a given absolute position and stepper motor resolution,
I want to calculate the number of absolute
steps that is closest to the given absolute position.

How would I do that in Python?

The above is just an example of how to state a problem simply.
The problem stated above is different that your problem.

I could have made the statement complicated by mentioning a
particular resolution and what to do based on which digit has
which value. That would just obscure the problem.

A solution to the above problem might be something like:

def foo(d, steps_per_unit):
'''Returns number of stepper motor steps
closest to given distance d,
for stepper motor step resolution steps_per_unit.

Unit in steps_per_unit must be same as unit of d.'''

return int(round(d * steps_per_unit))

MOTOR_STEP_RATE = 2000  #  Unit is 1 step/inch.

foo(1.23456, MOTOR_STEP_RATE)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

A solution to the another problem might be something like:

def goo(d, steps_per_unit):
'''Returns closest distance to d that a
steps_per_unit stepper motor can achieve.

Unit in steps_per_unit must be same as unit of d.'''
return round(d * steps_per_unit) / steps_per_unit

MOTOR_STEP_RATE = 2000  #  Unit is 1 step/inch.

goo(1.23456, MOTOR_STEP_RATE)

```