Theory of Self-maintaining Robots