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

Following a fixed distance along a curve #204

Open
jschiefele opened this issue Dec 11, 2023 · 3 comments
Open

Following a fixed distance along a curve #204

jschiefele opened this issue Dec 11, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@jschiefele
Copy link

Versions: Scenic 2.1.0, Python 3.11

Hi.

My goal is to model a scenario where the ego vehicle follows a curved track, and there is an obstacle on this track. I want to be able to specify the distance between ego and obstacle, not as the crow flies, but measured along the track (like a braking distance on a curved road).

I am using the following specifier to obtain this, like in the minimal example below, but do not get the intended results:

from scenic import scenarioFromString

scenario_str = """
track = PolylineRegion([(0., -6.), (0. ,0.), (4., 3.)])
ego = Object at (0. @ -5.)
obstacle = Object following track.orientation from ego.position for 10.
"""
scenario = scenarioFromString(scenario_str)
scene, _ = scenario.generate()
print([obj.position for obj in scene.objects])
# Result:   [(0.0 @ -5.0), (1.9999999999999998 @ 4.0)]
# Expected: [(0.0 @ -5.0), (4.0 @ 3.0)]

The obstacle was not placed on the track, and the ego-obstacle-distance is not 10. Am I misunderstanding something here?
Or is there any other syntax to specify a distance along a curve?

@Eric-Vin
Copy link
Collaborator

Eric-Vin commented Mar 25, 2024

For your first question, the inaccuracy is due to the forward Euler approximation being done internally. You might be able to get better results with a smaller step size (see the note here), but with this method there will always be some noise.

As to your second question, to my knowledge there's no direct way to calculate that distance in Scenic right now, though this has come up in the past and it's something we'd like to add/review a PR adding.

@Eric-Vin Eric-Vin added the enhancement New feature or request label Mar 25, 2024
@jschiefele
Copy link
Author

Thanks @Eric-Vin. Thinking about your hint with the Euler approximation, I guess the VectorField which defines the orientation of a PolylineRegion is simply not intended to support my specific use-case:

  • I aim to move a railroad vehicle along a 1-dimensional track. It cannot go off sideways, just forwards and backwards. In the plot, I use track = PolylineRegion([(0., -1., 0.),(0., 0., 0.), (2. , 2., 0.)]).

  • The orientation of the PolylineRegion has field lines parallel to the line segments. This does supports my idea of following as long as there are no corners. (As in the blue trajectory_1.)

  • Where the straight segments form corners, the step procedure in VectorField.followFrom will overshoot the corner at some place or the other. From there on, it will step along parallel to the track instead of correcting the overshooting. (As in the orange trajectory_0.)

follow_PolylineRegion

My plan now is to modify one of the Regions implemented in Scenic 3 (PathRegion?) by defining something like a 1D VectorField to serve as the track's orientation. Its followFrom() should stay strictly on the linear segments, somehow wrapping the incremental step around to the next linear segment when a corner is reached.

Please let me know if you think this is a reasonable idea (and if this might be of general interest as a PR).

@Eric-Vin
Copy link
Collaborator

Eric-Vin commented Jun 5, 2024

Apologies for the late response, just saw that this comment was posted! This seems like a reasonable idea to me overall, and the idea for the default vector field for PathRegion seems similar to the one for PolylineRegion.

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

No branches or pull requests

2 participants