ITS: Improve error msg if wrong firmware

Bug: 234605416
Test: Run test_sensor_fusion with old/new firmware
Change-Id: I5a418d4e90c6a3da7260d48eebdf87e0feeb32f7
diff --git a/apps/CameraITS/utils/sensor_fusion_utils.py b/apps/CameraITS/utils/sensor_fusion_utils.py
index 327b233..48a61da 100644
--- a/apps/CameraITS/utils/sensor_fusion_utils.py
+++ b/apps/CameraITS/utils/sensor_fusion_utils.py
@@ -87,6 +87,7 @@
                       criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT,
                                 10, 0.03))  # cv2.calcOpticalFlowPyrLK params.
 _ROTATION_PER_FRAME_MIN = 0.001  # rads/s
+_GYRO_ROTATION_PER_SEC_MAX = 2.0  # rads/s
 
 # unittest constants
 _COARSE_FIT_RANGE = 20  # Range area around coarse fit to do optimization.
@@ -364,6 +365,7 @@
     raise AssertionError('Gyro times do not bound camera times! '
                          f'gyro: {gyro_times[0]:.0f} -> {gyro_times[-1]:.0f} '
                          f'cam: {cam_times[0]} -> {cam_times[-1]} (ns).')
+
   # Integrate the gyro data between each pair of camera frame times.
   for i_cam in range(len(cam_times)-1):
     # Get the window of gyro samples within the current pair of frames.
@@ -396,7 +398,6 @@
         f = (t_cam1 - t_gyro0) / (t_gyro1 - t_gyro0)
         frac_correction = gyro_val * t_gyro_delta * f
         gyro_sum += frac_correction
-
     gyro_rots.append(gyro_sum)
   gyro_rots = np.array(gyro_rots)
   return gyro_rots
@@ -651,6 +652,13 @@
   matplotlib.pyplot.savefig(f'{file_name}_gyro_events.png')
   pylab.close(plot_name)
 
+  z_max = max(abs(z))
+  logging.info('%.3f', z_max)
+  if z_max > _GYRO_ROTATION_PER_SEC_MAX:
+    raise AssertionError(
+        f'Phone moved too rapidly! Please confirm controller firmware. '
+        f'Max: {z_max:.3f}, TOL: {_GYRO_ROTATION_PER_SEC_MAX} rads/s')
+
 
 def conv_acceleration_to_movement(gyro_events, video_delay_time):
   """Convert gyro_events time and speed to movement during video time.