Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Timer – constant radius turn.


Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2010, 05:57 PM
simon271 simon271 is offline
Freshman
 
Join Date: Sep 2007
Location: Sunshine Coast
Posts: 28
Default Timer – constant radius turn.


I am designing a program (VB2005 Express) that will give a predicted compass heading for a boat following a constant radius turn.
Eg. A boat doing 15knots, heading 090deg alters to 180deg on a constant radius of 0.5’. The distance covered will be 0.79’, the turn will take 3.14 min and have a rate of turn of 28.6 deg /min.
My program will have an initial and final heading input, boat speed and required radius of turn.
When the boat is at the alteration point, hit the “Execute” button and a text box will change over time to display what the boat heading should be. That way if the navigator can follow the predicted “Text box” heading on the boat, the boat should stay on the radius.
Sorry for the long winded explanation. Now for my question.
This project is going to be a good learning experience for me. I am not sure on how to go about it at this stage. A couple of “timer” posts I have looked at refer to multi threading. I don't know what that means. Because the value of the text box is changing while the timer is counting, does this require multi threading? Do I need to be looking at that sort of thing for this project? Any suggestions will be most appreciated. Thanks in advance for any help.
Reply With Quote
  #2  
Old 01-20-2010, 06:46 PM
hawkvalley1's Avatar
hawkvalley1 hawkvalley1 is offline
Centurion
 
Join Date: May 2008
Location: Denver, CO USA
Posts: 190
Default

It depends on how long the process is to collect the data - which I doubt it is very long, your just making a math equation - this should be relatively quick. To check the length of the equation surround it with this:
Code:
Dim sw As New Stopwatch
sw.Start()
' your math here...
MessageBox.Show(sw.ElapsedMilliseconds.ToString)
sw.Stop()
Reply With Quote
  #3  
Old 01-20-2010, 08:27 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is online now
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,415
Default

There are three timers in the .NET framework (more like three that Windows Forms can use; WPF adds a fourth.) Two require you to know some multithreading concepts.

System.Windows.Forms.Timer is what you'll normally find on your toolbox, and you can drag it onto your form. It raises its Tick event whenever the interval elapses, and it will never do so on an illegal thread. It's only inappropriate to use this timer if you want *very* fast intervals (< 200ms or so) or if your calculations take more than ~100ms. It doesn't sound like either of these apply, so I'd recommend using this so you don't have to know about threading.

The other two are System.Threading.Timer and System.Timers.Timer. Both have a higher resolution than System.Windows.Forms.Timer, and both raise their event on a worker thread. This is bad news for Windows Forms because you can only access controls from the UI thread; any attempt to access a control from a worker thread will at best crash the application and at worst do unpredictable things. However, since they use another thread they aren't as delicate with respect to "doesn't raise the event at precisely the time I expect". They work best when you want to do something that takes a long time on each timer tick or you need updates to be raised at very short intervals. It doesn't sound like either applies so it's not worth a discussion of the threading topics unless you just really want to talk about it.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 01-21-2010, 02:19 AM
simon271 simon271 is offline
Freshman
 
Join Date: Sep 2007
Location: Sunshine Coast
Posts: 28
Default

hi and thanks very much for the feed back and advice.
i will have a look at the things you have mentioned and see how i can progress. once again, thanks for the help.
Reply With Quote
  #5  
Old 01-22-2010, 06:59 AM
dbasnett's Avatar
dbasnett dbasnett is offline
Junior Contributor
 
Join Date: May 2005
Posts: 294
Default

I am not certain what Atma meant when he said that those two timers had better resolution, or that it matters. The following shows the problem with Timers:

Code:
Public Class Form1
    Dim stpw As New Stopwatch, tickCT As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1 '1 ms.
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs) Handles Timer1.Tick
        tickCT += 1 'count number of events
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If stpw.IsRunning Then
            Timer1.Stop()
            stpw.Stop()
            'If Timer1 fires every ms. then tickCT and  
            'stpw.ElapsedMilliseconds should be equal.
            TextBox1.Text = String.Format("Timer Ticks: {0}   Actual ms. {1}", _
                                          tickCT, stpw.ElapsedMilliseconds)
        Else
            TextBox1.Text = "" : TextBox1.Refresh()
            tickCT = 0
            Timer1.Start()
            stpw.Reset()
            stpw.Start()
        End If
    End Sub
End Class
But this should not affect you. Providing a person with updates faster than 10 times per second, if that fast, doesn't make sense, but for the calculation accuracy matters.

So use a Forms timer with a resolution of 100 ms. and a Stopwatch. The Stopwatch is far more accurate at measuring elapsed time. The timer will only be used to give the user periodic updates, and the stopwatch for the calculation.

A rough guess at what you need:

Code:
Public Class Form1
    Dim stpw As New Stopwatch
    Const degPmin As Double = 28.6
    Dim degPms As Double = degPmin / 60 / 1000
    Dim heading As Double = 15
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 250 '1/4 of a second
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs) Handles Timer1.Tick
        'calculate the new heading based on the original heading
        'plus the degrees per ms. times the total ms. from the stopwatch

        TextBox1.Text = (heading + (degPms * stpw.ElapsedMilliseconds)).ToString("N2")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If stpw.IsRunning Then
            Timer1.Stop()
            stpw.Stop()
        Else
            TextBox1.Text = "" : TextBox1.Refresh()
            Timer1.Start()
            stpw.Reset()
            stpw.Start()
        End If
    End Sub
End Class
Reply With Quote
  #6  
Old 01-22-2010, 09:17 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is online now
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,415
Default

Quote:
I am not certain what Atma meant when he said that those two timers had better resolution, or that it matters.
As the documentation states, the minimum resolution of the System.Windows.Forms.Timer is 55ms. While it's valid to set the Interval property to something small like 25ms, the timer ticks will happen roughly 55ms apart. The other two timers are presumably based off of high-performance counters and are more likely to be able to tick much more frequently.

I say "roughly" and "more likely" because for the WinForms one, the ticks have to happen on the UI thread and if the UI thread is busy doing something else then your event won't be raised until the UI thread is free. Also, since Windows is a preemptive multitasking environment, if a high-priority process is monopolizing the time slices then you're not going to get your events every 55ms either. You can't get around this without running a real-time OS that won't let multiple processes run.

Your example is flawed, and I'm not really sure what problem it's trying to demonstrate. Why is it flawed? Well, first the timer can't possibly raise an event once per millisecond. Second, raising an event takes a non-zero amount of time. So does incrementing an integer. So even if the timer could tick every 1ms, you might spend 0.25ms counting that a tick happened. That's going to throw off your count. The only thing you demonstrate is that timers don't support a resolution of 1ms, but the documentation already called that out.

I do support the notion that if the user is actually interested in a calculation that varies by real-life elapsed time, it is best to use the Stopwatch class rather than assuming the timer ticks are an accurate measure of time. Even the higher-resolution timers can't guarantee perfect timing.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #7  
Old 01-22-2010, 10:28 AM
dbasnett's Avatar
dbasnett dbasnett is offline
Junior Contributor
 
Join Date: May 2005
Posts: 294
Default

I have read the documentation, just so you know. On some machines, mine for example, it seems to be able to tick more frequently than the 55 ms(20 ms.). My sample was not flawed in that what I was showing was that an Interval of 1 didn't mean 1 ms.

Also, I strongly doubt that tickCT += 1 takes .25 ms. (my pc took 0.000600 ms.)

My real point, and it appears that we agree, is that using a stopwatch for the calculation is the best approach. In my second example I used the tick to update the UI and the stopwatch for the calculation.
Reply With Quote
  #8  
Old 01-22-2010, 07:57 PM
simon271 simon271 is offline
Freshman
 
Join Date: Sep 2007
Location: Sunshine Coast
Posts: 28
Default timer1_tick event - constant radius turn.

thanks for the feedback and examples.
i have posted what i have come up with. so far i have not been able to get the frm_pred_hdg label to update during the alteration. initially it would go from the initial to final course after the allotted time, but not change during the alteration. i made some changes last night and i don't think it does anything anymore.
i also have a few things to do regarding logic when the course changes thru 360 deg / due north.

have i got the right idea about what the tick event does?
it fires once every second - timer1.interval = 1000, so runs thru the calculation / code every second. if that is so, my pred heading label should change every second or so (bearing in mind periods of no / reduced rate of turn during alteration). the calculation rate doesnt need to be any quicker than 1 sec intervals i would think.
should i take the calculations for the turn and turn direction out of the tick event??? is the scope of the variables ok to take them out of the tick event?
perhaps the do while loop is not the best option here, maybe a select case "elapsed time". but i cant see how either of them wouldnt work equally well.


Code:
    Private Sub btn_Execute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Execute.Click
        'show the heading box
        frm_Pred_Hdg.Show()
        'only have "Predicted Heading" form visible
        Me.Visible = False
        Timer1.Enabled = True
        Timer1.Interval = 1000

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim IniCrs, FinCrs, CrsAlt, AltTime As Integer
        Dim RoT, MainRoT, VslSpd As Double
        Const Pi As Double = 3.14159265358979
        Dim StWch As New Stopwatch
        Dim ts As New TimeSpan(0, 0, 1)
        Dim TurnRad As Single

        IniCrs = CInt(lbl_InCrs.Text)                       ' deg
        FinCrs = CInt(lbl_FinalCrs.Text)                    ' deg
        CrsAlt = FinCrs - IniCrs                          ' deg
        TurnRad = CSng(txt_Radius.Text)                  ' nm
        VslSpd = CInt(txt_Spd.Text)                         ' kts
        AltTime = CInt(((Pi * 2 * TurnRad * CrsAlt) / 360) / VslSpd * 3600)        '(CrsAlt / 30 * TurnRad * Pi) / VslSpd * 60    ' sec
        RoT = CrsAlt / AltTime / 60                             ' deg / sec
        MainRoT = (CrsAlt / (0.92 * AltTime) - RoT * 0.1) / 0.8 ' deg / sec

        If CrsAlt < 0 Then
            CrsAlt = CrsAlt * -1
        End If

        'determines whether to add or subtract to heading
        'this will be to add directional coloured arrows port or stbd.
        Dim AltDir As String
        AltDir = "Port"
        If FinCrs < IniCrs Or FinCrs - IniCrs > 180 Then
            AltDir = "Port"
        End If

        If FinCrs > IniCrs Or IniCrs - FinCrs > 180 Then
            AltDir = "Stbd"
        End If

        StWch.Start()

        ts = StWch.Elapsed
        Dim elapsedTime As Integer = ts.Seconds

        'for the initial part (8% of overall alt time) of the alteration,
        'helm has no effect on heading.
        Do While elapsedTime < AltTime * 0.08
            frm_Pred_Hdg.lbl_PredHdg.Text = IniCrs.ToString
            'do i need to have the elapsed time re-calculate within the loop?????
            ts = StWch.Elapsed
            elapsedTime = ts.Seconds
        Loop

        'helm has started to take effect, vessel commences alter now, but at less than required RoT
        'work on estimated RoT/2 for next 10% of alteration
        Dim ChangingHdg As Integer

        Do While elapsedTime < AltTime * 0.18

            ChangingHdg = CInt(frm_Pred_Hdg.lbl_PredHdg.Text)
            'this event fires every second, so update the pred hdg using RoT (change of heading)
            'every second?????

            'look whether altering to port or stbd, add or subtract to total.
            If AltDir = "Port" Then
                frm_Pred_Hdg.lbl_PredHdg.Text = CStr(ChangingHdg - RoT / 2)
                'amend heading from 0 thru to 360 deg going to port
                If ChangingHdg < 0 Then
                    ChangingHdg = 360 + ChangingHdg
                End If
            Else
                'vessel altering to stbd
                frm_Pred_Hdg.lbl_PredHdg.Text = CStr(ChangingHdg + RoT / 2)
                'amend heading if it goes past 360 deg going ot stbd
                If ChangingHdg > 360 Then
                    ChangingHdg = ChangingHdg - 360
                End If
            End If

            'do i need to have the elapsed time re-calculate within the loop?????
            ts = StWch.Elapsed
            elapsedTime = ts.Seconds
        Loop

        'vessel changing course now. required rot higher than calculated to catch up after 
        'delay of helm. main body of alteration 
        Do While elapsedTime < AltTime * 0.9
            ChangingHdg = CInt(frm_Pred_Hdg.lbl_PredHdg.Text)
            'this event fires every second, so update the pred hdg using RoT (change of heading)
            'every second?????

            'look whether altering to port or stbd, add or subtract to total.
            If AltDir = "Port" Then
                frm_Pred_Hdg.lbl_PredHdg.Text = CStr(ChangingHdg - MainRoT)
                'amend heading from 0 thru to 360 deg going to port
                If ChangingHdg < 0 Then
                    ChangingHdg = 360 + ChangingHdg
                End If
            Else
                'vessel altering to stbd
                frm_Pred_Hdg.lbl_PredHdg.Text = CStr(ChangingHdg + MainRoT)
                'amend heading if it goes past 360 deg going ot stbd
                If ChangingHdg > 360 Then
                    ChangingHdg = ChangingHdg - 360
                End If
            End If

            'do i need to have the elapsed time re-calculate within the loop?????
            ts = StWch.Elapsed
            elapsedTime = ts.Seconds
        Loop

        'vessel is coming onto new course so rot is slowed for final 10% of alteraiton.

        Do Until elapsedTime > AltTime

            ChangingHdg = CInt(frm_Pred_Hdg.lbl_PredHdg.Text)
            'this event fires every second, so update the pred hdg using RoT (change of heading)
            'every second?????

            'look whether altering to port or stbd, add or subtract to total.
            If AltDir = "Port" Then
                frm_Pred_Hdg.lbl_PredHdg.Text = CStr(ChangingHdg - RoT * 3 / 5)
                'amend heading from 0 thru to 360 deg going to port
                If ChangingHdg < 0 Then
                    ChangingHdg = 360 + ChangingHdg
                End If
            Else
                'vessel altering to stbd
                frm_Pred_Hdg.lbl_PredHdg.Text = CStr(ChangingHdg + RoT * 3 / 5)
                'amend heading if it goes past 360 deg going ot stbd
                If ChangingHdg > 360 Then
                    ChangingHdg = ChangingHdg - 360
                End If
            End If

            'do i need to have the elapsed time re-calculate within the loop?????
            ts = StWch.Elapsed
            elapsedTime = ts.Seconds
        Loop

        frm_Pred_Hdg.lbl_PredHdg.Text = FinCrs.ToString

        StWch.Stop()
        Timer1.Stop()

    End Sub
any advise will be most appreciated. if i have done something really simple and stupid, i apologize in advance, but it has been a great learning experience so far.

regards, simon.
Reply With Quote
  #9  
Old 01-22-2010, 08:17 PM
simon271 simon271 is offline
Freshman
 
Join Date: Sep 2007
Location: Sunshine Coast
Posts: 28
Default

one thing i have just seen that was probably causing problems. i have taken the

StWch.Stop()
Timer1.Stop()

out of the timer_tick event.
it hasnt fixed the problem, but hopefully solved one i didnt know about yet.
Reply With Quote
  #10  
Old 01-23-2010, 07:12 AM
dbasnett's Avatar
dbasnett dbasnett is offline
Junior Contributor
 
Join Date: May 2005
Posts: 294
Default

You have missed the point. Take my second example (after "A rough guess at what you need:") and create a new form with a button, textbox, and timer. Run my code and watch what it does. I understand that my calculations are not yours.

The stopwatch was your time source. The tick event was used to make calculations and update the UI.
Reply With Quote
  #11  
Old 01-23-2010, 10:45 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is online now
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,415
Default

You've got loops in the timer tick event. This happens on the UI thread. The UI *would* update your label, but it's too busy performing the loops to update the label. Despite the illusion they provide, computers can still do only one thing at a time per thread.

dbasnett was trying to point you to an architecture more like this:
Code:
Sub Timer1_Tick()
    UpdateUI()
End Sub

Sub UpdateUI()
    Dim timeElapsed As Double = watch.ElapsedMilliseconds
    Dim currentValue As Double = CalculateCurrentHeading(timeElapsed)
    lblWhatever.Text = currentValue.ToString()
End Sub

Function CalculateCurrentHeading(ByVal timeElapsed As Double) As Double
    ' Determine what &#37; of the time has elapsed
    ' Based on that % determine the current heading
    ' Return the heading
    
    ' For example, if "heading" varies from 0 to 360 over 10 minutes:
    Dim totalInterval As Double = TimeSpan.FromMinutes(10.0).TotalMilliseconds
    Dim percent As Double = timeElapsed / totalInterval
    Dim maxHeading As Double = 360.0
    Dim currentHeading As Double = percent * maxHeading
    
    Return currentHeading
End Function
No loops, no updating intermediate values. Calculate the value for *this moment* and return it.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #12  
Old 01-23-2010, 03:42 PM
simon271 simon271 is offline
Freshman
 
Join Date: Sep 2007
Location: Sunshine Coast
Posts: 28
Default timer1_tick event - constant radius turn.

thanks for more examples to refer to.

atmaweapon: noted the point about looping in the tick event. i will change that. i need to adjust the rate of turn over time (see below for my reasoning), so i am wondering if "select case elapsed time" will work. only one way to find out.

dbasnett. i ran your example and it is exactly what i am trying to achieve, now i shall just try to incorporate the altering rate of turn over time.

i need to alter the rate of turn during the alteration because that is what happens on the boat. when the rudder is first applied at the alteration point, nothing happens instantaneously due to the straight line inertia of the vessel. the rate of turn gradually increases as time goes by, and it then becomes the navigators job to adjust the amount of rudder applied to maintain the required rate of turn. the rate of turn then slows down as counter-helm is applied to stop the boat swinging and steady up on the next course. in reality, the boat doesnt follow a perfect circle, but rather a truncated one. its not an exact science, that is for sure. when people ask me what i use as an alteration point, my usual answer is "it just feels right!!!"

i will have a look at the changes and see if i can get it to work. thanks again for your ongoing help and advise. it is much appreciated.
Reply With Quote
  #13  
Old 01-23-2010, 04:12 PM
dbasnett's Avatar
dbasnett dbasnett is offline
Junior Contributor
 
Join Date: May 2005
Posts: 294
Default

@atma - well put

@simon - if you could describe the math we might be able to help. I think it is in your post maybe.
Reply With Quote
  #14  
Old 01-23-2010, 05:20 PM
simon271 simon271 is offline
Freshman
 
Join Date: Sep 2007
Location: Sunshine Coast
Posts: 28
Default timer1_tick event - constant radius turn.

success!!!!!

i have got the predicted heading box to change over time at the altering rate of turn.

there are a few glitches and it is not the most elegant of code, but at least it works and is (sort of) doing what it is supposed to.

dbasnett: for your info. the "rough" rate of change i am working on is...
stage 1: rudder applied, no change in heading - about 8% of total alter time
stage 2: vessel starts to swing but rate of turn is not up to calculated "required" RoT. i am working on RoT/2 for next 10% of total alter time.
stage 3: vessel is swinging now. MainBodyRoT must be higher than calc RoT to catch up for sluggish start. i tried to work that out algebraically, got an answer that sort of fitted then played around in excel til i got a formula that worked most of the time....the benefits of it not being an exact science i guess!!
stage 4: vessel is approaching final heading so counter helm is applied to slow down swing and steady up on next course. i worked on RoT*3/5 for last 10% of alteration.

thanks again for all the help over the last few days. i will post once the project is complete if you are interested in looking at it...or if i run into some more problems...more likely.

Code:
Public Class frm_RoT

    Dim IniCrs, FinCrs, CrsAlt, AltTime As Integer
    Dim RoT, MainRoT, VslSpd As Double
    Const Pi As Double = 3.14159265358979
    Dim StWch As New Stopwatch
    Dim ts As New TimeSpan(0, 0, 1)
    Dim TurnRad As Single
    Dim AltDir As String

    Private Sub frm_RoT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'default values
        'opt_In.Checked = True
        txt_Radius.Text = "0.5"
        txt_Spd.Text = "15.0"

        With lbo_Beacons.Items
            .Add("NW Fwy (Sth)")
            .Add("NW Fwy (Nth)")
            .Add("NW 2 (Sth Fwy)")
            .Add("NW 2 (Nth Fwy)")
            .Add("NW 12")
            .Add("M 1")
            .Add("M 7 (Main Ch / Sth M5)")
            .Add("E 5")
            .Add("Custom")
        End With

        'set the direction to inbound on settings form.
        frm_Settings.opt_In.Checked = True

    End Sub


    Private Sub btn_Execute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Execute.Click
        'show the heading box
        ' frm_Pred_Hdg.Show()
        'only have "Predicted Heading" form visible
        '   Me.Visible = False

        IniCrs = CInt(lbl_InCrs.Text)                                           ' deg
        FinCrs = CInt(lbl_FinalCrs.Text)                                        ' deg
        CrsAlt = FinCrs - IniCrs                                                ' deg
        TurnRad = CSng(txt_Radius.Text)                                         ' nm
        VslSpd = CInt(txt_Spd.Text)                                             ' kts
        AltTime = CInt(((Pi * 2 * TurnRad * CrsAlt) / 360) / VslSpd * 3600)     ' sec
        RoT = CrsAlt / AltTime / 60                                             ' deg / sec
        MainRoT = (CrsAlt / (0.92 * AltTime) - RoT * 0.1) / 0.8                 ' deg / sec

        If CrsAlt < 0 Then
            CrsAlt = CrsAlt * -1
        End If

        'determines whether to add or subtract to heading
        'this will be to add directional coloured arrows port or stbd.
        AltDir = "Port"
        If FinCrs < IniCrs Or FinCrs - IniCrs > 180 Then
            AltDir = "Port"
        End If

        If FinCrs > IniCrs Or IniCrs - FinCrs > 180 Then
            AltDir = "Stbd"
        End If

        Timer1.Enabled = True
        Timer1.Interval = 1000

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If Not StWch.IsRunning Then
            StWch.Start()
        End If

        ts = StWch.Elapsed
        Dim elapsedTime As Integer = ts.Seconds

        Dim ChangingHdg As Integer

        Select Case elapsedTime

            Case Is < CInt(AltTime * 0.08)
                'for the initial part (8% of overall alt time) of the alteration,
                'helm has no effect on heading.
                txt_PredHdg.Text = IniCrs.ToString
                'do i need to have the elapsed time re-calculate within the loop?????
                ts = StWch.Elapsed
                elapsedTime = ts.Seconds

            Case Is < CInt(AltTime * 0.18)
                'helm has started to take effect, vessel commences alter now, but at less than required RoT
                'work on estimated RoT/2 for next 10% of alteration
                ChangingHdg = CInt(txt_PredHdg.Text)

                'look whether altering to port or stbd, add or subtract to total.
                If AltDir = "Port" Then
                    txt_PredHdg.Text = CStr(ChangingHdg - RoT / 2)
                    'amend heading from 0 thru to 360 deg going to port
                    If ChangingHdg < 0 Then
                        ChangingHdg = 360 + ChangingHdg
                    End If
                Else
                    'vessel altering to stbd
                    txt_PredHdg.Text = CStr(ChangingHdg + RoT / 2)
                    'amend heading if it goes past 360 deg going ot stbd
                    If ChangingHdg > 360 Then
                        ChangingHdg = ChangingHdg - 360
                    End If
                End If

                'do i need to have the elapsed time re-calculate within the loop?????
                ts = StWch.Elapsed
                elapsedTime = ts.Seconds

            Case Is < CInt(AltTime * 0.9)
                'vessel changing course now. required rot higher than calculated to catch up after 
                'delay of helm. main body of alteration 
                ChangingHdg = CInt(txt_PredHdg.Text)
                'this event fires every second, so update the pred hdg using RoT (change of heading)
                'every second?????

                'look whether altering to port or stbd, add or subtract to total.
                If AltDir = "Port" Then
                    txt_PredHdg.Text = CStr(ChangingHdg - MainRoT)
                    'amend heading from 0 thru to 360 deg going to port
                    If ChangingHdg < 0 Then
                        ChangingHdg = 360 + ChangingHdg
                    End If
                Else
                    'vessel altering to stbd
                    txt_PredHdg.Text = CStr(ChangingHdg + MainRoT)
                    'amend heading if it goes past 360 deg going ot stbd
                    If ChangingHdg > 360 Then
                        ChangingHdg = ChangingHdg - 360
                    End If
                End If

                'do i need to have the elapsed time re-calculate within the loop?????
                ts = StWch.Elapsed
                elapsedTime = ts.Seconds

            Case Is < CInt(AltTime)
                'vessel is coming onto new course so rot is slowed for final 10% of alteraiton.
                ChangingHdg = CInt(txt_PredHdg.Text)
                'this event fires every second, so update the pred hdg using RoT (change of heading)
                'every second?????

                'look whether altering to port or stbd, add or subtract to total.
                If AltDir = "Port" Then
                    txt_PredHdg.Text = CStr(ChangingHdg - RoT * 3 / 5)
                    'amend heading from 0 thru to 360 deg going to port
                    If ChangingHdg < 0 Then
                        ChangingHdg = 360 + ChangingHdg
                    End If
                Else
                    'vessel altering to stbd
                    txt_PredHdg.Text = CStr(ChangingHdg + RoT * 3 / 5)
                    'amend heading if it goes past 360 deg going ot stbd
                    If ChangingHdg > 360 Then
                        ChangingHdg = ChangingHdg - 360
                    End If
                End If

                'do i need to have the elapsed time re-calculate within the loop?????
                ts = StWch.Elapsed
                elapsedTime = ts.Seconds

            Case Is > CInt(AltTime)

                txt_PredHdg.Text = FinCrs.ToString

                If elapsedTime > AltTime Then
                    StWch.Stop()
                End If
                Timer1.Stop()

        End Select

    End Sub
End Class
Simon
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->