Without seeing the rest of your code or knowing specifically what isn’t working, I can’t say for certain.
Having said that, there are VERY few valid reasons to use loops in FRC code (don’t at me, I know they exist), especially while loops. They often lead to loop overrun errors due to taking longer than 0.02ms to complete, which is the cycle time (50Hz) for the main TimedRobot loop in which all of your code runs.
Firstly, follow @Fletch1373’s advice regarding loops. Something of note is that the Falcon encoder is 2048 counts per revolution which means that if one rotation of the motor happens, the encoder will show 2048 as the position.
@RoboticsGuy1 I think there is a fundamental misunderstanding about how the FRC development framework functions.
What you are currently using is a raw TimedRobot class. In this class the ~Init() methods will run once at the beginning of the different parts of a match. The ~Periodic() methods will execute “periodically” I think about every 20ms and any logic you do in those methods should try to limit the amount time you spend in your own code. In your case you could think of the teleopPeriodic() method as your loop.
This means you should be able to replace your while statements with if statements and you might be able to do something like what you are looking for.
With this said, I would make several suggestions.
All CTRE motor controllers (including Falcons) include AWESOME logic to do much of what you are trying to do automatically. What I would investigate is using something called Motion Magic. It takes a bi to setup, but once you have it setup you just tell the motor what position you want to move to and it will do it all for you. For Information you want to check out CTRE’s documentation Motor Controller Closed Loop — Phoenix documentation . I know it probably seems like a lot, but it really isn’t too bad once you get the hang of it.
Appears there is a lot of great things with the Motion Magic and Closed loop motor controllers. Read the documentation and there is a significant learning curve on this topic.
Our team is using the Command-Based Programming and using code in the isFinished method to check sensor positions to determine when to end motion. One of the issues still working out is using the Forward or Reverse PIN on Falcon 500 to reset the sensor when the mechanism is as a certain location.
This may be true, but I honestly feel it is one of the biggest things someone can do to improve the performance of their robot. Finding ways to offload this type of logic is huge in my opinion. Maybe it isn’t something to figure out int he middle of a season though
Have you looked into it? What did you find the most confusing?
I think the only way to do this on the Falcon is to use a forward or reverse limit switch and run the following: falcon.configClearPositionOnLimitR(true, timeoutMs);
I don’t think the Falcon supports the clear position on QuadIdx option like the TalonSRX.
What type of motion are you trying to do with what type of mechanism?