Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Can I use gyro to drive straight in teleop period? (http://www.chiefdelphi.com/forums/showthread.php?t=155151)

versole 12-02-2017 00:27

Can I use gyro to drive straight in teleop period?
 
I wanted to know if you can drive straight using the gyro sensor because we don't have encoder to correct the speed of each motor. We're using tankdrive and right now the problem we're facing is that it's not going in the direction we wanted. For instance, if we move left and right stick to up direction the robot doesn't go straight, and for some reason, I think the speed of left side of the robot is going faster then the right side.

Also, I wanted to know if we can use it in autonomous mode. Like I need help with turning the robot with gyro (corresponding the wheel with the gyro angle.)

This is our first year so we're rookie, and their no programming mentor to mentor us.

mikets 12-02-2017 02:01

Re: Can I use gyro to drive straight in teleop period?
 
It would be very helpful with encoders but it is possible to do it without. Consider the differential of the two tank sticks is directly proportional to the turning rate of the robot. The bigger the difference, the faster the robot should turn. And the turning rate of the robot is the raw output of the gyro (rotational velocity). So in theory, you can do this:
Code:

double drivePower = (leftStick + rightStick)/2.0;
double stickDifferential = leftStick - rightStick;
double motorDifferential = Kp*(stickDifferential - gyro.getScaledRotationRate());
leftMotor.set(drivePower + motorDifferential);
rightMotor.set(drivePower - motorDifferential);

Note: this is pseudocode, not real code. It is intending to demonstrate the concept. If stickDifferential is zero, that means you want to go straight. If the gyro rotation rate is zero, that means your robot is going straight. Then motorDifferential is zero. If stickDifferential is zero but the robot is turning left, then gyro rotation rate is negative, then motorDifferential will be a positive number. Then the left motor will get more power than the right thus correcting the left drift. Does that make sense?

soundfx 12-02-2017 02:06

Re: Can I use gyro to drive straight in teleop period?
 
Quote:

Originally Posted by versole (Post 1643611)
I wanted to know if you can drive straight using the gyro sensor because we don't have encoder to correct the speed of each motor. We're using tankdrive and right now the problem we're facing is that it's not going in the direction we wanted. For instance, if we move left and right stick to up direction the robot doesn't go straight, and for some reason, I think the speed of left side of the robot is going faster then the right side.

Also, I wanted to know if we can use it in autonomous mode. Like I need help with turning the robot with gyro (corresponding the wheel with the gyro angle.)

This is our first year so we're rookie, and their no programming mentor to mentor us.

Our team reuses this class as a basic implementation of a pi controller attempting to keep rotation to a minimum. We only usually only use it for holonomic drive trains, but it could easily be used for a tank drive. We only use a pi controller here, but you could easily modify this for a more accurate pid controller, or use the wpilib class.

EDIT:
I didn't internalize that you were using tank drive. You could still try to use this, but it might be a little harder to adapt. I suppose if you run this method only when both joystick values are within some value of each other, it might work.

AustinSchuh 12-02-2017 03:03

Re: Can I use gyro to drive straight in teleop period?
 
Quote:

Originally Posted by soundfx (Post 1643622)
Our team reuses this class as a basic implementation of a pi controller attempting to keep rotation to a minimum. We only usually only use it for holonomic drive trains, but it could easily be used for a tank drive. We only use a pi controller here, but you could easily modify this for a more accurate pid controller, or use the wpilib class.

I'd suggest here a reasonably stiff P controller. That'll get the OP most of the gain for fewer corner cases. We use essentially P gyro compensation.

mikets 12-02-2017 03:42

Re: Can I use gyro to drive straight in teleop period?
 
Here is the code from our FTC library.
Code:

    /**
    * This method implements tank drive where leftPower controls the left motors and right power controls the right
    * motors.
    *
    * @param leftPower specifies left power value.
    * @param rightPower specifies right power value.
    * @param inverted specifies true to invert control (i.e. robot front becomes robot back).
    */
    public void tankDrive(double leftPower, double rightPower, boolean inverted)
    {
        leftPower = TrcUtil.clipRange(leftPower);
        rightPower = TrcUtil.clipRange(rightPower);

        if (inverted)
        {
            double swap = leftPower;
            leftPower = -rightPower;
            rightPower = -swap;
        }

        if (gyro != null)
        {
            //
            // Gyro assist is enabled.
            //
            double drivePower = (leftPower + rightPower)/2.0;
            double diffPower = (leftPower - rightPower)/2.0;
            double turnPower = gyroAssistKp*(diffPower - gyroRateScale*gyro.getZRotationRate().value);
            leftPower = drivePower + turnPower;
            rightPower = drivePower - turnPower;
            double maxMag = Math.max(Math.abs(leftPower), Math.abs(rightPower));
            if (maxMag > 1.0)
            {
                leftPower /= maxMag;
                rightPower /= maxMag;
            }
        }

        if (frontLeftMotor != null)
        {
            frontLeftMotor.setPower(leftPower);
        }

        if (frontRightMotor != null)
        {
            frontRightMotor.setPower(rightPower);
        }

        if (rearLeftMotor != null)
        {
            rearLeftMotor.setPower(leftPower);
        }

        if (rearRightMotor != null)
        {
            rearRightMotor.setPower(rightPower);
        }
    }  //tankDrive


GeeTwo 12-02-2017 05:53

Re: Can I use gyro to drive straight in teleop period?
 
Quote:

Originally Posted by versole (Post 1643611)
...For instance, if we move left and right stick to up direction the robot doesn't go straight, and for some reason, I think the speed of left side of the robot is going faster then the right side...

I would look at this problem first. If your robot is pulling badly enough that the driver is having trouble going straight, something is amiss. Check out this recent thread for things to try.


All times are GMT -5. The time now is 06:33.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi