In industrial automation and robotics, the motion control of the automatic equipment (e.g., mobile robots, assembling manipulators, machine tools, etc.) is an important task for intelligent and flexible manufacturing. Because of the limited space on the factory floor and limited operating conditions, most tasks require work in confined spaces and subject to regulatory requirements. This confined motion control objective is considered as the constraints in the paper (hence, it belongs to the constraint following control field). There are two categories of constraints for the motion control: equality and inequality which are corresponding to the two motion requirements. The problem of motion requirement with fixed boundary has not been solved systematically using constraint following method. The equation of motion for a constrained mechanical system which addresses both constraints is presented. This can be considered a generalization of the Udwadia-Kalaba (U-K) equation. The advantages of the equation include that it does not require additional pseudo variables and the solution is analytical. This exhibits profound applications. As a demonstration, a pan/tilt device mounted under the firefighting unmanned aerial vehicles (UAVs) is manipulated. The water-jet nozzle need motion requirements of swaying horizontally and not overshooting limits in vertical. Simulation and experimental results are presented to validate the effectiveness of the proposed approach.