I am trying to generate random numbers to simulate steering wheel angles and velocities of a car. So for steering wheels the random numbers could go like 1,2,4,6,4,3,40,0.
I can generate random numbers but the problem is it wouldnt make sense to have truly random numbers for steering angle data. So usually a driver only turns a few degrees unless there is a turn and somtimes he will not steer and the steering angle would be just zero. Can someone give me some advice regarding this?
4
As you’ve noted, random steering wheel angles don’t make sense.
Instead, try random or semi-random inputs to the steering wheel instead.
For example:
Assume the wheel is straight. You can randomly apply deltas (perhaps in the range of +/- 2 degrees) to the wheel position to simulate guiding the vehicle down a straight road.
You can introduce a bias to those deltas (say, +/- 2 degrees, plus another 0 – 5 degrees) to introduce a bend in the road.
You’ll want to keep track of the absolute position of the steering wheel, especially if you’re adding sharp corners (it’s not possible to turn the wheel +90 degrees 20 times in a row).
You could create a list of discrete steering behaviors where each one has a set of wheel angles that are executed in succession:
- Right Turn
- Sharp left turn
- straight with minor adjustments
- avoid pot hole or other obstacle
- veer off road (someone was texting and driving)
- change lane
Then you can randomly select through this list. Each item could be weighted to occur more often depending on the type of driving you’d like to simulate: off-road, highway, inner city, country road, etc.
2
You can map the values to a function that rises sharply at one end and then select from this.
I think this function might work well:
y = 1/(1.1 - x)
If x is your randomly produced number and y is the value you use for steering.
Most of the time your values will be fairly small, but occasionally the output of the function will rise to very high value giving you the peaks you want.
Tweaking values of this function will allow you to get different results such as higher peaks or less likely peaks.
1