Generally to do one thing, and that is two solve or prevent Government tyranny via Constitutional "loophole".
Examples; Some governments among the Union did not see negroid people as "human" or otherwise inferior and did not grant them equal rights. Therefore to patch this Constitutional Loophole amendments 13, 15, and for women, 19 were made.
Everyone has the God-given right to things like Life, Liberty, and Property. They also have the God-given right to defend those things from people who wish to wrongfully harm them. This means that they have the right to self-preservation, and may acquire tools to do so. To make sure this is not prevented, the Second Amendment was made, so that there is no Constitutional "Loophole" to disarm the populous.