An attempt at algorithm creation

A turntable needs to be positioned depending on user input.
This system consists of

  1. a steppermotor driven turntable
  2. a 4x4 keypad for user commands
  3. a rotary encoder for manual tunrtable positioning
  4. a photocell for absolute positioning (calibration to a '0' position)

Below is a sheet with possible turntable scenarios (current position and target position) that must be solved using an algorithm that I have a hard time finding.

some additinal information is required:

  1. scenarios 1 through 3 are "straight through", scenarios 4 & 5 are "reversing"
  2. the user must select a target with prior indication whether it must be "straight through" or "reversing" by using the key '#' (straight) or '*' (reversing), before selecting a target destination. This means that a different algorithm can be used depending on this key choice.
  3. the numbers on the drawings correspond to an actual amount of steppermotor steps (CCW) from a calibrated '0' position.
  4. each position has an index number that corresponds to these number of steps, per position.
  5. the '0' position is obtained by turning the table until a photosensor is reached (CCW).

The solution is far from a simply subtracting of positions: the algorithm must for each case calculate the number of steps, both CW and CCW, and select the shortest route.

EDIT: for algorithm input the only givens are 'target position', 'current position' and total number of steps for a full revolution.

And the algorithm will be different whether a "straight through" path or a "reversing path" is selected.

EDIT: how do I attach a document? ..ok, done
scenarios scanned v2.pdf (283.4 KB)

better to attach directly a JPEG so that people can see what you mean

1 Like

I'd think of the different actions that a non-trivial process like needs to do as a state diagram:

image -- live graphviz editor

...and then make a state machine to handle the different transitions between the tasks that the process is supposed to accomplish.

I'm sure I don't understand.

If there is a choice of CCW or CW, what means "straight through" v. "reversing path" and why is there still a need to "select the shortest route"?

It's tired, though, and I'm pretty late, so there's that. It prolly makes perfecg sense. :expressionless:

a7

@DaveX no offence intended but you are kicking an open door. My question relates the contents of the "reversing" and "forward" in your sort-of flowchart.
Besides your proposal negates the contents of my stated prerequisites.

@alto777

  1. the choice for CW or CCW must be taken by the algorithm
  2. "straight through" means that whatever moves forward (ie "head first", from the current position onto the turntable, is also moving forward "head first" onto the target path.
  3. "reversing" means that whatever is moved from the current position onto the turntable first is turned around 180 degrees, and after turntable positioning, is moved "head last" onto the target position

You can see the little marks at one end of the turntable rotating plate.
In essence, the turntable rotating plate is polarised.

EDIT: "shortes route" is to minimise the time it takes to rotate the turntable from "current" to "target".

are those the correct answers ?

I don't understand the first one for example

going from step 200 to step 900 takes 700 steps if you go the direct route and takes 1300 steps if you go in the opposite direction

calculating this is simple maths depending on relative C and T positions if you don't want to do modulo

struct {
  uint16_t c;
  uint16_t t;
  uint16_t R;
  bool reversed;
} scenario[] = {
  {200,  900, 2000, false},
  {200, 1500, 2000, false},
  {100,  200, 2000, false},
  {200,  800, 2000, true},
  {200, 1500, 2000, true},
};


void setup() {
  Serial.begin(115200);

  for (auto & s : scenario) {
    uint16_t cw, ccw;
    if (s.c > s.t) {
      cw = (s.c - s.t);
      ccw = (s.R - s.c) + s.t;
    } else {
      cw = s.c + (s.R - s.t);
      ccw = s.t - s.c;
    }
    Serial.print("C = "); Serial.println(s.c);
    Serial.print("T = "); Serial.println(s.t);
    Serial.print("R = "); Serial.println(s.R);

    Serial.print("CW = "); Serial.println(cw);
    Serial.print("CCW = "); Serial.println(ccw);
    Serial.println("-----------");
  }
}

void loop() {}

see results here

and I did not understand what reversed means and how it should be taken into account since you stated it's not an input to the algorithm

@J-M-L hi J_M_L,

in the first scenario going CW = C + R/2 - T = 200 + 1000 - 900 = 300.
Going CCW the rotating table needs to make a full CCW turn (ie F / 2), and subsequentlye move from 200 to 900. Hence, CCW = C + F/2 + abs( T - C) = 200 + 1000 + (900-200) = 1700.

EDIT: remember that the rotating table polarity must be respected. In scenario 1 an item is moved head first onto the rotating tbable and upon exit it must also be head first into position 900.

sorry I've no idea what you mean by polarity or head first or what the item has to do with it.

Also if your algorithm input is only 'target position', 'current position' and total number of steps for a full revolution then I don't see how those matters anyway

" .. and I did not understand what reversed means and how it should be taken into account since you stated it's not an input to the algorithm.." Yes it is: the user either presses # for "straigth move" or * for a reversing move (see scenarios 4 & 5)

The turntable as shown has a little square mark on the turning plate, on one end of the turning table. That is a polarising mark.

I guess my English is not good enough to understand your use case...

That's how I interpreted your explanation

ah, I now see the little flag on your drawing and in scenario 5 it ends up flipped (flag was right of the pole at the top and is to the left at the bottom)

how can that happen ? is that an object sitting on the turn table ? how do you flip it ? it won't happen by just rotating the table underneath

I can't make any sense of what you said... sorry

@J-M-L : for scenario 1, CCW

  1. first a CCW rotation of 180 degrees: 1000 steps until the square notch on the turntable rotator sits at the opposite end of position "200".
  2. next a further CCW rotation so that the "non-square noth" side of the turntable moves from its position obtained in "1" here above,; alligns with the 900 target position.
    Total CCW moves:
  3. 1000 steps CCW until the table is turned 180 degrees
  4. another 900 - 200 = 700 steps until the "non-square notch" part of the turntable alligns wioth target 900.

That little square notch is to indicate the polarity of the turntable.

At every intial move, a device moves "head first" onto the rotating table.

The the rotating table must move in such a way, for the "straight" move (not the "inverting or reversing move") that the device (that had been run onto the turntable head first) now also moves "head-first" into the target position.

" ...how can that happen ? is that an object sitting on the turn table ? how do you flip it ? it won't happen by just rotating the table underneath..."

The idea is that an object moves, from the target position, "head-first" onto the rotating table.

If a "non-reversing" button is pressed before a target position is selected, the this object also has to move "head-first" into the target position.

EDIT: the rotating table is exactly what you see as the single diagonal line in the circle. The square noth shows its actual "polarityu".

is the "little square notch" what I call the flag ?
image

can you do a time line drawing ?

:bulb: Do I get this right:

the top of the "flag" is at 200 and you want to rotate so that the tail of the pole ends up at 900

is that it ?

for the last 2 examples, how does the "flag" get flipped ? I don't get that