Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Hey guys!

    I'm developing an application which uses the accelerometer sensor, available on some S60 phones. I want to handle a shake, by using the RDAccelerometer.lib . So, i'm already using the accelerometer, I just need to get good values for a shake. The current values i'm using are very sensitive, any little shake on the phone, and it triggers the action. The code i'm currently using is:

    Code:
    void CMusicShakeAppView::HandleAccelerationL( TInt aX, TInt /*aY*/, TInt /*aZ*/ )
    	{
    	iAccelX[iAIndex++]=aX; //Only on X
    	
    	if (iAIndex>1) {
    		TInt Diff = iAccelX[0] - iAccelX[1];
    		
    		if ( aX>30 ) {
    		
    			//Do something here ...
    
    		}
    		iAIndex=0;
    	}
    	}
    I've already checked the MovingBall source code, but it didn't helped me on how to handle shakes, anyway.

    If you could help me would be great

    Thanks!!!

    (Especial thanks to Paul Todd who gave me the hint of the S60 Public API in my last topic!)

  2. #2
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    How about simply displaying the differences? Then you could find an optimal threshold in a visual way, via shaking your device and checking the output.

  3. #3
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    You mean displaying the accelerometer data on screen and check the values?

  4. #4
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Please help!!!

  5. #5
    Nokia Developer Champion hotcheese's Avatar
    Join Date
    Jul 2004
    Posts
    2,015
    I know absolutely nothing whatsoever about the accelerometer yet Wizard's suggestion makes perfect sense to me.
    What is it about his suggestion, which seems like a good idea, that you find so difficult to understand?

    And even if you don't understand his suggestion then what is preventing you from trying a bit of experimentation? If the threshold is a billion do you get the result you want? If not then what if the threshold is a million, or a thousand or whatever.

    In the time you've been waiting hoping for somebody to supply a magic value you could have experimented and found the IDEAL range of values that YOU want. The chance that somebody will suggest a threshold value and it will be exactly what you want seems a bit tenuous anyway. What if I said you should use 150 and it was still just a tiny bit over sensitive than what you wanted, would you come back and ask for another suggestion for another number to try?
    Hey, why don't you try 150 anyway.

    Is there something about this problem that isn't apparent and I therefore don't undertand the issues involved?
    Last edited by hotcheese; 2008-09-24 at 23:38.

  6. #6
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Thanks for the reply, hotcheese!

    But I want you to know that I'm really trying to do it. I'm not just hoping someone comes here and solve for complete my problem. The issue is that I think I'm handling it badly. By my tests, the shake value should be between -5 and 5. But when I put this values it becomes more sensitive that it was. So, If anyone knows how to "filter" the shake to X axis and some helpful values, please tell me. I will continue to try!

    Hope you all understand!

  7. #7
    Nokia Developer Champion hotcheese's Avatar
    Join Date
    Jul 2004
    Posts
    2,015
    Hi

    How did you get your test values of -5 to 5?


    How often does HandleAccelerationL() get invoked, is it lots of times per second? Maybe the average threshold is -5 to 5 but occassionally there are peak values which results in action you don't want, but if the function gets called many many times then even if there is only an occasional peak value it will make your code execute apparently all the time.
    Find out if this is the case, if so you could write code to recognize and exclude peak values or base the threashold value upon an average of values and not against each individual value.

  8. #8
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Yes, I think it's invoked all the time, since the HandleAccelerationL() is the function that controls the accelerometer data. So it should be active as long as the accelerometer is on.

    I tested with -5 and 5 and -10 and 10. Both are too dificult to work. Instead of the shake being very sensitive, it becomes difficult to trigger, you have to shake a lot.

    Inspite, when I use ==, it's hard to shake, and when I use just =, it's very sensitive:

    Code:
    if (aX==+-5) {
                  
                   // this is a very hard shake.
          }
    
    if (aX=+-5) {
    
            // this is a very sensitive shake.
    }

    How could I delete this peaks? (I think they must exist)

    Thanks for the help, hotcheese!

  9. #9
    Nokia Developer Champion hotcheese's Avatar
    Join Date
    Jul 2004
    Posts
    2,015
    You could detect the peaks by logging every value received to a file and then examining the contents of the file afterwards. THen you could see what values you are receving exactly and analyse them.

    But what is this syntax supposed to mean?

    aX=+-5



    And what do you think is the difference between = and ==?

  10. #10
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Quote Originally Posted by hotcheese View Post
    You could detect the peaks by logging every value received to a file and then examining the contents of the file afterwards. THen you could see what values you are receving exactly and analyse them.

    But what is this syntax supposed to mean?

    aX=+-5



    And what do you think is the difference between = and ==?
    aX=+-5 is the same thing of aX=+5 or -5

    The difference of = and == I have no idea in this case.

  11. #11
    Nokia Developer Champion hotcheese's Avatar
    Join Date
    Jul 2004
    Posts
    2,015
    If you don't know the difference why are you experimenting with them.

    Check out a C/C++ book, one is assignment and one is equality thus you will get radically different result, one will always return true !!!!!!

  12. #12
    Registered User sriky27's Avatar
    Join Date
    Dec 2005
    Posts
    1,236
    Hi,
    I tried this formula to find out shake however you can play around with the threshold it depends on how sensitive you want
    (x2*x2 + y2*y2 + z2*z2 )- ( x1*x1 + y1*y1 + z1*z1 ) > 900
    where x2, y2, z2 are current values and x1,y1,z1 are previous values.
    Hope you would find it useful.
    Regards,
    Sriky

  13. #13
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Thank you both for the reply!

    sriky27, it would be like this:

    Code:
    void HandleAccelerationL(TInt aX, TInt aY, TInt aZ)
        {
    
        if ((x2*x2 + y2*y2 + z2*z2 )- ( x1*x1 + y1*y1 + z1*z1 ) > 900) {
            
             //Do Something here ...
        }
        }
    Is this right? What would be the previous and the current values?

    Thanks for the reply!!

  14. #14
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    Sriky attempted to convert your uniaxial check into 3D. The two ()-s are the 2nd powers of the lengths of your acceleration vectors, and the 900 is the 2nd power of your 30.
    From algebraical point of view the transformation is not correct (though it can be intentional), from a programmer's point of view it can work. But it is still using your '30' in practice.

  15. #15
    Registered User sriky27's Avatar
    Join Date
    Dec 2005
    Posts
    1,236
    Hi wizard_hu,
    You are correct but i guess the acceleration call back does give the change in all the three direction and I have used and coming to the 30 it was a factor I came up with lot of testing though I dont have much to explain on it, it was a test based factor not a theory based one. Correct me if I am wrong. Suggestion is appreciated.

    Rafeal,

    initially iX1 , iY1, iZ1 are initialized to zero, when you get the call back

    void HandleAccelerationL(TInt aX, TInt aY, TInt aZ)
    {

    if ((aX*aX + aY*aY + aZ*aZ )- ( iX1*iX1 + iY1*iY1 + iZ1*iZ1 ) > 900) {

    //Do Something here ...
    iX1 = aX;
    iY1 = aY;
    iZ1 = aZ;
    }
    }
    Regards,
    Sriky

Page 1 of 2 12 LastLast

Similar Threads

  1. Cannot handle SIP response
    By biyikli in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-04-20, 12:31
  2. how to get the camera handle...
    By s60sdk in forum Streaming and Video
    Replies: 0
    Last Post: 2007-03-22, 11:54
  3. Replies: 0
    Last Post: 2006-12-26, 12:35
  4. Cannot handle SIP rsponse
    By biyikli in forum Mobile Java General
    Replies: 0
    Last Post: 2006-11-02, 07:35
  5. D211CTL.EXE Handle counts increases
    By lkussy in forum Multimodecards
    Replies: 0
    Last Post: 2004-01-15, 09:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved