Device orientation - alpha

Posted on
  • Not specifically Espruino but hoped to pick the forums brains.

    I'm trying to use browser deviceorientation API to control an RC car running Espruino.

    I was using the beta and gamma change events so the steering would work with tilting the phone left and right of the horizontal, which I thought was fine, but on handing my phone to my youngest - he rotated it and starting to use the phone like a steering wheel. He was disappointed.

    A UI lesson learned I'm now trying to use the alpha change event, which is basically using the phones compass I think?

    So my problem/question. My problem is that steering needs to be relative to the position the phone starts in say facing 180 degrees. I can detect decrements and increments relative to that, no problem, to provide left and right events, but what if the user changes their orientation - as they might if following an RC car? The steering will start to go off. Same result if the phone starts from a angled position, my first bearing will be off so the steering will not be natural

    I hope that makes sense. Has anyone done this? Is there a better approach?

  • With compas information alone you will never get there, because you have no information how the phone is relative to the main orientation of the kid's body... whis shold not matter in the first place... never ever... Why: Because your son is not sitting in/on he car. With any conventional car remote control, the contol has two (2) components that 'turn' relative to one another and the angle between the two components is used for the control/steering inforation. If the phone is slightly tilted like any real steering wheel is for ergonomic reasons, you can use all three parameters (https://www.html5rocks.com/en/tutorials/­device/orientation/) to calculate steering information.

    (Conventional alternative is a UI on your phone display that shwos the controls - steering wheel and other controls - and responds to multi touch events... not an easy task ether)

    The other question then is: how do you control the forward / reverse speed / acceleration / deceleration.

    Wor st case your son has to let go the classic steering wheel concept and let the car behave more like a bearing ball pled on the display of the hone screen.

  • Thanks @allObjects. You are right and I think i have it sussed.

    The alpha/compass was a red herring I also came to conclusion it is not possible to use that alone. It seems the beta data will give me what I need as it still works when phone is held landscape and when tilted, I didn't cotton on to that initially.

    Re the other controls, the screen will display an SVG steering wheel. With the following controls start/stop, toot, honk (we have a buzzer as horn, which also toots when connected to wifi), and drive reverse. I'm building it as a riot.js component for easy implementation & reuse so will share when done.

    I've attached a pic showing of the WIP wheel and also attached the "new" car. Made some good progress since your help in the other thread, and it's been so easy to work on - look at all the space!


    2 Attachments

    • IMG_3087.png
    • IMG_3086.jpeg
  • Are you using Apple or Android?
    Do you have 3 axis accelerometer and 3 axis magnetometer data?

  • It's an Apple iPhone and I don't know re your second question I'm afraid - whatever the iphone has built in.

  • Obviously a great fun project...

    As a next enhancement you put in some real safety features, like reared ing prevention / a tomato emergency breaking with a distance sensor like HC-SR04 ULTRASONIC DISTANCE SENSOR...

    Be fore that you may go for just simple breaking, bei shortcutting your motor with the driver bridge or actual electro/magneto-mechanical friction breaks... ;]

  • Thanks, @ClearMemory041063 - I'll have a look at those. Appreciated!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Device orientation - alpha

Posted by Avatar for Ollie @Ollie

Actions