Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Compass+GPS - Part Deux

  1. #1
    Intern Newbie
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    40

    Compass+GPS - Part Deux

    Hi Folks,

    Those that read my earlier post will know I am trying to do linear interpolation on compass headings that are received from a GPS 1/second.

    The drawing is done at maybe 60 frames per second. Based on advise from zeoverlord and others I have tried to impliment this but it doesnt look quite right when it draws.

    Could someone please take a look at my code - especially the way the loop works around interpolating the course heading.

    Thanks

    -Al

    Code :
     
     
    WinMain()...
    ...<snip>....
     
    	while(!done)				// Loop That Runs While done=FALSE
    	{
    		if (PeekMessage(&amp;msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
    		{
    			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
    			{
    				done=TRUE;							// If So done=TRUE
    			}
    			else									// If Not, Deal With Window Messages
    			{
    				TranslateMessage(&amp;msg);				// Translate The Message
    				DispatchMessage(&amp;msg);				// Dispatch The Message
    			}
    		}
    		else										// If There Are No Messages
    		{
    			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
    			if (active)								// Program Active?
    			{
    				if (keys[VK_ESCAPE])				// Was ESC Pressed?
    				{
    					done=TRUE;						// ESC Signalled A Quit
    				}
    				else								// Not Time To Quit, Update Screen
    				{	tickCount = GetTickCount();
    					deltaTime = ((float)(tickCount - lastTickCount))/1000;
    					lastTickCount = tickCount;
     
    					timecounter=timecounter+deltaTime;
     
    					if (timecounter>1.0)
    					{
    						lastcourse=course;
    						GetGPSData();
    						deltacourse=(course-lastcourse);
    						courseincrement=(deltacourse/(1/deltaTime));
    						timecounter=0;
    					}
    					//course has been updated and gldraw shows this rather than incremented ver
    					lastcourse=lastcourse+courseincrement;
    					DrawGLScene();					// Draw The Scene
    					SwapBuffers(hDC);				// Swap Buffers (Double Buffering)
     
    				}
    			}
     
     
     
     
    GetGPSData()
    void GetGPSData()
    {int Code;
     char *pend;
     
        // lock data buffer
        mgcLockData(1);
        // get timestamp
        Code = mgcGetData(GPRMC_COURSE,(LPSTR)DataBuffer);
    	if(Code<0) ShowMGC32Error(Code);
     //   if(Code>0) course=(LPSTR)DataBuffer;
    	course=strtod(DataBuffer, &amp;pend);
        mgcLockData(0); // Lock Data Buffer
        Sleep(200);
     
    } /* end GetGPSData */

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: Compass+GPS - Part Deux

    This is wrong:
    Code :
    courseincrement=(deltacourse/(1/deltaTime));
    Should be:
    Code :
    courseincrement=(deltacourse/timecounter);
    Since course changed by 'deltacourse' during 'timecounter' then this is proper way of calculating how fast course is changing during one second.

    And another error:
    Code :
    lastcourse=lastcourse+courseincrement;
    Should be:
    Code :
    lastcourse=lastcourse+courseincrement*deltaTime;
    I think this one is obvious.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    Pasadena, CA, USA
    Posts
    16

    Re: Compass+GPS - Part Deux

    Aren't you calling GetGPSData only once per second (timecounter > 1.0)? I thought you said earlier the GPS provided updates at 200 ms. You ought to get every one to have a smoother display.

    Also, you call Sleep(200) in that routine. Are you trying to suspend yourself for 200 ms? This shouldn't be done here (maybe shouldn't be done at all).

    Is this a real GPS you're handling? I work in the aviation industry and we don't average heading or attitude at all from digital sources. You shouldn't get a 50 to 65 degree jump in one n to n+1 sample period. (Unless your aircraft has just been hit by a missile.)

  4. #4
    Intern Newbie
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    40

    Re: Compass+GPS - Part Deux

    Originally posted by k_szczech:
    This is wrong:
    Code :
    courseincrement=(deltacourse/(1/deltaTime));
    Should be:
    Code :
    courseincrement=(deltacourse/timecounter);
    Since course changed by 'deltacourse' during 'timecounter' then this is proper way of calculating how fast course is changing during one second.
    I dont get it? If delta course is lets say 40 degrees. And deltatime is 0.1s to draw a frame, then I know I can draw 10 frames per second.

    Therefore I want to increment the course 4 degrees at a time to get to the next heading over a 1 second interval????

    Using the same figures with your formula yields 40/0.1 = 400 for the course increment?????

    Could you please explain more?

    Ta

    -Al

  5. #5
    Intern Newbie
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    40

    Re: Compass+GPS - Part Deux

    Originally posted by k_szczech:
    And another error:
    Code :
    lastcourse=lastcourse+courseincrement;
    Should be:
    Code :
    lastcourse=lastcourse+courseincrement*deltaTime;
    I think this one is obvious.
    Again, I dont get it. Over one second you want to get from say 50 dgrees to 90 degrees. This is a delta heading of 40 degrees. If you are drawing 10 frames a second (deltatime = 0.1) then you want last course (50) to be equal to lastcourse + 4 for each frame drawn???

    Or am I missing something?

    -Al

  6. #6
    Intern Newbie
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    40

    Re: Compass+GPS - Part Deux

    I have been watching it draw the compass and it seems to draw one increment past the newheading before flicking to the new heading.....

    I might try writing some values to a log file to see whats going on.

    -Al

  7. #7
    Intern Newbie
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    40

    Re: Compass+GPS - Part Deux

    k_szczech

    Maybe it wasnt clear but time counter is not a integer counter like from 1-10. It sums a float until it gets to 1 and then repolls the gps.

  8. #8
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: Compass+GPS - Part Deux

    Seems like you have read my post with one eye closed.
    Or maybe I wasn't clear enough - to get it work properly don't put 'degrees per frame' to courseincrement - put 'degrees per second' there.

    Using the same figures with your formula yields 40/0.1 = 400 for the course increment?????
    You have put wrong data into my formula. Don't divide deltacourse by deltatime - divide it by timecounter.


    Again, I dont get it. Over one second you want to get from say 50 dgrees to 90 degrees. This is a delta heading of 40 degrees. If you are drawing 10 frames a second (deltatime = 0.1) then you want last course (50) to be equal to lastcourse + 4 for each frame drawn???
    If time between measuring 40 degrees and 90 degrees was 1 second, then according to my first formula you will get courseincrement = 40. If you render 10 frames with deltatime = 0.1 then you will add 4 degrees each frame and will end up at 90 degrees. This is exactly what you want, isn't it?

  9. #9
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: Compass+GPS - Part Deux

    And by the way - what nickn wrote is true - you could just display what you get from GPS. Smoothing will cause the display to be a bit delayed.
    And watch out for the situation when course will change from 359 to 0 - in current implementation your application will show that vehicle (aircraft?) turned left by 359 degrees.

  10. #10
    Intern Newbie
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    40

    Re: Compass+GPS - Part Deux

    I still dont get it k_szczech. Each time A frame is drawn timecounter gets slightly higher, until it reaches 1, then the program knows to poll the GPS again. Typically the program is around 60fps.

    If I divide deltacourse by timecounter, I will always be diving deltacourse by a number slightly above 1 (since this occurs inside the if >1 loop). Therefore I could end up with something like 40/1.1=36.6

    so you are saying courseincrement is now 36.6? So each time I draw a frame you want me to add 36.6 degrees to the course.

    I may just be really thick, but I dont follow?

    If you could explain for this dummie/n00b I would relly appreciate it.

    Maybe even show me how you would set the logic out?

    -Al

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •