Repository navigation
Add CV and CTRV motion prediction of other vehicles - #475
Open
leninworld wants to merge 1 commit into
Open
leninworld wants to merge 1 commit into
leninworld wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes issue #432.
Summary
Adds physics-based motion prediction of other vehicles for Chapter 11 with two models, constant velocity (CV) and constant turn rate and velocity (CTRV), and a simulation that compares them with where three moving obstacles really go.
src/components/prediction/motion_prediction.py:predict_cv(x_m, y_m, yaw_rad, speed_mps, horizon_s, step_s):x(t) = x + v cos(θ) t,y(t) = y + v sin(θ) t.predict_ctrv(x_m, y_m, yaw_rad, speed_mps, yaw_rate_rps, horizon_s, step_s):x(t) = x + (v/ω)(sin(θ + ωt) - sin θ),y(t) = y + (v/ω)(cos θ - cos(θ + ωt)). For|ω| < 1e-6rad/s it uses CV, because dividing by a very smallωloses precision. Positive yaw rate turns counter-clockwise.(N,)atstep_s, 2 step_s, ..., horizon_s(N = horizon_s / step_s; the current position at t = 0 is not included). A non-finite or non-positive time, or a horizon that isn't a whole multiple of the step, raisesValueError. The docstrings note that prediction uncertainty (the track covariance) is out of scope.src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.py: threeObstacles at 3 m/s in separate parts of the plot, using their true states (obstacle.state,obstacle.yaw_rate_rps), so it doesn't depend on the tracker of Multi-object tracking with a Kalman filter and nearest neighbor data association #379:yaw_rate_rpsto 0. The stop is decided from the heading, not from a time counter, so it happens at the same place in the animation and in the error calculation.--save-gif; the GIF is committed next to the script. Running the script prints the error table below.test/test_motion_prediction.py: CV worked out by hand; CTRV with ω = 0 equals CV; CTRV with ω ≠ 0 stays on the circle of radiusv/ωaround its centre; a tiny ω matches CV; output shape and times (30 steps of 0.1 s end at 3.0 s; 0.1 + 0.2 against 0.3 gives one step); theValueErrorcases (zero/negative, non-multiple, inf/NaN).test/test_cv_ctrv_motion_prediction.py: runsmain()withshow_plot = Falseand checks the error comparison below.doc/object_tracking/index.md: a## Sectionslist with "11.1 CV vs CTRV motion prediction" (doc/WRITING_GUIDE.md names comparison sections "A vs B"). Please change the number if you want it elsewhere.pyrightconfig.json/.devcontainer/devcontainer.jsonregenerated withgenerate_pyrightconfig.py.Closes #432
Comparing CV and CTRV
Predictions made at t0 = 3.5 s from each obstacle's true state, compared with its true position 1, 2 and 3 s later (0.1 s steps):
CV and CTRV are the same on the straight road; CTRV wins in the constant turn; for the obstacle that stops turning at 4.0 s, CTRV is better at 1 s but keeps turning afterwards and overshoots, so CV wins at 2 and 3 s. The small CTRV error in the constant turn comes from the simulation's vehicle model (
Statekeeps the heading constant during each 0.1 s step), not from the prediction.How I checked it works
pytest -q test/test_motion_prediction.py test/test_cv_ctrv_motion_prediction.py test/test_book_chapters.py test/test_generate_example_gallery.py: 24 passed (Python 3.12). The two new test files fail onmain(module not found).pytest -q: 315 passed.--save-gifand looked at the frames at 3.5 s, 4.2 s and 8.0 s: the three obstacles and their predictions stay apart and inside the plot, and CTRV follows the constant turn. At 3.5 s the third obstacle's CTRV prediction still curves left, although the obstacle goes straight from 4.0 s on; from 4.2 s its yaw rate is 0 and both predictions lie on its straight path.doc/EXAMPLES.mdis unchanged (the gallery workflow regenerates it after merge).Images
The GIF is also in
src/simulations/perception/cv_ctrv_motion_prediction/, so the gallery picks it up.Book