This paper proposes an Improved Particle Swarm Optimization (IPSO) technique for adjusting the gains of a PID controller. The new approach introduces particle space constraints so as to improve the performance of velocity updating and position updating capability. Numerical simulations and experimental results based on PID, PSO-PID and IPSO-PID control systems are compared. Real time experimental results show that the proposed IPSO algorithm has great computational convergence and ensure the stability of the controlled system without the strict constraints on the updating velocity. Tests on the linear synchronous motor (LSM) via the digital signal Microchip (dsPIC) processor demonstrate effectiveness and robustness in positioning with disturbance excitation.