setServo(int servonum, int position) for 6-claw robot, how it works?

T tried this 6-claw robot:
6-claw robot

but I couldn't understand these code:

    switch (servonum) {
      case 6:
      case 7:
      case 9: servos[servonum]->write(position);
        break;
      case 0:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 8:
      case 10:
      case 11: servos[servonum]->write(180 - position);
        break;
    }

it was in this function:

void setServo(int servonum, int position) {
  if (position != ServoPos[servonum]) {
    ServoTime[servonum] = millis();
  }
  ServoPos[servonum] = position;  // keep data on where the servo was last commanded to go

  if (TrimInEffect && servonum < LEG_DOF) {
    //Console.print("Trim leg "); Console.print(servonum); Console.print(" "); Console.println(ServoTrim[servonum] - TRIM_ZERO);
    int p = map(position, 0, 180, SERVOMIN, SERVOMAX);
    p += ServoTrim[servonum] - TRIM_ZERO; // adjust microseconds by trim value which is renormalized to the range -127 to 128
    position = map(p, SERVOMIN, SERVOMAX, 0, 180);
  }
  if (!deferServoSet && servos[servonum]->attached()) {


#ifdef __VORPAL_FRAME__
    servos[servonum]->write(position);
#else
    switch (servonum) {
      case 6:
      case 7:
      case 9: servos[servonum]->write(position);
        break;
      case 0:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 8:
      case 10:
      case 11: servos[servonum]->write(180 - position);
        break;
    }
#endif
  }
  // DEBUG: Uncomment the next line to debug setservo problems. It causes some lagginess due to all the printing
  //Console.print("SS:");Console.print(servonum);Console.print(":");Console.println(position);
}

is here anyone know why the servonum in switch was not symmetrical?3 write(position) vs. 9 write(180 - position).

Means that if case is 6 or 7 or 9 to execute servos[servonum]->write(position);

Same with the other. If any of case is 0, 1, 2, ,3 4, 5, 8, 10, 11 then execute ```
servos[servonum]->write(180 - position);

So it is like a logic OR.

[quote="MianQi, post:1, topic:862904"]
is here anyone know why the servonum in switch was not symmetrical?
[/quote]

No idea.

My question is:
IMG_20210518_084921-1

These are the 6 arms of the robot, there are 12 servos used. The servos numbered 0-11, 0-5
(cross) are for the elbows and 6-11(square) for claws. So, why in setServo(), it were 6,8,9 contrast to 0,1,2,3,4,5,7,10,11, not anyone of these patterns:
6,8,4 - 5,7,9
6,7,8 - 9,10,11
6,8,10,5,7,9 - 0,1,2,3,4,11
......

My guess is that those three servos (6, 7, and 9) have their shaft pointing in the opposite direction from the other nine. Can you see the servo shafts?

I searched on the net and found some clues:

  1. the sum of deference positions if it have are always 180 degree.
  2. when the robot start to move, there are always some legs pull backward and others push backward.
  3. there are gaits settings of phrases:
    phrase 0: 6-7-9
    phrase 1: 7-8-11
    phrase 2: 9-10-6
    phrase 3: 10-11-8

not:
11-7-9
6-10-8
or other even distributing pattern.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.