Legacy auto makers such as Ford and GM are racing to catch up to Tesla by investing billions of dollars to develop electric cars.