Added checks for negative discriminants #1420
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request adds checks for negative discriminants before calculating square roots in the longitudinal speed planning logic to prevent invalid operations that could occur when the discriminant is negative.
Abstract
This pull request introduces validation for negative discriminants in the LongitudinalSpeedPlanner to prevent invalid square root calculations during acceleration and deceleration constraint planning.
Background
In the current implementation, the code attempts to compute the square root of a discriminant that can occasionally be negative. This can lead to exceptions and undefined behavior. Adding checks before these calculations ensures stability and prevents such issues.
Details
The changes involve checking if the discriminant is negative before performing a square root operation in both the acceleration and deceleration branches. If the discriminant is negative, a semantic error is thrown to handle the situation appropriately. This fix addresses the problem where the target speed may be too high or too low relative to the acceleration or deceleration rate, leading to negative values in the discriminant.
References
N/A
Destructive Changes
N/A
Known Limitations
N/A