|Argh! How do I detect when you've tipped over? Argh!|
I felt very tired this morning. I got about nine hours sleep last night.
I added controls to manually rotate a robot around yaw, pitch, and roll. Makes working out the numbers to help me set limits easier.
The valid range for pitch will be from -85 degrees to 85 degrees.
The valid range will be the same for roll.
Luckily, only yaw is the tricky one and I don't need to look at that to write the code to help robots get back up.
The problem is that roll changes when I change yaw.
The same with pitch.
When yaw is 0 degrees, pitch is 0 degrees and roll is 0 degrees.
When yaw is -90 degrees, pitch is 180 degrees and roll is -180 degrees.
5 degrees more and yaw is -85, pitch -180, roll is 180.
There's got to be an easier to way to tell when a robot has tipped over and then reset it.
I could cheat. I could reset any robots that haven't moved for a while or disable vertical movement...
I wish my teachers had put mathematics in context for when I was a kid. I would have paid much more attention and learned a whole bunch more.
I remember something about how you can put the end of two vectors together and calculate the angle between them. I think you can do the same thing with quaternions. I can get a quaternion representing a robot's orientation and another quaternion that points straight up. Then I can calculate the angle between then and if it is more than 85 degrees, I can reset the position of the robot. I'll give it a go tomorrow.
Through doing game and simulation programming, I've come across more and more situations that have put the maths that I barely learned in use. One of the things I'm going to do is keep track of these situations. I have a hunch they'll become useful. Especially as my little brother starts to complain about learning maths.