Results 1 to 19 of 19
  1.    #1  
    Here's some code for folks who want to get started playing with raw data from the accelerometer. Very, very basic. It just lets you hold your Pre flat and tip it back and forth to roll a ball around. Figured it would be something fun to play around with for coders new to the Pre.

    Just one event handler and a tiny bit of math pulls off the heavy lifting:

    Code:
    MainAssistant.prototype.handleAcceleration = function(event) {
    	this.driftX += (event.accelX * this.scale);
    	this.driftY += (event.accelY * this.scale);
    	this.driftZ += (event.accelZ * this.scale);
    }
    And a PeriodicalExecuter to move the ball around once every 30th of a second:

    Code:
    MainAssistant.prototype.setup = function() {
    ...
    	new PeriodicalExecuter(function(pe) {
    		obj.moveDot();
    	}, (1/30));
    ...
    }
    And the moveDot function:

    Code:
    MainAssistant.prototype.moveDot = function(){
    	// Move that dot! Note that the Z axis isn't used in this demo...
    	this.theDot.style.left = (parseInt(this.theDot.style.left) + this.driftX) + 'px';
    	this.theDot.style.top = (parseInt(this.theDot.style.top) - this.driftY) + 'px';
    
    	// And there's more code to keep the ball within the viewport, just snag the source...
    }
    Attached Files Attached Files
  2. #2  
    just installed, works great!
  3. #3  
    I thought there was a 4Hz sample rate limitation from the accel API?
  4. #4  
    There's an app for the iPhone/iPod Touch like this but with obstacles and a Goal at the end of a maze. It's my favorite time-waster for the format.

    I hope someone further expands on this. The only suggestion I could think of would be to fix the speed. It seems to move too much with little effort. I suppose it kinda makes sense though. The ball is small so it's "lighter". A bigger ball would be "heavier" so it wouldn't move as much.

    Thanks again!
  5.    #5  
    Quote Originally Posted by Shane112358 View Post
    I thought there was a 4Hz sample rate limitation from the accel API?
    Indeed there is, and the "drift" variables are getting updated at 4Hz, however, the data can still be used 30 times a second (or more for that matter). I have a hunch that 4Hz was chosen simply to keep the API from getting flooded with "acceleration" events, lest the Pre be brought to it's kness any time an app wanted to put the accelerometer to work.

    At this point I am attempting to track down a method for bumping the polling interval up. Unfortunately it doesn't appear to be quite as simple as some of the other hardware hacks. Simply changing the value in "/sys/class/input/input5/poll_interval" (hopefully I got that typed out right...) doesn't do a damn thing. But, it does contain a value of "250" and 250ms = 4Hz, so that's certainly on the right track. Any info anyone has would be greatly appreciated!

    Quote Originally Posted by Dtom2444 View Post
    There's an app for the iPhone/iPod Touch like this but with obstacles and a Goal at the end of a maze. It's my favorite time-waster for the format.

    I hope someone further expands on this. The only suggestion I could think of would be to fix the speed. It seems to move too much with little effort. I suppose it kinda makes sense though. The ball is small so it's "lighter". A bigger ball would be "heavier" so it wouldn't move as much.
    I actually intend to code just that, a maze app. Dunno if I will get around to it or not, but if I do, it'll end up in the Homebrew section!

    The only reason this is so spartan is to show off how the code works, not to create an end user app/game. For that purpose, I wanted to add as few bells & whistles as possible. Hence why it is in the development forum and not homebrew.

    And personally, I feel it is still too slow. I haven't taken the time to add the math to lock this in to "real physics" yet, however I feel it is still slower than gravity. I want to get it to the point where "dropping" a ball from the top of the screen will result in it accelerating at 9.82 m/sē, the real acceleration due to gravity. (As in, calculating out the physical width of a pixel and going from there...)

    Think of it this way. With the scaling set the way it is now, if you put a marble on the screen of your Pre and rolled it around along with this ball, the marble would still roll around faster than the on screen ball... But, snag the code and change the scale variable around so you can get a feel for what is going on, it really helps to solidify understanding.
  6. #6  
    If this qualifies as an app, get it into the Homebrew section.
  7.    #7  
    Quote Originally Posted by Colonel Kernel View Post
    If this qualifies as an app, get it into the Homebrew section.
    It doesn't really...it doesn't do anything useful at this point. It simply exists to give programmers some code to start from when using the accelerometer. If I get around to adding some other physics goodies to it, then yeah, possibly should end up over in Homebrew.
  8. #8  
    And personally, I feel it is still too slow.
    Well, I showed this off to my brother and he immediately agreed with my previous statement. The responsiveness is okay, but it feels like it continues to roll for a split second too long, hence the "unnatural" feel.

    But good luck with that possible app! Can't wait to see what develops!

    "We all follow the Chelsea!!!"
  9.    #9  
    Quote Originally Posted by Dtom2444 View Post
    Well, I showed this off to my brother and he immediately agreed with my previous statement. The responsiveness is okay, but it feels like it continues to roll for a split second too long, hence the "unnatural" feel.
    Ah, yes, inertia. Yes, that would actually be taken care of by speeding it up. The "lag" is because it is responding slower than gravity actually would. Slow it down further and that "unnatural feel" gets magnified like you wouldn't believe.
  10. #10  
    Randall. Thank you for having such a concise example of using the accelerometer. I can't wait to play with this tonight. I've been working on a mythtv controller app, and this will add a few nifty whizbang features like jog control in recordings (turn the pre like a knob), and navigation of media lists by tilting the device 'up' and 'down'.

    Not killer features, I know. But the tv has such a larger screen, when you're in front of it
  11.    #11  
    Quote Originally Posted by dennisharrison View Post
    Randall. Thank you for having such a concise example of using the accelerometer. I can't wait to play with this tonight. I've been working on a mythtv controller app, and this will add a few nifty whizbang features like jog control in recordings (turn the pre like a knob), and navigation of media lists by tilting the device 'up' and 'down'.

    Not killer features, I know. But the tv has such a larger screen, when you're in front of it
    Excellent! People being able to get a quick start towards being innovative and creative is exactly what I was hoping for.

    The idea of using the Pre as a "knob" is great!
  12. #12  
    Quote Originally Posted by randallagordon View Post
    I actually intend to code just that, a maze app. Dunno if I will get around to it or not, but if I do, it'll end up in the Homebrew section!
    Please code it! I love apps that actually utilize the accelerometer!
  13. mjsmiley's Avatar
    Posts
    89 Posts
    Global Posts
    101 Global Posts
    #13  
    Quote Originally Posted by randallagordon View Post
    It doesn't really...it doesn't do anything useful at this point. It simply exists to give programmers some code to start from when using the accelerometer. If I get around to adding some other physics goodies to it, then yeah, possibly should end up over in Homebrew.
    First, this is probably one of the neatest apps amongst the homebrew apps. I think if you put this into the homebrew apps as a demo, it would get your code seen a lot more and maybe spark more development with it. This little red ball still shows more accelerometer promise than any other app that I've spotted-so I'm rooting for it getting mass attention on this forum. If you wanted to blow everyone's mind (or at least mine), add the ability to tap on the screan and create a small round fixed peg obstical.
  14. #14  
    Quote Originally Posted by randallagordon View Post
    At this point I am attempting to track down a method for bumping the polling interval up. Unfortunately it doesn't appear to be quite as simple as some of the other hardware hacks. Simply changing the value in "/sys/class/input/input5/poll_interval" (hopefully I got that typed out right...) doesn't do a damn thing. But, it does contain a value of "250" and 250ms = 4Hz, so that's certainly on the right track. Any info anyone has would be greatly appreciated!
    I don't know if you are keeping up with this, but changing this value does indeed work. I have also created a service for apps to use so they can dynamically decide what value to use for the poll frequency.

    Application:AccelService - WebOS Internals


    I've started work on a Labyrinth game, and setting the poll frequency to 1KHZ (poll_interval = 1ms) doesn't seem to bog down the application at all. There are brief hiccups every once in a while, but I've seen those at 4HZ as well.

    Labyrinth - WebOS Internals
  15. s219's Avatar
    Posts
    498 Posts
    Global Posts
    1,008 Global Posts
    #15  
    You can easily back that down to 20-40 Hz for a labyrinth type of game and save some resources (power, etc). 1KHz is waaay overkill! But, nice work!
  16.    #16  
    Quote Originally Posted by emoney_33 View Post
    I don't know if you are keeping up with this, but changing this value does indeed work. I have also created a service for apps to use so they can dynamically decide what value to use for the poll frequency.

    Application:AccelService - WebOS Internals


    I've started work on a Labyrinth game, and setting the poll frequency to 1KHZ (poll_interval = 1ms) doesn't seem to bog down the application at all. There are brief hiccups every once in a while, but I've seen those at 4HZ as well.

    Labyrinth - WebOS Internals
    Excellent news, indeed! I've been busy with other projects lately, so I've fallen behind on developments. Although, your link appears to be broken and searching on the site doesn't reveal the app either...

    Good to know high polling rates work (1KHz is awesome!), because that's precisely what I need for the app I have in mind... Going to have to toy with this tonight.
  17.    #17  
    Quote Originally Posted by randallagordon View Post
    Although, your link appears to be broken and searching on the site doesn't reveal the app either...
    I do see the source on the git, however, so I'll snag it there. Thanks, much!
  18. #18  
    Quote Originally Posted by randallagordon View Post
    I do see the source on the git, however, so I'll snag it there. Thanks, much!

    Yes I believe webos-internals.org is down right now for upgrades. Let me know if you have trouble or need help installing the AccelService.

    Or come over to #webos-internals irc channel (freenode.net)
  19. #19  
    I installed this and opened it with pandora, the web browser, and my emailed opened at the same time . It ran great !! I can't wait to see more. Good job and thanks!

Posting Permissions