Coder Social home page Coder Social logo

Comments (3)

gearsincorg avatar gearsincorg commented on June 20, 2024

It's very possible that your encoders are not connected correctly. And therefore not generating pulses to be counted. The code sample shows reading two sets of numbers from the motor controller hardware registers. This looks perfectly OK.

You say that "I know that PID is working because the motor ramps up it's power after moving."

But this in not conclusive. If you are requesting a constant slow speed, and the encoders are not connected properly, then the motor controller will start with low power, and then continue to ramp up the power in an attempt to generate encoder counts. Eventually it will max out the power. To me, this an indication of a disconnected encoder.

Please verify that the encoder is plugged into the correct motor channel (1 or 2) and that the encoder cable has been plugged in the correct way around (yellow wire near the outside edge of the motor controller).

I true indication that the encoders are being read correctly is that you can run the motors slow for several seconds and run them fast for several seconds.

from ftc_app.

FTC6499 avatar FTC6499 commented on June 20, 2024

I just verified that it is not a hardware issue. Instead it is a software bug (either on my part or in compiled FTC provided code).

It seems to be a combination of two problems

  • Not reseting the encoders
  • Not waiting for pending writes before switching to READ_ONLY mode.

The reason I know that this is a software bug is because I wrote a test program in which I can see getCurrentPosition() correctly updating by adding a delay before switching to READ_ONLY mode. I verified that it works
The initalization is the same except I start with RESET_ENCODERS and later switch to RUN_TO_POSITION. I added a global variable called loopcnt which is of type int.
Here is my code for loop.

            if(loopcnt==24) {
                arm[0].setMode(DcMotorController.RunMode.RUN_TO_POSITION  );
            }else if(loopcnt==64) {
                telemetry.addData("Arm", "Set");
                arm[0].setTargetPosition(128);
                arm[0].setPower(.25);
            }else if(loopcnt==128){
                armzeroctl.setMotorControllerDeviceMode(DcMotorController.DeviceMode.READ_ONLY);
            }else if(loopcnt>128&&(armzeroctl.getMotorControllerDeviceMode()==DcMotorController.DeviceMode.READ_ONLY)){
                telemetry.addData("Arm", String.format("Position: %d Target: %d busy: %b", arm[0].getCurrentPosition(),arm[0].getTargetPosition(),arm[0].isBusy()));

            }
            if(loopcnt<Integer.MAX_VALUE)
                ++loopcnt;

If I use a very small delay the motor will not move at all because the writes were never done to the controller telling it to move the motor. The issue is most likely because any pending writes are not completed during SWITCHING_TO_READ_MODE..

If this is a feature and not a bug how do I wait for writes to be completed before switching to READ_ONLY mode? Could someone add a function such as pendingRW() which returns true if there are any pending reads or writes. Using a hardcoded value is not a good idea for a delay.

Are any pending writes supposed to be flushed while in SWITCHING_TO_READ_MODE? If so then this is a software bug in the FTC Application.

Leaving the encoder in WRITE_ONLY mode allows for correct behavior of the rotary encoder. Because of this new information I have changed the title of the issue.

from ftc_app.

cmacfarl avatar cmacfarl commented on June 20, 2024

All reads and writes to motor controllers are synchronous with this season's SDK. For this reason I believe your problem here is solved. If you are still having trouble please post a question over on the forums.

from ftc_app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.