Ankle foot orthoses (AFOs) are widely used as assistive/rehabilitation devices to correct the gait of people with lower leg neuromuscular dysfunction and muscle weakness. We have developed a portable powered ankle-foot orthosis (PPAFO), which uses a pneumatic bi-directional rotary actuator powered by compressed CO2 to provide untethered dorsiflexor and plantarflexor assistance at the ankle joint. Since portability is a key to the success of the PPAFO as an assist device, it is critical to recognize and control for gait modes (i.e. level walking, stair ascent/descent). While manual mode switching is implemented in most powered orthotic/prosthetic device control algorithms, we propose an automatic gait mode recognition scheme by tracking the 3D position of the PPAFO from an inertial measurement unit (IMU). The control scheme was designed to match the torque profile of physiological gait data during different gait modes. Experimental results indicate that, with an optimized threshold, the controller was able to identify the position, orientation and gait mode in real time, and properly control the actuation. It was also illustrated that during stair descent, a mode-specific actuation control scheme could better restore gait kinematic and kinetic patterns, compared to using the level ground controller.