Reverse operation

45 views
Skip to first unread message

René van den Broek

unread,
Nov 30, 2023, 12:53:56 PM11/30/23
to Vorpal Robotics Forum
First of all: what a great project!! Thanks.
I build the hexapod and the gamepad to control it for my grandson Sverre. All works fine now. I also installed the Gripper successfully.
My question is can I install the distance control at the same time? 
It does not fit at the same time on the same bolts where the gripper is mounted and It would probably not work because the gripper would be in the 25 cm range of the distance control.

So my idea is to mount the distance control at the "back" with velcro.
But then it would only work when the hexapod walks backwards. 
That is why I also want the controls on the gamepad work reverse as standard.
I could mount the servos on the hexapod in a different order but I do prefer to change the code a bit.

Question if I change the code of the gamepad in the section DpadSlyle like :

'b' switch 'f´
and
'r´ switch 'l´

Would that work?
Best regards René


switch (DpadStyle) {
case ALTDPADSTYLE:
if (b < 20) {
return 'b'; // backward (bottom button)
} else if (b < 60) {
return 'l'; // left
} else if (b < 130) {
return 'r'; // right
} else if (b < 250) {
return 'f'; // forward (top of diamond)
} else if (b < 800) {
return 'w'; // weapon (very top button) In the documentation this button is called "Special"
// but a long time ago we called it "weapon" because it was used in some other
// robot projects that were fighting robots. The code still uses "w" since "s" means stop.
} else {
return 's'; // stop (no button is pressed)
}
break;

case STDDPADSTYLE:
default:
if (b < 100) {
return 'b'; // backward (bottom button)
} else if (b < 200) {
return 'l'; // left
} else if (b < 400) {
return 'r'; // right
} else if (b < 600) {
return 'f'; // forward (top of diamond)
} else if (b < 850) {
return 'w'; // weapon (very top button) In the documentation this button is called "Special"
// but a long time ago we called it "weapon" because it was used in some other
// robot projects that were fighting robots. The code still uses "w" since "s" means stop.
} else {
return 's'; // stop (no button is pressed)
}
} // end of switch DpadStyle

vorpalrobotics

unread,
Dec 1, 2023, 10:39:09 AM12/1/23
to Vorpal Robotics Forum
Hello,

Thank you for the kind words! This project represents thousands of hours of work (between the 3d design, electrical system, research, programming, documentation, packaging, etc.) but it was fun every step of the way! (Other than some supplier headaches from time to time lol).

Yes, just looking at your code I don't see any glaring issues. This would simply reverse the sense of "forward". However, just thinking about it for a moment, I think Left and Right turns would remain the same. Visualize in your heard a normal "forward" gait from the top view. Turning right would cause the robot to spin clockwise. Now visualize the same thing but robot's forward is really reverse. Isn't "right" still clockwise?

I think the code would be something more like this (although I have not tried compiling this or testing it):

#define REVERSEROBOT 1

char forwardchar = 'f';
char backwardchar = 'b';

if (REVERSEROBOT) {
   forwardchar = 'b';
   backwardchar = 'f';
}

switch (DpadStyle) {
  case ALTDPADSTYLE:
    if (b < 20) {
       return backwardchar;  // backward (bottom button)
    } else if (b < 60) {
       return left;  // left
    } else if (b < 130) {
      return right;   // right
    } else if (b < 250) {
      return forwardchar;  // forward (top of diamond)
    } else if (b < 800) {
      return 'w';  // weapon (very top button) In the documentation this button is called "Special"
                   // but a long time ago we called it "weapon" because it was used in some other
                   // robot projects that were fighting robots. The code still uses "w" since "s" means stop.
    } else {
      return 's';  // stop (no button is pressed)
    }
    break;

  case STDDPADSTYLE:
  default:
    if (b < 100) {
       return backwardchar;  // backward (bottom button)
    } else if (b < 200) {
       return 'l';  // left
    } else if (b < 400) {
      return 'r';   // right
    } else if (b < 600) {
      return forwardchar;  // forward (top of diamond)
    } else if (b < 850) {
      return 'w';  // weapon (very top button) In the documentation this button is called "Special"
                   // but a long time ago we called it "weapon" because it was used in some other
                   // robot projects that were fighting robots. The code still uses "w" since "s" means stop.
    } else {
      return 's';  // stop (no button is pressed)
    }
  } // end of switch DpadStyle
}


Now, another improvement I can think of is, instead of hard coding the gamepad to always reverse the robot, you
could detect a button press at boot time that implies the robot should be reversed. This code is near the start of
setup() in the gamepad code:
  // see if we're supposed to be in trim mode or card format mode or HC05 pad mode
  int mat = scanmatrix();
  if (mat == WALK_1) {
    Serial.println("#trim");
    TrimMode = 1;
  } else if (mat == REC_ERASE) {
    // Format the SD card
    Serial.println("#sdfmt");
    SDCardFormat();
    Serial.println("#sdfmt done");
  } else if (mat == DANCE_1) { // no padding of BT packets
    HC05_pad = 0;
    EEPROM.update(1, HC05_pad); // save for future boots
  } else if (mat == DANCE_2) { // pad BT packets
    HC05_pad = 1;
    EEPROM.update(1, HC05_pad); // save for future boots
  }

So we can see here that holding down W1 during gamepad boot puts us in trim mode, holding R4 while booting
formats the SD card, D1 and D2 were used to work around an issue with certain bluetooth modules (which no longer
happens, it was just one manufacturer for a few months who had this weird bluetooth issue that required packets
be padded out to 256 bytes.)

You could pick any button other than those, for example maybe W4, and if you boot the gamepad when W4 is held that
would mean to reverse the direction of "forward". The code would be something like this:


  // see if we're supposed to be in trim mode or card format mode or HC05 pad mode
  int mat = scanmatrix();
  if (mat == WALK_1) {
    Serial.println("#trim");
    TrimMode = 1;
  } else if (mat == REC_ERASE) {
    // Format the SD card
    Serial.println("#sdfmt");
    SDCardFormat();
    Serial.println("#sdfmt done");
  } else if (mat == DANCE_1) { // no padding of BT packets
    HC05_pad = 0;
    EEPROM.update(1, HC05_pad); // save for future boots
  } else if (mat == DANCE_2) { // pad BT packets
    HC05_pad = 1;
    EEPROM.update(1, HC05_pad); // save for future boots
  } else if (mat == WALK_4) { // reverse the robot's sense of "forward" direction
ReverseRobot = 1;
}

You would then declare near the top of the program a global like: byte ReverseRobot = 0; and you would change
the prior code by removing the #define REVERSEROBOT and instead just reference the variable ReverseRobot.

Again, I have not tested any of the above, so debugging may be necessary!

On a side note, the mode W4W4 (double tap on W4) actually "turns" by simply redefining what the front of the robot is.
Try it out! (A lot of people are unaware of the double-tap modes but there are some fun ones there.) It's not useful for
what you're trying to do, but the robot side of the code already has a mechanism to redefine the front of the robot
to be between any of the six hip servos. For your purposes, just redefining the buttons in the gamepad is a
cleaner and simpler solution.

Hope this helps,
-Steve P.

Reply all
Reply to author
Forward
0 new messages