"Get a grip" actually has two meanings.
When a person has let their emotions take control of their actions and thoughts, often times people will tell them to "get a grip" - to get their emotions under control.
Get a grip (on yourself): to make an effort to control your emotions
and behave more calmly. (ex. Come on, get a grip, we've got an
important meeting in five minutes. I just think he ought to get a
grip on himself - he's behaving like a child.)
Get a grip (on yourself) (spoken): to control your emotions. (ex. I
know it's hard, but get a grip on yourself and tell me what you saw.
Oh, get a grip, Tess! It's really not as bad as you think.)
Additionally, "get a grip" can also refer to gaining an understanding:
Get a grip (on something): to understand how to deal with something.
(ex. The program will have helpful tips on how to get a grip on your
finances. Something is obviously not right in our organization, and we
must get a grip on the problem.)
As to the origination of the idiom, that I'm not sure of.