An iterative scheme for learning gravity compensation in flexible robot arms