Uber’s self-driving vehicle program has been rocked by a fatal collision, a costly legal fight with Alphabet Inc.’s Waymo and the sudden dissolution of its robotic-trucking project. But a new partnership and investment from Toyota Motor Corp. could help change that and aid Uber’s plans for an IPO by 2019.

The Japanese automotive giant will invest $500 million in the U.S. ride-hailing company and also supply a purpose-built vehicle based on the Toyota Sienna minivan for the project, the companies said in a joint statement. The minivan go into an on-demand pilot ride service in 2021 and use both Uber’s autonomous driving system and Toyota's suite of automated safety tech features it calls Guardian.

"The deal is the first of its kind for Uber, and signals our commitment to bringing world-class technologies to the Uber network," Uber CEO Dara Khosrowshahi said in a statement. "Our goal is to deploy the world's safest self-driving cars on the Uber network, and this agreement is another significant step towards making that a reality."

It may be a coup for Khosrowshahi as he works to rehabilitate the San Francisco company’s image, cut costs and improve the balance sheet ahead of his target to take Uber public by next year. The Toyota project also comes days after Uber filled a CFO position that had been empty since 2015.

The partnership also benefits Toyota, which has previously invested in Uber. Though it’s among the world’s most advanced automakers, Toyota has moved more conservatively in the autonomous vehicle space than competitors such as General Motors and Waymo. In January, Toyota CEO Akio Toyoda showed off the e-Palette, a vanlike vehicle for use in ride-share and delivery services, and said Uber might be among the companies that use it.

The Toyota e-Palette, an autonomous vehicle designed for multiple business purposes such as driverless stores, is displayed at CES in Las Vegas, Nevada, January 12, 2018.

Getty

“This agreement and investment marks an important milestone in our transformation to a mobility company as we help provide a path for safe and secure expansion of mobility services like ride-sharing that includes Toyota vehicles and technologies,” Shigeki Tomoyama, Toyota's executive vice president and head of Toyota Connected, said in the statement.

Uber’s program, which under former CEO Travis Kalanick attempted to catch up to Waymo, formerly the Google Self-Driving Car Project, spent lavishly to do so, including the $680 million August 2016 purchase of Ottomotto LLC, a startup created by former Google driverless car engineer Anthony Levandowski. Kalanick made no secret of his plan to one day replace human drivers on the Uber platform with fully automated vehicles that would be much cheaper to operate.

The company also beat tech rivals by launching a public ride program in Pittsburgh in September 2016, touting it as one of the first large demonstrations of robotic vehicles.

Soon after, Levandowski, who’d co-founded Otto as a provider of autonomous trucking technology, was accused in a federal lawsuit of taking trade secrets stolen from Waymo with him to Uber. Uber eventually fired Levandowski and was ordered to give Waymo an equity stake valued at $245 million in February to settle that lawsuit.

Then, on March 18, one of Uber’s self-driving Volvo XC90 SUVs being tested in Tempe, Arizona, struck and killed Elaine Herzberg, 49, as she was crossing a dark city street. The safety driver doesn't appear to have been paying attention and a preliminary report by federal safety investigators found that although the vehicle’s sensors detected Herzberg, there was a delay in how rapidly it determined “emergency braking was needed to mitigate a collision.”

Although the National Transportation Safety Board hasn’t yet posted its final findings, the accident was the first fatality for a self-driving vehicle and an enormous blow to Uber’s program.

Then, in July, Uber announced it was discontinuing its robot truck program and would “move forward exclusively with cars,” Eric Meyhofer, head of Uber Advanced Technologies Group, said in a July 30 statement. "We recently took the important step of returning to public roads in Pittsburgh, and as we look to continue that momentum, we believe having our entire team’s energy and expertise focused on this effort is the best path forward.”

While the deal is certainly much-needed good news for Uber, it could also be a win-win partnership for Toyota as it looks to get self-driving vehicles on road the from the early 2020s, a bit after Waymo and GM Cruise robotaxi fleets start rolling out this year and next.