-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Switching between READ_ONLY and WRITE_ONLY mode causes issues. #102
Comments
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. |
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
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 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. |
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. |
swap controls for mouth, grsbber, and rotator
It appears that the function
getCurrentPosition()
does not ever update inspite of the fact that motor moves and in spite of the fact that rotations are being recongized by the rotatry encoder. PID is working so the motor controller must be registering the rotations in some way. I know that PID is working because the motor ramps up it's power after moving.Here are the related global variables.
Some of these variables are initalized in
init()
as so. I based my code off of theK9TeleOp
class.In
loop()
I have the following codeUpon viewing the telmetry data I noticed that
getTargetPosition()
is always zero and most likely because of this the motor never stops. I used the Netbeans decompiler and I am baffled by this issue because of the following:This is from
HiTechnicNxtDcMotorController.class
and we can see thatgetMotorTargetPosition()
is using reading from the array which is calledb
. Values returned bygetMotorTargetPosition()
are correct. HowevergetMotorCurrentPosition()
always returns zero. At this point I do not know how to percede futher. What could be causing this issue?The text was updated successfully, but these errors were encountered: