This is going to be a hard one…
Really, a lot of the explanations of how the segway works is flawed. They are true, but they aren’t getting at the basis of why it uses gravity to go.
You have to understand that torque of a motor is a force (one that is rotating). Force makes things go faster (increase velocity). The key to the segway is that it uses gravity to serve as a negative torque to make the wheels spin. If you had a platform such as the 2-wheeled Segway, but with some buttons on it to make it go forward or backward, the moment you pressed them, the wheels would go forward but also the platform would spin backward, and you would fall on your butt. This is because, as Isaac Newton said, for every action (force), there is an equal and opposite reaction (force). To counteract this reaction, the device forces you to lean forward. The device then accelerates you forward, until you are parallel to the force of gravity again. Velocity is not a force, so this explains why you can be moving. Force = Mass x Acceleration.
Next, torque will always cause a shaft to spin perpendicular to the torque acting upon it. This answers your question. The wheels are the source of torque, and the handlebar is the shaft. Therefore, the handlebars will always be perpendicular to the surface when the device spins. Also, the reason the platform doesn’t come crashing down even though you are straight up is that the motors are spinning in opposite directions, therefore they are inducing an equal, but opposite torque on the platform that cancels itself.
Really, all you need to make a segway work is a device that tells you when you are parallel to gravity. You can then just apply torque to the motors (negative or positive) until the device registers parallel (of course actual numbers make the work easier because then you can tell when you are approaching parallel and don’t overshoot). Of course you need +/- to tell which direction the user is leaning.
Speed really isn’t the issue, it’s how much torque you have available (and therefore the power of the motors). You should always have more torque than that of the weight of the rider times gravity. You can reasonably expect that the rider will only lean as far as 60 degrees so you can get away with multiplying the above number by sqrt(3)/2. You can reasonably expect a rider to be 200 lbs or 90 kg so the force you would need to apply at the wheels is sqrt(3)/2 * 90kg * 10 m/s^2 = 800N. This means you’d have to gear down your motors enough to put out 400N of torque each. You can cut this number to 250N of torque each if you expect the rider to lean a maximum of 30 degrees. Just don’t have any emergencies…
FIRST motors would barely be able to handle this at a decent speed. You could get away with using dual motors on each side. The motors on the segway are 1,500W each whereas our FIRST motors (drill, CIM) are 300-400W each.
By the way, you can cut down on the amount of torque required to right the rider by mounting most of your weight underneith the axle, such as the battery. Also, keep in mind that torque decreases linearly as the speed increases, so eventually it will reach the point where, at top speed, you won’t be able to “recover” the rider no matter how little they lean. You need to code a speed limiter that puts the max speed at 2/3 power. Once the rider leans forward at this max speed, the device should abruptly apply full power to force the rider into the backward position, and then reverse direction in the wheels, applying a force equal or barely higher than the gravitational force in the Y-Axis to slow them down (without crashing them into the ground).
Creating a Segway as functional as the real one is not easy. I’m sure the programmers have implemented some ingeneous algorithms to act as fail-safes. The purpose there is not to get sued. As you can see, some rudimentary physics and trigonometry are needed to create such a device.