Device Movement using Accelerometer Reading

Hi,
I am trying to find a small movement of my Windows Phone device using Accelerometer reading.
 I got this
article which uses GPS location as the initial point and then find the direction using accelerometer reading.
I tried to implement the same, but not able to get the data. Its always "NaN". Also I followed this
article for accelerometer reading.
Please see if you can help me in this case.
Thanks
Somnath

Thanks for your reply.
Here is the code that I am using to get the distanced moved by the device. But even if the devices is stable I see accelerometer reading. I am following
this article and trying to get the speed,accelerometer,distances covered by the device, so that when I hold the device in my hand and talk a distance of 1m I should get a distance and the new coordinates also.
  static Double earthRadius = 6378D;
        String prevLatitude = "50.9847845229511";
        String prevLongitude = "37.7661668451207";
        String currentDirection = "45";
        Double initialVelocity = 0.0;
        Double prevDistanceTravelled = 0.0;
        float PrevAcceleration = 0;
        Double PrevSpeed = 0.0;
        private double _ax = 0.0;
        private double _ay = 0.0;
        private double _az = 0.0;
        private const int _num = 100;
        private double[] _x = new double[_num];
        private double[] _y = new double[_num];
        private double[] _z = new double[_num];
        private int _index = 0;
        double distanceX, distanceY, distanceZ;
        double speedX, speedY, speedZ;       private async Task<int> CalculateAccelerometerReading(AccelerometerReading reading)
            //Average of 100 Accelerometer readings
            _x[_index] = reading.AccelerationX;
            _y[_index] = reading.AccelerationY;
            _z[_index] = reading.AccelerationZ;
            _index++;
            if (_index >= _num)
                _index = 0;
            double xsum = 0.0;
            double ysum = 0.0;
            double zsum = 0.0;
            for (int i = 0; i < _num; i++)
                xsum += _x[i];
                ysum += _y[i];
                zsum += _z[i];
            double x = xsum / _num;
            double y = ysum / _num;
            double z = zsum / _num;
            if (x > 0.5)
                x = 0.5;
            else if (x < -0.5)
                x = -0.5;
            if (y > 0.5)
                y = 0.5;
            else if (y < -0.5)
                y = -0.5;
            if (z > 0.5)
                z = 0.5;
            else if (z < -0.5)
                z = -0.5;
            //Get Current Time to calculate time Travelling - In seconds
            // var secondsTravelling = 5;// date - tripStartTime;
            //  var t = 5;// secondsTravelling.TotalSeconds;
            double t = (reading.Timestamp.Ticks - _time) / 10000000.0;
            // Compute average accelerations during this time interval
            double ax = ((x * _gravity) + _ax) / 2.0;
            double ay = ((y * _gravity) + _ay) / 2.0;
            double az = ((z * _gravity) + _az) / 2.0;
            //calculare velocity
            double vx = _vx + (ax * t);
            double vy = _vy + (ay * t);
            //calculate distances
            distanceX = (initialVelocity * t) + (0.5 * ax * t * t);
            distanceY = (initialVelocity * t) + (0.5 * ay * t * t);
            distanceZ = (initialVelocity * t) + (0.5 * az * t * t);
            //calculate speed
            speedX = distanceX / t;
            speedY = distanceY / t;
            speedZ = distanceZ / t;
            //float currentAcceleration = (float)Math.Sqrt(reading.AccelerationX * reading.AccelerationX + reading.AccelerationY * reading.AccelerationY + reading.AccelerationZ * reading.AccelerationZ);
            float currentAcceleration = (float)Math.Sqrt(ax * ax + ay * ay + az * az) - PrevAcceleration;
          //  var distanceTravelled = (initialVelocity * t) + (0.5 * currentAcceleration * t * t);
            var distanceTravelled = (float)Math.Sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ);
          //  distanceTravelled = distanceTravelled / 1000;
            var finalvelocity = initialVelocity + (currentAcceleration * t);
            //var currentSpeed = distanceTravelled / t;
            var currentSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY + speedZ * speedZ);
            var oldLatitude = Double.Parse(prevLatitude);
            var oldLongitude = Double.Parse(prevLongitude);
            var direction = Double.Parse(currentDirection);
            if (distanceTravelled != prevDistanceTravelled && currentAcceleration > 0.5 && currentSpeed != PrevSpeed)
                prevDistanceTravelled = distanceTravelled;
                PrevSpeed = currentSpeed;
                PrevAcceleration = currentAcceleration;
                //Convert from Degree to Radians (For Formula)
                oldLatitude = Math.PI * oldLatitude / 180;
                oldLongitude = Math.PI * oldLongitude / 180;
                direction = Math.PI * direction / 180.0;
                //Calculate the New Longitude and Latitude
                var newLatitude = Math.Asin(Math.Sin(oldLatitude) * Math.Cos(distanceTravelled / earthRadius) + Math.Cos(oldLatitude) * Math.Sin(distanceTravelled / earthRadius) * Math.Cos(direction));
                var newLongitude = oldLongitude + Math.Atan2(Math.Sin(direction) * Math.Sin(distanceTravelled / earthRadius) * Math.Cos(oldLatitude), Math.Cos(distanceTravelled / earthRadius) - Math.Sin(oldLatitude) * Math.Sin(newLatitude));
                //Convert From Radian to degree/Decimal
                newLatitude = 180 * newLatitude / Math.PI;
                newLongitude = 180 * newLongitude / Math.PI;
                prevLatitude = newLatitude.ToString();
                prevLongitude = newLongitude.ToString();
                initialVelocity = finalvelocity;
                _time = reading.Timestamp.Ticks;
                _ax = ax;
                _ay = ay;
                _az = az;
                _vx = vx;
                _vy = vy;
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    txtlatnew.Text = newLatitude.ToString();
                    txtlngnew.Text = newLongitude.ToString();
            return 0;
It would be really nice if you could help me to fix this code.

Similar Messages

  • When ever I use Adobe reader 11 with a USB device, I cannot safe remove the USB device and get the following message (or similar one) in system log:  The application \Device\HarddiskVolume1\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe with pr

    When ever I use Adobe reader 11 with a USB device, I cannot safe remove the USB device and get the following message (or similar one) in system log:  The application \Device\HarddiskVolume1\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe with process id 6620 stopped the removal or ejection for the device USB\VID_05DC&PID_C75C\20131215015821328FC8.
    I am running on Windows Server 2012 R2 in Desktop Experience mode.
    Any ideas?
    Roger

    In addition to that symptom, I discovered that even though I had closed all Adobe Reader sessions, the processes kept running and used up 90%+ of my CPU.

  • My Mac OS X v 10.6.8 used to read mpg movie files.  Now it doesn't.  What changed and how do I correct it?

    My Mac used to read mpg as well as mp4 movie files.  Now it does not recognize the .mpg movies.  What changed & how do I correct it?

    Try using the VLC Media Player.  It's free and can play just about any kind of media file or stream you can throw at it.

  • When I rent a movie using Apple TV, it takes several hours to load and then I select watch later. When I go to my rented movies and try to watch it , it starts loading all over again. This can't be normal. Is there something that I am doing wrong?

    When I rent a movie using Apple TV,it takes several hours to load. At this point, I opt to watch later. When I try to watch the movie, it starts loading again and tells me that it will be ready to watch in one hour forty four minutes. This can't be normal. Is there something I am doing wrong? Any suggestions.

    If it's taking several hours then that is likely due to your internet connection. You can verify at speedtest.net
    6mbps required for instant 720P
    8mbps for 1080P
    You can switch to SD in the settings (which only requires 3mbps)
    You can also check istumbler or netstumbler for interference
    Make sure you are on your ISPs DNS
    The reloading is normal. There is no accessible storage on ATV. The small flash is used for caching streamed content, if you access other things or turn the device off it will be flushed.

  • How do I export a movie using a different format (iMovie 2013)

    Title question. I can only seem to export my movie using .mp4 and I've seen on youtube using previous versions of iMovie being able to change the format...
    I use a Sony DSC-HX20V to capture my footage which formats the videos in AVCHD and it records in an image quality of 50p. I want to also know how to import these videos onto a 4th generation iPod Touch and which format will support the device better. Thank You.

    Although I don't use it myself, saving to Theater creates versions for all sorts of devices including iPod Touches.
    iMovie 10 help says:
    "When you add a movie, trailer, or clip to the Theater, iMovie creates versions of your movie tailored for local playback (1080p HD), playback on an iOS device (720p HD), and web streaming (480p SD)."
    Geoff.

  • Can I link a chain of airport express devices to use as wifi extenders?

    Hi all,
    At work we have a large warehouse, office at one end, offices at the other end and warehousing in the middle (to keep things simple) .  I would like one single wifi network for the whole building so I can link up Filemaker to iPads, iPhones, Macbooks etc.  I have bought two Airport Express devices and put them at two ends of the building but they don't reach each other so I've temporarily set up two wifi networks.  I will need a 3rd, maybe even 4th Airport Express.
    My question is this:
    Can I form a chain of airport express devices to use as wifi repeaters from the first?  i.e. Can a repeated wifi signal be repeated again?
    Or in other words... say I have 4 airport express devices (A, B, C, D) and only A is linked to the network with a cable...B repeats the signal from A. (A is out of reach of C and D).  B repeats the wifi signal from A to C...C repeats the wifi signal to D...will this work/is it possible?
    Thanks!
    p.s. hopefully I haven't confused you too much

    Hi - Tesserax is right - you can't do this wirelessly but I notice that you say that you have temporarily set up two wi-fi networks - does this mean that you have access to ethernet connections - if you do and the distances aren't too long, then you can do it by placing wired base stations where their wi-fi would overlap - you would then set up each to create a wireless network with the same name, password and security type - and as long as they are on the same subnet, you would have a roaming network so that clients can move from one "zone" to the next without having to re-connect - I have 2 parallel networks using 8 Extremes and 2 Expresses connecting 3 hangars and 3 offices and it works great.

  • HT204291 Airplay on Mac prevents other devices from using airplay

    I have successfully connected my mid 2011 Mac mini to my 3rd gen Apple TV to allow for extended desktop on Mavericks. The problem is after I have disconnected Apple TV from the Mac mini and turned off airplay features, the Apple TV stays connected to the Mac mini, causing the Apple TV to turn on and stay on, even when the Mac mini is asleep. I have also just found out that this unwanted connection prevents my other iOS devices from using Airplay with Apple TV. The device will connect momentarily the then be kicked off with the Apple TV showing that it's "playing" an "Untitled" track from "Internet radio". At the time of this incident, the Mac mini was on sleep mode. This problem was resolved when I shut down the Mac mini.
    What is causing this unwanted connection and how can I be able to use Airplay from devices without having to shut down my Mac mini?

    Thank you for the quick reply HACKINT0SH. But it does not solve anything.
    When i move the iMac to the first floor and connect trough wifi it works. When I move the device back to the cellar then it works via LAN for a day or so... After some time the Airplay Icon is just gone
    It seems that the Mac is not searching anymore for AirPlay devices or the broadcasts goes nuts.
    Is there any way to search manually for AirPlay devices?

  • Error in updating 311 movement using BAPI_GOODSMVT_CREATE

    Hi All,
    I need hlep to understand the problem in doing a transfer.
    SAP MII is doing a 311 type movement using BAPI_GOODSMVT_CREATE. BAPI is returning the response back to MII. Once the BAPI is commited it shall make transfer inside SAP. But it does not reflect the movement while checking under HUMO.
    under SM13 it say " SSFCOMPOSER 323"  error in address output (name not filled)
    MII is getting this reponse back as a result of BAPI execution.
    <?xml version="1.0" encoding="UTF-8"?>
    <BAPI_GOODSMVT_CREATE>
    <INPUT><GOODSMVT_CODE><GM_CODE>04</GM_CODE></GOODSMVT_CODE><GOODSMVT_HEADER><PSTNG_DATE>2010-07-03</PSTNG_DATE><DOC_DATE>2010-07-03</DOC_DATE><REF_DOC_NO/><BILL_OF_LADING/><GR_GI_SLIP_NO/><PR_UNAME/><HEADER_TXT/><VER_GR_GI_SLIP/><VER_GR_GI_SLIPX/><EXT_WMS/><REF_DOC_NO_LONG/><BILL_OF_LADING_LONG/><BAR_CODE/></GOODSMVT_HEADER><GOODSMVT_REF_EWM><REF_DOC_EWM/><LOGSYS/><GTS_SCRAP_NO/></GOODSMVT_REF_EWM><TESTRUN/></INPUT>
    <OUTPUT><GOODSMVT_HEADRET><MAT_DOC/><DOC_YEAR>0000</DOC_YEAR></GOODSMVT_HEADRET><MATDOCUMENTYEAR>0000</MATDOCUMENTYEAR><MATERIALDOCUMENT/></OUTPUT>
    <TABLES><EXTENSIONIN/><GOODSMVT_ITEM><item><MATERIAL>130116</MATERIAL><PLANT>2715</PLANT><STGE_LOC>LINE</STGE_LOC><BATCH>96</BATCH><MOVE_TYPE>311</MOVE_TYPE><STCK_TYPE/><SPEC_STOCK/><VENDOR/><CUSTOMER/><SALES_ORD/><S_ORD_ITEM>000000</S_ORD_ITEM><SCHED_LINE>0000</SCHED_LINE><VAL_TYPE/><ENTRY_QNT>96.000</ENTRY_QNT><ENTRY_UOM/><ENTRY_UOM_ISO/><PO_PR_QNT>0</PO_PR_QNT><ORDERPR_UN/><ORDERPR_UN_ISO/><PO_NUMBER/><PO_ITEM>00000</PO_ITEM><SHIPPING/><COMP_SHIP/><NO_MORE_GR/><ITEM_TEXT/><GR_RCPT/><UNLOAD_PT/><COSTCENTER/><ORDERID/><ORDER_ITNO>0000</ORDER_ITNO><CALC_MOTIVE/><ASSET_NO/><SUB_NUMBER/><RESERV_NO>0000000000</RESERV_NO><RES_ITEM>0000</RES_ITEM><RES_TYPE/><WITHDRAWN/><MOVE_MAT/><MOVE_PLANT>2715</MOVE_PLANT><MOVE_STLOC>J01</MOVE_STLOC><MOVE_BATCH>96</MOVE_BATCH><MOVE_VAL_TYPE/><MVT_IND/><MOVE_REAS>0000</MOVE_REAS><RL_EST_KEY/><REF_DATE>0000-00-00</REF_DATE><COST_OBJ/><PROFIT_SEGM_NO>0000000000</PROFIT_SEGM_NO><PROFIT_CTR/><WBS_ELEM/><NETWORK/><ACTIVITY/><PART_ACCT/><AMOUNT_LC>0</AMOUNT_LC><AMOUNT_SV>0</AMOUNT_SV><REF_DOC_YR>0000</REF_DOC_YR><REF_DOC/><REF_DOC_IT>0000</REF_DOC_IT><EXPIRYDATE>0000-00-00</EXPIRYDATE><PROD_DATE>0000-00-00</PROD_DATE><FUND/><FUNDS_CTR/><CMMT_ITEM/><VAL_SALES_ORD/><VAL_S_ORD_ITEM>000000</VAL_S_ORD_ITEM><VAL_WBS_ELEM/><GL_ACCOUNT/><IND_PROPOSE_QUANX/><XSTOB/><EAN_UPC/><DELIV_NUMB_TO_SEARCH/><DELIV_ITEM_TO_SEARCH>000000</DELIV_ITEM_TO_SEARCH><SERIALNO_AUTO_NUMBERASSIGNMENT/><VENDRBATCH/><STGE_TYPE/><STGE_BIN/><SU_PL_STCK_1>0</SU_PL_STCK_1><ST_UN_QTYY_1>0</ST_UN_QTYY_1><ST_UN_QTYY_1_ISO/><UNITTYPE_1/><SU_PL_STCK_2>0</SU_PL_STCK_2><ST_UN_QTYY_2>0</ST_UN_QTYY_2><ST_UN_QTYY_2_ISO/><UNITTYPE_2/><STGE_TYPE_PC/><STGE_BIN_PC/><NO_PST_CHGNT/><GR_NUMBER/><STGE_TYPE_ST/><STGE_BIN_ST/><MATDOC_TR_CANCEL/><MATITEM_TR_CANCEL>0000</MATITEM_TR_CANCEL><MATYEAR_TR_CANCEL>0000</MATYEAR_TR_CANCEL><NO_TRANSFER_REQ/><CO_BUSPROC/><ACTTYPE/><SUPPL_VEND/><MATERIAL_EXTERNAL/><MATERIAL_GUID/><MATERIAL_VERSION/><MOVE_MAT_EXTERNAL/><MOVE_MAT_GUID/><MOVE_MAT_VERSION/><FUNC_AREA/><TR_PART_BA/><PAR_COMPCO/><DELIV_NUMB/><DELIV_ITEM>000000</DELIV_ITEM><NB_SLIPS>000</NB_SLIPS><NB_SLIPSX/><GR_RCPTX/><UNLOAD_PTX/><SPEC_MVMT/><GRANT_NBR/><CMMT_ITEM_LONG/><FUNC_AREA_LONG/><LINE_ID>000000</LINE_ID><PARENT_ID>000000</PARENT_ID><LINE_DEPTH>00</LINE_DEPTH><QUANTITY>0</QUANTITY><BASE_UOM/><LONGNUM/></item></GOODSMVT_ITEM><GOODSMVT_SERIALNUMBER/><GOODSMVT_SERV_PART_DATA><item><LINE_ID>000000</LINE_ID><RET_AUTH_NUMBER/><DELIV_NUMBER/><DELIV_ITEM>000000</DELIV_ITEM><HU_NUMBER>115934300024</HU_NUMBER><INSPOUT_GUID/><EVENT/><DATE>0000-00-00</DATE><TIME>00:00:00</TIME><ZONLO/><TIMESTAMP>0</TIMESTAMP><SCRAP_INDICATOR/><KEEP_QUANTITY>0</KEEP_QUANTITY><GTS_STOCK_TYPE/><MOVE_GTS_STOCK_TYPE/></item></GOODSMVT_SERV_PART_DATA><RETURN><item><TYPE>S</TYPE><ID>L9</ID><NUMBER>514</NUMBER><MESSAGE>Delivery 80817129 created</MESSAGE><LOG_NO/><LOG_MSG_NO>000000</LOG_MSG_NO><MESSAGE_V1>80817129</MESSAGE_V1><MESSAGE_V2/><MESSAGE_V3/><MESSAGE_V4/><PARAMETER>GOODSMVT_HEADER</PARAMETER><ROW>0</ROW><FIELD/><SYSTEM>SP1330</SYSTEM></item></RETURN></TABLES>
    </BAPI_GOODSMVT_CREATE>

    PL Stock in transit exceeded by 200 UNT : 10000000125 3065 0005"
    the code does not matter, it is the process and the stock situation that does not allow the creation of the movement.
    you cannot receive e.g. 200 from in-transit stock  if you only have nothing in transit.
    First the goods issue has to be  performed in the shipping plant.

  • Since the iOS7.0.2 update to my iPhone 4S, I can no longer choose use of my Bluetooth device if using the power cord to listen to MUSIC or answer my phone (choice of powercord as 'dock,' speaker,

    Since the iOS7.0.2 update to my iPhone 4S, I can no longer choose use of my Bluetooth device if using the power cord to listen to MUSIC or answer my phone (choice of powercord as 'dock,' speaker, & phone only).  Was this former-feature now an oversight??  I'd really appreciate having my Bluetooth once again listed as a choice of  audio option.  Especially considering the battery life is not what it was prior to this update, and requires recharging often.

    Sorry to tell you but unless you have a Retail Apple Store close by, they are the only ones I have found with all the adapters and accessories. I bought an extra lightning to usb adapter the other day to use in my truck. Good luck....

  • We have a router at home supposed to support 10 devices but when i try to connect my mac book pro it says another device is using your computer's ip address

    we have a router at home that is supposed to support 10 devices but when i try to connect my mac book pro it says another device is using my computer's ip address

    Are the IP addresses statically assigned (wrong ), or does the router give them out using DHCP (right )?

  • I have a wireless network at home. I run my iphone and ipad on it with no problems. Just purchased a MacBook Pro, and now my wi-fi keeps disconnecting and i get an error message saying another device is using the same IP address. What does all this mean?

    I have a wireless network at home. I run my iphone and ipad on it with no problems. Just purchased a MacBook Pro, and now my wi-fi keeps disconnecting and i get an error message saying another device is using the same IP address. What does all this mean?

    Hello AKCamus
    To give you some ideas of what to do next, I have provided a few articles that will give some troubleshooting Wi-Fi connections and recommended Wi-Fi settings.
    iOS and OS X: Recommended settings for Wi-Fi routers and access points
    http://support.apple.com/kb/HT4199
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/ts1398
    Troubleshooting Wi-Fi issues in OS X Lion and Mac OS X v10.6
    http://support.apple.com/kb/HT4628
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • Issue with web links in PDF document using adobe reader 10.1.1

    Hi,
    We are creating the PDF documents that contains website links. The problem that is occurring is whenever we click on the website links in the pdf file, it opens up IE browser but just show connecting message without actually showing the link and its content. This is ocuurring when we open the PDF using adobe reader 10.1.1 . However it seems to be working fine with Adobe reader 9 . Moreover the length of the URL is bit large and seems like links work fine when we have 253 characters in the URL and if they are more than that then it is not working.Since it is working fine in Adobe reader 9 is there any constraint imposed on the length of URL with adobe reader 10.1.1 . Anything regarding this will be of great help.

    Hi..
    Try removing a plugin...
    Quit Safari.
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type this exactly as you see it here:
    /Library/Internet Plug-Ins
    Move the Adobe PDF Browser plugin (or just PDF Browser plugin) from the Internet Plug-Ins folder to the Trash.
    Relaunch Safari to test.

  • Can I have one itunes account, but have two devices that used different email accounts?

    I have an iPad2 and want to buy an iPod Touch for my daughter.  I want it to use her email address, but use my itunes account.  Can that be done?

    The Apple/iTunes ID (which is a email address) is seperate from any mail accounts yu have on the iPod/iPad.  Both devices can use the same Apple/iTunes ID but have different email address for the mail accounts on the devices.

  • HT3819 If I have to load the same apple id on all devices to use home share, does that preclude each device from using a second apple id and does that constitute a separate Itunes db or something?

    If I have to load the same apple id on all devices to use home share, does that preclude each device from using a second apple id and does that constitute a separate Itunes db or something?

    Welcome to the Apple community.
    Only one of your libraries needs to use your iTunes Store Apple ID for home sharing. Your other computers can use their own ID for iTunes, so long as they use the same ID as all of the devices on the network for home sharing.

  • Is it possible to change the Apple id on one device while keeping all purchases and apps? Also, several other devices are using the same apple Id.

    There are about 3 devices that use the same apple id. I would like to take my iphone and make my own apple id but I don't want to lose all the purchases that were made on the original apple id

    You can sign out and sign in with the new ID. The old purchases wont go away.

Maybe you are looking for