# Zed2i - detect backwards movement

**URL:** <https://community.stereolabs.com/t/zed2i-detect-backwards-movement/2165>\
**Category:** Python\
**Tags:** imu\
**Created:** [February 23, 2023, 12:37pm UTC](https://community.stereolabs.com/t/zed2i-detect-backwards-movement/2165 "2023-02-23T12:37:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francois](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@Francois](https://community.stereolabs.com/u/Francois)\
**Post date:** [February 23, 2023, 12:37pm UTC](https://community.stereolabs.com/t/zed2i-detect-backwards-movement/2165/1 "2023-02-23T12:37:19Z")

</div>

Hi,

I’m working with a Zed2i.  
We will put it in a car, heading front. We detect objects, that we place on a map.  
The car’s heading (and so the camera’s) is given by a GPS.  
The problem is, when we drive backwards, the heading is going backwards too and we project objects behind the car.

**How can I detect that the car is running backwards ?**  
I tried using the IMU. I recorded a SVO, walking forwards then backwards.

```python
        sensors_data = sl.SensorsData()
        accelerometer_csv = open('/home/georges/Workspace/test_accelerometre/accelerometer.csv', 'w+')
        accelerometer_csv.write("frame;linear_acceleration_0;linear_acceleration_1;linear_acceleration_2\n")
        while zed.grab(rt_param) == sl.ERROR_CODE.SUCCESS and svo_position < end_frame:
            svo_position = zed.get_svo_position()
            zed.get_sensors_data(sensors_data, sl.TIME_REFERENCE.IMAGE) # Retrieve only frame synchronized data
            # Extract IMU data
            imu_data = sensors_data.get_imu_data()
            # Retrieve linear acceleration and angular velocity
            linear_acceleration = imu_data.get_linear_acceleration()
            angular_velocity = imu_data.get_angular_velocity()
            accelerometer_csv.write(f"{svo_position};{linear_acceleration[0]};{linear_acceleration[1]};{linear_acceleration[2]}\n")

```

But I cannot read the graph, telling on which part I was walking forwards (frames 40 to 100), and which part I was walking backwards (frames 120 to 190).

 ![image](https://community.stereolabs.com/uploads/default/original/2X/7/7b3f9e134221a127f030bc07232dead10be48323.png)

Note that I tried with sl.TIME\_REFERENCE.LAST and sl.TIME\_REFERENCE.CURRENT too.

---

<div class="post-metadata">

**Author:** ![alassagne](https://community.stereolabs.com/user_avatar/community.stereolabs.com/alassagne/32/2428_2.png) [@alassagne](https://community.stereolabs.com/u/alassagne)\
**Post date:** [February 23, 2023, 6:43pm UTC](https://community.stereolabs.com/t/zed2i-detect-backwards-movement/2165/2 "2023-02-23T18:43:36Z")

</div>

Hello and thank you for contacting us,

Rather than using the IMU, you should use our Positional tracking. Check our positional tracking on github [https://github.com/stereolabs/zed-examples/tree/master/positional%20tracking](https://github.com/stereolabs/zed-examples/tree/master/positional%20tracking)  
Take care of the reference. If you use WORLD, you get an absolute position. If you use CAMERA, you get a position relative to the previous frame.

Best regards,

Antoine Lassagne  
Senior Developer - ZED SDK  
Stereolabs Support

---

<div class="post-metadata">

**Author:** ![Francois](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@Francois](https://community.stereolabs.com/u/Francois)\
**Post date:** [February 27, 2023, 9:40am UTC](https://community.stereolabs.com/t/zed2i-detect-backwards-movement/2165/3 "2023-02-27T09:40:53Z")

</div>

Thanks a lot, it seems to work.
