Nationals infielder Danny Espinosa, right, hit a pinch-hit home run in Sunday’s win over the Giants. (Greg Fiume/Getty Images)

Nationals second baseman Danny Espinosa has spent much of this season in the batting cages, trying to simulate pitches at game speed.

This is because opportunities at the plate have diminished for the 27-year-old, whose hitting has been off track for almost two seasons. Despite everything Espinosa offers defensively, his struggles at the plate have earned him a spot on the bench.

But he still has to prepare as if he’s a starter, just in case he’s called upon. Coming off the bench in Sunday’s 14-6 win over the Giants, Espinosa, a switch-hitter who entered Tuesday’s game batting .217, crushed a pitch from the left side of the plate for his eighth home run of the season.

“My role this year has been when guys get hurt to get in there,” Espinosa said. “If not, keep your head up, keep grinding, keep doing what you can to maintain your swing and game speed.”

Espinosa has some extreme splits this year. Before Tuesday’s game, he hit .298 batting right-handed against left-handed pitchers. But as a lefty facing right-handers, his average was a dismal .181.

When Ryan Zimmerman injured his hamstring in July, the Nationals made a deal with Cleveland to bring in infielder Asdrubal Cabrera. The move essentially guaranteed that Espinosa would stay on the bench and could eliminate almost any meaningful playing time for him this season once Zimmerman is cleared to return.

“I’ve been working on my swing a lot in the cages. I’ve been feeling good and sticking to my routine,” Espinosa said. “Obviously, with Asdrubal doing well for us, [I’m] not going to get the at-bats. But I’ll continue to work and hopefully it will play out as I get a couple more at-bats.”

Read more from Express Sports:

Nationals’ Wilson Ramos finally starting to get his power back

For Nationals, it’s been a taxing time on the bullpen

Nationals have put together a string of nail-biting wins

Nationals lead NL East, but Strasburg and Harper aren’t the reason why

Nationals’ Jordan Zimmermann hasn’t changed approach, but he’s getting better results