Refer the following documentation link which states how you can perform troubleshooting steps when you get the error "Unable to receive data from the target hardware".
If you continue to face the issue with IMU sensors, it is likely that it is due to the loose connections between the sensor and Arduino board. This causes the code to get stuck while performing the I2C operation.
Also, Trace messages can be used to view the commands which are being executed on the hardware board when you are using sensor functions. To view the trace messages, create the arduino object with the TraceOn parameter set as true and use sensor functions.