Robots, especially ours it seems :D, seem to disconnect at the worst possible times and are very annoying to handle.
This method is what seems to work best for us and it is a very comprehensive strategy.
Turn off robot.
Disconnect robot phone from usb
disconnect cables from expansion hubs/webcam
replug everything except phones
fully exit (swipe out app from dock) Robot Controller App and Driver Station App
Turn on robot.
Plug in robot phone with app not open
wait for phone to automatically open app
click restart robot with the three dots in the upper right corner
wait and then click configure robot
select your config
click scan and make sure it detects your hub(s)
return to main screen
open driver station app and listen for the ring that says you are connected
it should be good to go now!
phone usbs are in, but at an angle or slightly loose
phones need to be secure tightly to minimize shaking during rounds which dislodge USB
add stress relief case for your phone and expansion hub (search it on Thingiverse)
Usually Android Studio or Onbot Java will tell you if your code has an error before it downloads. However, this only catches Syntax Errors (haha a fellow robot team) not logic errors so code could have inherent flaws that don't do what you intended. We ourselves have only encountered one software issue causing disconnects, and it was because there was a missing opModeIsActive() boolean and also the computer vision code was running the entire autonomous which eats up a lot of computing power, so we solved that by disabling the camera earlier.
TIP: it often helps to have a non-coder check your code because they will question everything and be able to see past the bias of a programmer who may skip over certain details. (how we figured out the computer vision issue above)
For a more in depth guide on troubleshooting controls, refer to this trouble shooting guide: www.firstinspires.org/sites/default/files/uploads/resource_library/ftc/control-system-troubleshooting-guide.pdf
Hope this helps!
Also, you can always contact us through the contact page!