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

Possible division by zero on robot speed handling causing crashes #160

Open
FelipeMartins96 opened this issue Apr 20, 2021 · 5 comments
Open

Comments

@FelipeMartins96
Copy link
Contributor

grSim/src/robot.cpp

Lines 472 to 473 in 206c8dc

vx *= new_v / v;
vy *= new_v / v;

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

@g3force
Copy link
Member

g3force commented Apr 20, 2021

oh, sry... I've missed that. 🤦

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

@FelipeMartins96
Copy link
Contributor Author

FelipeMartins96 commented Apr 22, 2021

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

@g3force
Copy link
Member

g3force commented Apr 23, 2021

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);
        }

@FelipeMartins96
Copy link
Contributor Author

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
Copy link
Contributor Author

        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

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

No branches or pull requests

2 participants