Monday, December 25, 2017

Update on Mecanum Wheels - straight, turn,and slew

Here's the latest version of the "crab" method.   Right now I'm thinking that if this works, we should use it for autonomous too.  Except, since there aren't any gamepad controllers in the autonomous mode, the first thing to do there will be to translate the desired angles and speeds into their corresponding x & y vectors (3 total) and pass that on to this method.  That.just.might.work.

Of course there will be some interesting relationships to figure out for autonomous, but this maybe gets us started.

FWIW, I ran this on a laptop (using Netbeans IDE) after writing it.  Pulled a couple bugs out of it in the process.  Probably there are a couple others, but we're closer than we were.  

public static botMotors crab(Gamepad cx)
{
   botMotors m = new botMotors();      

   float maxDrive;
   float tempMax;
   //   Sum the vectors and hope for the best :-)
   /        turn=left.x,      fwd=left.y,      crab=right.x
   m.leftFront  =  cx.left_stick_x + cx.left_stick_y + cx.right_stick_x;
   m.rightFront = -cx.left_stick_x + cx.left_stick_y - cx.right_stick_x;
   m.leftRear   =  cx.left_stick_x + cx.left_stick_y - cx.right_stick_x;
   m.rightRear  = -cx.left_stick_x + cx.left_stick_y + cx.right_stick_x;

 keep things proportional when the sum of any x or y > 1
   tempMax =  Math.max(Math.abs(m.leftFront),      Math.abs(m.rightFront));
  maxDrive = Math.max(Math.abs(m.leftRear), Math.abs(m.rightRear));
   maxDrive = Math.max(tempMax, maxDrive);
   maxDrive = (maxDrive > MOTORMAX) ? maxDrive : MOTORMAX;

        // scale and clip the front motors, then the aft

   m.leftFront = m.leftFront/maxDrive;
   m.leftFront = Range.clip(m.leftFront, MOTORMIN, MOTORMAX);
   m.rightFront = m.rightFront/maxDrive;
   m.rightFront = Range.clip(m.rightFront, MOTORMIN, MOTORMAX);

   m.leftRear = m.leftRear/maxDrive;

   m.leftRear = Range.clip(m.leftRear, MOTORMIN, MOTORMAX);
   m.rightRear = m.rightRear/maxDrive;
   m.rightRear = Range.clip(m.rightRear, MOTORMIN, MOTORMAX);
       
   return m;

}
This is what it looks like when you cycle all three inputs



Play with graphs and it can look like this ... which is meaningless but kind of cool to look at:

No comments:

Post a Comment

Java Is as Java Does

We would not seek a battle, as we are; Nor, as we are, we say we will not shun it. Henry to Montjoy,   Henry V ,  Shakespeare Last season I ...