Announcement

Collapse
No announcement yet.

Motor Problems with Gyro Sensor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Motor Problems with Gyro Sensor

    We are implementing a gyro sensor into our autonomous routine. Currently, I am trying to get the basic function for the gyro to work.

    The code seems to run fine with all of the gyro logic working as expected. The problem comes with the motors when implementing the code into the robot. Our drivetrain is a tread ripsaw design which is powered by 4 motors, 4 motors over 2 MR motor controllers.

    When I run the program, the right side runs against each other and the left side runs in the opposite of the programmed direction. Both of the right motors must run in parallel for the drivetrain to move, and when testing the gyro program, the 2 right motors run in the opposite direction. The other interesting part is at the moment when I start the program, the right motors go in the same direction for about .5 seconds, then they start going against each other. About 30 seconds later, one motor changes direction again (I didn't tell it to) which means both of the right motors are now going in the same direction.

    A side note, the gyro is working really well. When I rotate the gyro to the desired turn heading, the motors stop as expected. I do not believe there are any problems with the gyro except our turns are limited to 180* (I'll work on fixing this problem if we make it past State and the motors start working).
    Second side note, the motors work as expected in direction and setting the correct power in an Autonomous Encoder program and in TeleOp.

    Here is the high level view of our code. Most of the gyro commands are located inside of the "GyroHeadingDifference();" command which is working.

    I have tried putting the motor power commands right outside of the loop as currently shown, inside the while loop, and adding a waitOneFullHardwareCycle command after setting each power.
    Code:
            motorLeft1.setPower(.5);
            //waitOneFullHardwareCycle();
            motorLeft2.setPower(.5);
            //waitOneFullHardwareCycle();
            motorRight1.setPower(-.5);
            //waitOneFullHardwareCycle();
            motorRight2.setPower(-.5);
            //waitOneFullHardwareCycle();
    
            while(abs(headingDifference)<abs(headingTarget))
            {
                headingCurrent = sensorGyro.getHeading();
    
                GyroHeadingDifference();
    
                telemetry.addData("Previous:", String.valueOf(headingPrevious));
                telemetry.addData("Current:", String.valueOf(headingCurrent));
                telemetry.addData("Target:", String.valueOf(headingTarget));
                telemetry.addData("Difference:", String.valueOf(headingDifference));
                telemetry.addData("Motor Power Left:" + motorLeft1.getPower(), motorLeft2.getPower());
                telemetry.addData("Motor Power Right:" + motorRight1.getPower(), motorRight2.getPower());
            }
    
            motorLeft1.setPower(0);
            motorLeft2.setPower(0);
            motorRight1.setPower(0);
            motorRight2.setPower(0);
    Does anyone know why our motors are behaving this way with the gyro sensor and how to fix it?
    FTC 7104 - The Synergists

  • #2
    Originally posted by FTC7104 View Post
    The other interesting part is at the moment when I start the program, the right motors go in the same direction for about .5 seconds, then they start going against each other. About 30 seconds later, one motor changes direction again (I didn't tell it to) which means both of the right motors are now going in the same direction.
    The code you posted never shows motor pairs getting different values. Both right motors are either set to -0.5 or 0.0. I assume you have some .setPower calls within GyroHeadingDifference(). Can you post that code?

    Comment


    • #3
      Sure, here is the code for GyroHeadingDifference(); It is only dealing with the gyro however so it should not be interfering with the motors.
      Code:
      //GYRO
          public void GyroHeadingDifference()
          {
              if(abs(headingPrevious-headingCurrent) > headingTarget) //If the difference is greater than the target
              {
                  headingDifference = abs(abs(headingPrevious-headingCurrent)-360); //Then the difference can be corrected by -360
              }
              else
              {
                  headingDifference = abs(headingPrevious-headingCurrent); //Otherwise, difference is in a good zone
              }
              if(abs(headingTarget) > 180)
              {
                  telemetry.addData("|Target Heading| > 180* !!!!!!!!!", 1); //If Target is over limit....then CAUTION!!!
              }
          }
      FTC 7104 - The Synergists

      Comment


      • #4
        There must be some other motor setting code somewhere to cause the behavior you're describing. Your gyro loop appears to have the robot simply spin in place until it's pointed in the proper direction since there are no other motor calls inside the loop or in GyroHeadingDistance.

        When you initialize your motors do you ever call setDirection? Do you call setDirection in your TeleOp program? If you don't explicitly use setDirection every time if can remember the values from the previous OpMode.

        Comment


        • #5
          Oh...that may be messing it up.

          Currently, these are the commands involved with the motor definitions:
          Code:
              DcMotor motorLeft1;
              DcMotor motorLeft2;
          
              DcMotor motorRight1;
              DcMotor motorRight2;
          ...
              motorLeft1 = hardwareMap.dcMotor.get("motorLeft1");
              motorLeft2 = hardwareMap.dcMotor.get("motorLeft2");
          
              motorRight1 = hardwareMap.dcMotor.get("motorRight1");
              motorRight2 = hardwareMap.dcMotor.get("motorRight2");
          ...
              motorRight1.setDirection(DcMotor.Direction.REVERSE);
              motorRight2.setDirection(DcMotor.Direction.REVERSE);
          Would we need to define this for the left motors?
          Code:
          motorLeft1.setDirection(DcMotor.Direction.FORWARD);
          motorLeft2.setDirection(DcMotor.Direction.FORWARD);
          FTC 7104 - The Synergists

          Comment


          • #6
            Yes, I personally think it's safer to always set the motor direction. This is critical if your autonomous and teleop OpModes use the motors differently. The best solution is to extend all OpModes from a common base class so that the naming and direction is consistent across all OpModes.

            I still don't see any code that would cause both right motors to run in opposite directions.

            Comment


            • #7
              Try commenting out all of the "motor.getSpeed()". I doubt it, but perhaps there is a bug in the SDK that causes this function to have unexpected and undesired effects.

              Comment


              • #8
                Sorry I meant "motor.getPower()"

                Comment


                • #9
                  I'll try that tomorrow when I have access to the robot. Thanks for the suggestions thus far!
                  FTC 7104 - The Synergists

                  Comment


                  • #10
                    Update on this thread, we fixed the problem by reversing our encoder wires. For some reason, it appears that there was cross talk between encoders and motors so switching the encoder wires fixed the issue.
                    FTC 7104 - The Synergists

                    Comment


                    • #11
                      We're having a hard time with gyro sensors as well, and we're trying to troubleshoot. Could you please clarify what you mean by "reversing" so that we can try it?

                      Comment


                      • #12
                        Originally posted by macntosh47 View Post
                        We're having a hard time with gyro sensors as well, and we're trying to troubleshoot. Could you please clarify what you mean by "reversing" so that we can try it?
                        Cross-talk occurs when a changing magnetic field traverses a loop. Twist signals and their returns into twisted pairs.

                        If something needs to be reversed then it is likely a genuine wiring issue.
                        FTC6460 mentor (software+computer vision+electronics), FPGA enthusiast. In favor of allowing custom electronics on FTC bots.
                        Co-founder of ##ftc live chat for FTC programming--currently you may need to join and wait some time for help--volunteer basis only.

                        Comment

                        Working...
                        X