Resets during loop running

We need to see a diagram, and pictures of the setup.
With parts values/links and supply voltage/currents.

No kickback diodes across actuators could reset the Mega.
And maybe other things you haven't considered.
Leo..