3

I am trying to create an app which detect road bumps or potholes while driving , and i have searched for possible solutions on google and i have found a solution which uses accelerometer values to detect road bumps.

I have used code from this link , which is good when you tap phone against your palm but its not detecting bumps while driving car. iOS: Accurately determining energy of a bump from accelerometer output

I also found an algorithm Z-Diff which can be used to find road bumps, an explanation of that algorithm is here : http://open-sci.net/wiki/sealappexamplepotholes

This is the Code i have used :

typedef struct{ double x,y,z; }vec_d3;

#define RECENT_COUNT 10
#define SMOOTH_IP(x,x_new,fac) x = fac * x + (1. -fac) * x_new
#define DOUBLE_EMPTY DBL_MAX

-(void)startTakingMotionValues{



[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {


    static vec_d3 smooth = {DOUBLE_EMPTY,0,0};
    {
        if(smooth.x == DOUBLE_EMPTY){
            smooth.x=accelerometerData.acceleration.x;
            smooth.y=accelerometerData.acceleration.y;
            smooth.z=accelerometerData.acceleration.z;

            return;
        }
        SMOOTH_IP(smooth.x, accelerometerData.acceleration.x, 0.9);
        SMOOTH_IP(smooth.y, accelerometerData.acceleration.y, 0.9);
        SMOOTH_IP(smooth.z, accelerometerData.acceleration.z, 0.9);
    }

    // keep track of last k smoother acceleration values
    static vec_d3 recent[RECENT_COUNT];
    {
        static int ptr=0;
        static BOOL gotEnoughData = NO;

        recent[ptr]= smooth;
        ptr++;
        if(ptr==RECENT_COUNT){
            ptr=0;
            gotEnoughData=YES;
        }
        if (!gotEnoughData) {
            return;
        }
    }
    //get the resultant variation in acceleration over the whole array
    double variation;
    {
        vec_d3 min = smooth,max=smooth;
        for (int i=0; i< RECENT_COUNT; i++) {
            min.x = MIN(min.x, recent[i].x);
            min.y = MIN(min.y, recent[i].y);
            min.z = MIN(min.z, recent[i].z);

            max.x = MAX(max.x, recent[i].x);
            max.y = MAX(max.y, recent[i].y);
            max.z = MAX(max.z, recent[i].z);
        }
        vec_d3 V = (vec_d3)
        {
            .x = max.x - min.x,
            .y = max.y - min.y,
            .z = max.z - min.z
        };
        variation =sqrt(
                        V.x * V.x +
                        V.y * V.y +
                        V.z * V.z
                        );
    }
    //smooth it
    static double var_smoothed = DOUBLE_EMPTY;
    {
        if (var_smoothed == DOUBLE_EMPTY) {
            var_smoothed = variation;
            return;
        }
        SMOOTH_IP(var_smoothed, variation, 0.9);
    }

    // see if it's just passed a peak
    {
        static double varSmoothed_last = DOUBLE_EMPTY;
        if (varSmoothed_last == DOUBLE_EMPTY) {
            varSmoothed_last=var_smoothed;
            return;
        }
        static double varSmoother_preLast = DOUBLE_EMPTY;
        if (varSmoother_preLast == DOUBLE_EMPTY) {
            varSmoother_preLast = varSmoothed_last;
            varSmoothed_last = var_smoothed;
            return;
        }

#define THRESHOLD_IMPLUSE .40

        if (varSmoothed_last > varSmoother_preLast &&
            varSmoothed_last > var_smoothed &&
            varSmoothed_last > THRESHOLD_IMPLUSE) {
            didFindLocation=NO;
            if (newLocation.speed < 5) {

            }else{
            NSLog(@"varSmoothed_last: @ %f",varSmoothed_last);
            NSLog(@"varSmoother_preLast : %f",varSmoother_preLast);
            NSLog(@"var_smoothed : %f",var_smoothed);

            [self.bumpsData addObject:[NSString stringWithFormat:@"%f",varSmoothed_last]];
            [self.bumpsTableView reloadData];
            }

            //[self peakedWithImpulse: varSmoothed_last ];

        }
        varSmoother_preLast = varSmoothed_last;
        varSmoothed_last = var_smoothed;
    }

    }];
}
Community
  • 1
  • 1
Shabir jan
  • 2,295
  • 2
  • 23
  • 37
  • You haven't asked a question. You need to be specific about your code and what it does wrong. – Wain Jan 28 '15 at 07:48
  • @Wain The question is very clear , i have used code from the link i gave in second paragraph and i have also mentioned what is the issue i am getting. The issue is that code is not detecting bumps while driving but if you smash phone on your palm it detect that bump. – Shabir jan Jan 28 '15 at 07:57
  • 1
    Have you played around with the parameters - THRESHOLD_IMPLUSE, RECENT_COUNT? Also you can vary the sampling rate. These should all help to give you a way to vary the sensitivity (I am assuming the code and algorithm works correctly) – foundry Jan 28 '15 at 08:50
  • @foundry i am making app in iOS SDK, can you give me any example. I have tried the above code and my update frequency for accelerometer is 1.0/100. Can you help me sort this problem. Yes i have changed the THRESHOLD_IMPLUSE to different values . if i lower the THRESHOLD_IMPLUSE value it detect too many bumps. – Shabir jan Jan 28 '15 at 08:55
  • 1
    Have you just logged the values that are seen when you hit a bump in the road to see what they are so you can set the threshold appropriately? – Wain Jan 28 '15 at 09:10
  • Yes i am showing the bump value in the TableView whenever there is bump detection, but if i set the THRESHOLD_IMPLUSE value to .05 i am getting too much bumps value, and when i tried to set THRESHOLD_IMPLUSE value to .40 as this is the value most apps are using i am not getting a single bump. – Shabir jan Jan 28 '15 at 09:12
  • What did you find to be good values in the end? – Burf2000 Feb 09 '17 at 11:20

1 Answers1

1

You need to start by playing with the parameters, to get a feel for how the algorithm can be tuned to different frequency sensitivities:

#define THRESHOLD_IMPLUSE .40
#define RECENT_COUNT 10

Also you have a smoothing coefficient of 0.9 you could try adjusting:

SMOOTH_IP(smooth.x, accelerometerData.acceleration.x, 0.9);

You are trying to isolate an amplitude and wavelength that is indicative of a road bump. Adjusting the RECENT_COUNT or the smoothing coefficient should enable you to reduce the sensitivity to high-frequency bumps. Adjust the THRESHOLD_IMPULSE will probably affect the amplitude cut-off.

To measure how these affect the results, you should also devise some method for test and measurement. Recording some data from road bumps would help you a lot to understand the behaviour you are hoping to detect.

Once you have understood the algorithm, and tuned it, if it still does not isolate the movement you are after, you should take a look at the other algorithms in the first of your links, understand them each separately, and try adding them to the mix.

foundry
  • 31,615
  • 9
  • 90
  • 125