acmerobotics / road-runner

Wheeled mobile robot motion planning library designed for FTC
MIT License
224 stars 77 forks source link

May throw exception in Profiles.kt #103

Closed EthanHu29 closed 4 months ago

EthanHu29 commented 4 months ago

core/Profiles.kt

89 val rawIndex = this.disps.binarySearch(x) 90 val beginIndex = if (rawIndex >= 0) { 91 rawIndex 92 } else { ... 98 for (index in beginIndex..disps.lastIndex) { val v = vels.last() 100 val a = minAccels[index - 1]

        val targetDisp = newDisps.last() + (targetVel * targetVel - v * v) / (2 * a)
        if (x + targetDisp > disps[index]) {
            newDisps.add(disps[index] - x)
 105         vels.add(sqrt(v * v + 2 * a * (this.disps[index] - this.disps[index - 1])))

...

Here I list lines may throw exception. In line 89, rawIndex could be 0, when x == this.disps[0], then beginInedex = 0. In this scenario line 100 and 105 could throw exception, when index =0, 100: minAccels[index - 1] becomes minAccels[- 1] 105: this.disps[index - 1] becomes this.disps[- 1],

Any suggestion on this issue?