gps and needle

tufanv

Expert
Licensed User
Longtime User
First of all i am a new a user hello to all :eek:

I have a problem. With using gps location speed i have created a speedometer. In the code I have arranged the needle to turn to corresponding speed with
Angle = (lblSpeed.text) Mod 360
When i try the app in my car the speed is correctly shown by the angle of needle BUT the needle goes to every speed directly but i want it to move like the real cars speedometer that needle goes to new speed by transition ( sorry for bad english , i want needle not to go directly to new speed for example from 40 to 48 when location changed , i want it to go from 40 to 48 with passing 41,41,43 .. )

How can i do that ?
TIA
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Welcome!

I guess that you mean azmiuth or direction, not speed.

1. You should use a timer to update the compass.
2. On each Tick you should calculate the direction with this formula:
Direction = PreviousValue + (NewValue - PreviousValue) / Constant

You should play with the Constant value and the timer interval
3. Set PreviousValue = Direction
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I mean speed ,as in gps tutorial i can get the speed from gps , and with that speed i created a speedometer with indicator sign , i want the sign to rotate to correspanding speed on speedometer.
Can I do this whit what you sugessted in your previous message ?

Thanks
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Working on direction for 2 days but couldnt manage to do it.

the code where i get the speed is

Sub GPS_LocationChanged (Location1 As Location)
lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
lblSpeed.Text = Round(3.6 * (Location1.Speed))
Timer1_Tick

End Sub

This is the timer1_tick

Sub Timer1_Tick
Dim Angle1 As Float


Angle1 =Angle
Angle = (lblSpeed.text) + 231 Mod 360 ( +231 is to set the speed to corresponding angle for the true speed on speedometer)

csvNeedle.DrawRectRotated(DRectNeedle,Colors.Transparent,True,1,Angle1)
csvNeedle.DrawBitmapRotated(bmpNeedle,SRectNeedle,DRectNeedle,Angle)
imvNeedle.Invalidate2(DRectCompass)


Here i added the direction like this :

dim direction as float
direction = angle1 + ( angle - angle1 ) / 5
Angle1 = Direction

But this is resulted with the same movement of needle ( not continuos but on every speed change ) and also this draws multiple needles on the speedometer

any ideas ? TIA
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
You could try and use an array to get an average of your speed and use the average on your display. If you had a 5 or 10 value array that was updated every second, shuffle values up one and put in new value add them up and divide by the array size. So if you have been steady at 40 the average will be 40 if the speed now jumps up to 48 the average will be (40+40+40+40+48)/5 = 41.6 if the speed stays at 48 the average over the next 4 counts will be 43.2, 44.8, 46.4 & 48. The larger the array the slower the move but the response of also more sluggish.

Sent from my HTC One X using Tapatalk 2
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Yes , I had enabled the timer but didnt work for me.

I changed tthe code a bit. Now i calculate the difference between new speed and old speed and get the acceleration or slowing of the car. Now the thing i want to do is : If the difference between new and old speed ( which i get the data under locationchanged sub with location1.speed) is +12 (accelaration), i want to rotate the needle 12 times NOT DIRECTLY like Angle = Angle + 12 but i want 12 times to draw the needle with angle = angle + 1 ( if the car was slowing it had to be angle = angle - 1 but i am now supposing that it is accelerating). Which method do i have to use to do it like angle = angle + 1 ( 12 times, so that the needle doesnt directly go to angle + 12 but it slowly goes up ) I tried loop functions but couldnt manage to do it.

TY
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I want to put it as zip but i changed the code too much because i couldnt manage to do what i said above that you wont understand anything :) i will start from the begening. I hope i wil find a way to do what I had explained in previous post :)
 
Upvote 0
Top