How to tell if hardware component is detached?

How can a program tell if a component on the robot is working/attached or not?

For example, if I wrote…

void MyFunction()
    Jaguar *j = new Jaguar(3);

… how can I tell if the Jaguar is actually responsive and connected to the cRIO? What about for a camera? For joysticks?

Well. First make sure the Jag has power. When you turn on your robot, your Jaguar should have a yellow flashing light.

Enable the code, and that light should stay solid. Solid yellow light means it’s connected.

If you were to use the axis a Jaguar was on, it would change from a yellow solid light to a green light in 1 direction, and red in the other.

The camera, I’m not exactly sure of the process of seeing if it’s connected or not.

Joysticks should be listed in the Driver station if they are working. I believe under Diagnostics.

Sorry, I meant to ask how I can programmatically determine that so that if, for example, the camera is disconnected, the code will recognize that and just skip over the piece that uses it.

Why do you need to dynamically skip over the code? We use #ifdef to enclose code for some components such as Vision, so if we don’t have the camera connected, that code won’t compile. Isn’t that good enough?

Call me paranoid, but I’m worried about the robustness of the robot. For example, if a wire somehow comes loose during the competition, I’d like to have an error message pop up so we can diagnose it later and continue playing, and still be assured that the robot will continue to function and not accidentally go haywire.

Well then, if you want to do the work. Unfortunately, different components have different ways to report failures. For example, if you are using CANJaguar, WPILib will set error status when an operation failed. So in theory, you can query this status.
So for each component that you wish to write recovery code for, you need to look through the source code of WPILib and find a way to “poll” the health status of the hardware. CANJaguar is an easy one. If you are using PWM for Jaguars, that may be harder. Since PWM is an output only signal. So there is no feedback you can examine. Regarding camera, I haven’t looked through it in too much details, but it seems the camera task also has some sort of status that you may be able to query. Like I said, if you want to do the work, you need to dig into the source code of WPILib.