Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit stack trace when RUN_TO_POSITION steps are done out of order #1345

Open
Iris-TheRainbow opened this issue Dec 2, 2024 · 12 comments
Open

Comments

@Iris-TheRainbow
Copy link

The Lynx firmware level positional PID provided by RUN_TO_POSITION is an easy way to achieve position control without a team rolling their own PID or using one from a library. However, it does have an issue that is very easy to run in to, even on accident.

Because the position control is run at the firmware level, it is possible to "confuse" a Lynx module until power is cycled by setting the run mode for a DcMotor to RUN_TO_POSITION before you set a target position with .setTargetPosition(). Currently, the SDK basically does no handling of this error, only showing an error on the Driver Station where telemetry is found. There is no stack trace available on the Driver Station or in the robot log.

This makes it very difficult for even experienced programmers to locate where something has gone wrong. With my understanding of the SDK, the class TargetPositionNotSetException should be able to throw a stack trace or add one to the robot log, which would make it easier to correct RUN_TO_POSITION errors.

Ideally, there could be a mechanism to catch the error before it causes a fatal error on the Lynx module, not necessitating the power cycle, though that is a much more complex fix.

@gearsincorg
Copy link

My suggested alternative to throwing an exception was to automatically set the target position equal to the current position (if none had been provided). This would ensured that the RTP mode is stable at the current location, causing no unexpected motion.

Unfortunately this wasn't deemed an acceptable solution.

@Iris-TheRainbow
Copy link
Author

I have considered this as well, but i 100% understand why it is not a great solution. I think crashing and throwing an exception here is entirely reasonable, since the code does really mess with the Lynx module when its actually sent, but a stack trace somewhere would be a massive help to troubleshooting it.

@AlecHub
Copy link

AlecHub commented Dec 3, 2024

Kids have a massive learning curve as it is. I think that kids would appreciate Phil's AI solution to the problem.

@cmacfarl cmacfarl changed the title Catch fatal crash when RUN_TO_POSITION steps are done out of order Emit stack trace when RUN_TO_POSITION steps are done out of order Dec 3, 2024
@cmacfarl
Copy link
Member

cmacfarl commented Dec 3, 2024

There is no one right answer.

What to do in this scenario was discussed and debated extensively among the FTC Technology Team back in the 2019 time frame. The rationale for adopting a fail fast POLA (principle of least astonishment) approach was that the described sequence of operations is a bug. As such, teaching the SDK to paper over the bug would lead to software appearing to work, but not actually doing what the user intended in the majority of cases. These sorts of bugs can lie latent for months and/or be incredibly difficult to track down and fix.

The decision was made to throw the exception in this case. This decision is not likely to be changed.

I think the thought on the DS messaging was that it would be pretty easy to search through an OpMode for any instances of setMode() to RUN_TO_POSITION so a stack trace wasn't necessarily needed, or was overlooked. However, the exception is caught, and the forced restart of the OpMode is by design. We want teams to catch this problem in their workshop, not at a competition venue. I do however think that it is not unreasonable to drop a stack trace into the log. I have taken the liberty of changing your Issue title to reflect this.

@Iris-TheRainbow
Copy link
Author

Iris-TheRainbow commented Dec 3, 2024

Yea that may be a better name.

My main gripe with how the error is handled is that it is not just an OpMode restart that is forced, but that the Lynx Module is stuck in an unrecoverable state and requires a full power cycle, which can make locating issue very frustrating, especially if there are multiple instances of that issue. I do still understand that it could be considered non-ideal to try and catch that issue (the SDK would need a method to cache the target permanently and any check that before issuing the mode change command, which sounds like a messy solution), though.

Myself and anyone else who helps new programmers would love to see even just a stack trace.

@AlecHub
Copy link

AlecHub commented Dec 3, 2024

Perhaps setMode() can be deprecated altogether. The RunMode is implied by:

  • setPower() - doesn't use encoder
  • setPowerEx() or setPowerEnc() - uses encoder
  • setVelocity() - uses encoder
  • setTargetPosition(int position, double power) - uses encoder
  • resetEncoder(boolean stopTheMotor):
    • resetEncoder(true) - stops the motor (if you're lucky) and resets the encoder
    • resetEncoder(false) - resets the encoder without stopping the motor

@Iris-TheRainbow
Copy link
Author

unfortunately, that doesn't work because the run modes are firmware level, not in the SDK itself.

@AlecHub
Copy link

AlecHub commented Dec 3, 2024

What I'm saying is the SDK can set or switch the run mode of the firmware automatically if that is what is required by the particular firmware or motor controller.

@Iris-TheRainbow
Copy link
Author

Iris-TheRainbow commented Dec 3, 2024 via email

@AlecHub
Copy link

AlecHub commented Dec 3, 2024

That would be a layer of hiding things the sdk shouldn’t be doing.

Sorry, does not compute.

@cmacfarl
Copy link
Member

cmacfarl commented Dec 3, 2024

Perhaps setMode() can be deprecated altogether. The RunMode is implied by:

Also discussed extensively by the tech team over the years.

@AlecHub
Copy link

AlecHub commented Dec 4, 2024

Perhaps setMode() can be deprecated altogether. The RunMode is implied by:

Also discussed extensively by the tech team over the years.

Good to know @cmacfarl. I do see and appreciate the merits of explicitly having to change the RunMode. Teams always have the option to create their own interface classes and methods to the SDK, to simplify and manage any difficulties they are having with managing the RunModes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants