Teaching robots to avoid moving obstacles