ukmars / mazerunner-core

Core micromouse software for the ukmarsbot robot
MIT License
20 stars 8 forks source link

Magic numbers ? #9

Closed Nikitarc closed 2 months ago

Nikitarc commented 2 months ago

Hello In one of your youtube video you said there is no 'magic number' in the code. But I found 2 not explained values in profile.h.

211 m_target_speed = m_sign * 5.0f; // magic number to make sure we reach zero I understand the reason for the instruction, but how is this value determined, and what is its effect?

232 if (m_state != PS_FINISHED && remaining < 0.125) { How is the value 0.125 determined? Does it depend on the resolution of the encoder, the mass of the mouse (inertia). It probably needs to be determined experimentally to have a precise stop.

All this just to have a few more lines of comment!

Is there a place to ask this kind of question or more general ones about UKMARSBOT or this code (like a forum)?

Best regards

micromouseonline commented 2 months ago

Thank you for noticing.

Yes, there are still magic numbers.

The forst of these I normally set to be the same, numerically, as the current acceleration. It is just a small velicity that ensures that the motion continues past the finish point in case floating point rounding prevents that happening. It is a nasty hack I keep meaning to find a more tidy solution for.

The second is also a hack to ensure floating point rounding errors do not prevent the loop termination. The units are mm and independent of the encoder resolution. I figure that being within 1/8 of a mm will be close enough.

I should add an explanation.

This is a good place for these questions. We have no forum - only a UKMARS members mailing list.

If you wish you can also generate pull requests with code improvements. They are always welcome.

Nikitarc commented 2 months ago

Hello

My Github skills are very poor. I'll make a pull request when I'm done studying the code and understand it a bit better. Thank you for making your many years of experience available so generously.

micromouseonline commented 2 months ago

Practice makes perfect. Please raise further issues if you need assistance. I will close this one for now.