Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Zumo for Arduino Accelerometer Question



Does the LSM303 library have the ability to determine if the impact is from the front AND/OR the rear? If so, how would one be able to pull that data? With negative threshold defined?

i.e: #define XY_ACCELERATION_THRESHOLD **-**2400

I am using a Zumo v1.2 bot. I would like the bot to go in reverse if it detects a collision from the back.



Hello, Z.

The LSM303 library does not have a function that specifically indicates the direction of an impact. However, you can read and interpret the raw accelerometer data to program that reversal behavior, but it will require in-depth modifications to the SumoCollisionDetect.ino example in the Arduino library for the Zumo Shield.

Changing the XY_ACCELERATION_THRESHOLD value to a negative will not work, because the program computes the magnitude of the acceleration of the XY plane, ignoring direction, and compares it to that threshold.

Since it sounds like you are not familiar with how the SumoCollisionDetect example and the LSM303 library work, I suggest that you first try to understand how the collision detection behavior works by looking at the relevant parts in the code (e.g. check_for_contact) before looking at the available functions in the LSM303 library. Once you do that, you should have a general idea of how to modify the example to execute specific actions based on the impact direction.

- Amanda



Thank you for helping me dial in the to how the code is set up.:wink: I added check_for_contact_reverse() with the necessary bits and the bot is responding to impacts from the front and rear now. Well, the buzzer anyways. Next, will be adding the drive functions.

Just a little closer to becoming self aware… :grin:

Take care,