grSim icon indicating copy to clipboard operation
grSim copied to clipboard

Possible division by zero on robot speed handling causing crashes

Open FelipeMartins96 opened this issue 3 years ago • 5 comments

https://github.com/RoboCup-SSL/grSim/blob/206c8dcb0b354325c1e0542635f3ae1c71c0c669/src/robot.cpp#L472-L473

How to reproduce: Send v_x and v_y zero to a robot with current speed > AccBrakeAbsoluteMax * delta_t

FelipeMartins96 avatar Apr 20 '21 16:04 FelipeMartins96

oh, sry... I've missed that. :facepalm:

I can prepare a patch in the next days or if you like, you can also provide a patch yourself via Pull Request.

g3force avatar Apr 20 '21 21:04 g3force

I've tried some solutions, but they haven't worked so far, I'll try testing other ideas later

FelipeMartins96 avatar Apr 22 '21 13:04 FelipeMartins96

Could you test the following fix?

        if (v > 0) {
            vx *= new_v / v;
            vy *= new_v / v;
        } else {
            vx = cvv[0] * (new_v / cv);
            vy = cvv[1] * (new_v / cv);
        }

g3force avatar Apr 23 '21 17:04 g3force

it didn't work properly, I think it is because cvv is in global coordinates while vx and vy are local, I'll try converting it

FelipeMartins96 avatar Apr 23 '21 18:04 FelipeMartins96

        if (v > 0) {
            vx *= new_v / v;
            vy *= new_v / v;
        } else {
            // convert global to local
            dReal k, angle;
            angle = getDir(k);
            angle *= _DEG2RAD;
            dReal cvx = cvv[0]*cos(angle) + cvv[1]*sin(angle);
            dReal cvy = -cvv[0]*sin(angle) + cvv[1]*cos(angle);

            vx = cvx * (new_v / cv);
            vy = cvy * (new_v / cv);
        }

I think this fix works

FelipeMartins96 avatar Apr 23 '21 19:04 FelipeMartins96