I've been doing that my whole life...
I have RLS...restless leg syndrome.
I also have ADHD...
Both of those combined make it difficult to sleep some nights.
Do your legs feel like they have spiders or something crawling on them if you try to keep your legs still? If yes, then it's probably RLS.
I suggest seeing a doctor to rule out anything more serious.
You can try vigorous exercises ( like running on the spot) before getting into bed to see if that helps. Maybe a nice hot shower or bath as well.
Good luck, and keep us posted.
~update~
I will accept advice from anyone but I prefer a doctor