We propose a mathematical and computational model for learning the grid cells that are observed in the brains of many species for spatial awareness and navigation. In this model, the self-position of the agent is represented by a vector, and the self-motion of the agent is represented by a block-diagonal matrix. The learned units exhibit hexagon grid patterns that characterize the grid cells. The learned model can be used for path integral and path planning. Moreover, the learned representation is capable of error correction. Based on joint work with Ruiqi Gao, Jianwen Xie and Song-Chun Zhu.