View Single Post
  #1   Spotlight this post!  
Unread 13-02-2015, 10:54
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: How to Code Gyro to Help with Straight Strafing?

Thanks for the heads up about strafing with unbalanced weight. This is our first year with mecanum. The team took our practice chassis (a wide bot) from last year and mounted 4 mecanum on it for the programmers to play with while the actual robot (a long-bot) was under construction. The practice chasis behaved very nicely, but last night we put ~80lbs over the front two wheels. Strafing was very problematic and the robot wanted to rotate.

We added some very simple code to the DriveWithJoystick code and it was able to work much better-- this is just me retyping it from memory, but it was something along the lines of:

Code:
public class DriveWithJoystick extends Command {
    ...
    double m_lastAngle;
    boolean m_trackAngle;

    ...
    public void initialize() {
        m_trackAngle=false;
    }

    public void execute() {
         // get joystick readings x, y, rotation, and gyroAngle
         ...
         if(rotation==0)
         {
             //User does not want rotation, If this just happened, note current angle 
             if (!m_trackAngle)
             {
                 m_trackAngle=true;
                 m_lastAngle=gyroAngle;
             }

             //by here we are sure m_trackAngle is true and m_lastAngle
             //is our target angle, either just set above or on some previous
             //pass.

             // programatically inject rotation if
             // there is error.  Use P part of PID only
             double errVal=m_lastAngle-gyroAngle;
             double P=0.02;
 
             rotation= P * errVal;  //proportional rotation injected to counter error
         } else {
              //User is applying rotation, stop tracking angle
              m_trackAngle=false;
         }

         Robot.driveTrain.mecanumDrive(x,y,rotation,gyroAngle);
   }
   ..
}
As we strafed with 80lbs over the front wheels, it would tend to rotate due to the weight imbalance. With P==0.02, around 10 degrees, we begin applying a 0.2 power to compensate. At 20 degrees we're applying 0.4 power.

During normal balance the strafing maintained an angle of at most ~2 degrees from ideal, so the injected rotation will be around 0.04 which probably has some, but very little effect.

We did not yet try to tune the P, but it worked pretty good with the initial guess. I suspect a larger P would improve performance slightly-- it was a bit sluggish maintaining the angle. But it seems if we have a stack of 4 totes and a container out front (~40lbs) in addition to our ~30 lb fork, we will likely find ourselves in this situation and at least the practice chassis felt manageable with the cod modification. It all depends on how well the build team can pull the center of gravity toward the center of the robot.
Reply With Quote