VERSION 5.00 Begin VB.Form Form1 BackColor = &H00C0FFFF& Caption = "Form1" ClientHeight = 7845 ClientLeft = 60 ClientTop = 390 ClientWidth = 11025 LinkTopic = "Form1" ScaleHeight = 7845 ScaleWidth = 11025 StartUpPosition = 3 'Windows Default End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Public inkey$ Private Sub Form_KeyPress(KeyAscii As Integer) inkey$ = Chr$(KeyAscii) End Sub Private Sub Form_Load() Show ZOrder (0) Scale (3, -2.5)-(-3, 2.5) SetFocus Print "Simulation of closed-loop system with `live input'" Print "ERROR Phase-plane is shown - velocity against position ERROR" Print "Press number keys, q to quit" Print 'INPUT "Feedback, damping (suggest 8,2 to start) "; f, d f = 8 d = 2 'VIEW (2, 20)-(638, 328), 8, 4 Line (-2.5, 0)-(2.5, 0), vbBlue Line (0, -2.5)-(0, 2.5), vbBlue Print "Press number keys 0 to 9 to change the target, q to quit" Print "Velocity versus position ERROR"; Print " Scale -2.5 to 2.5 in position and velocity"; ' dt = 0.001 'Make dt larger to speed up running x = 1 'Initial values v = 0 t = 0 Target = 0 'until a key is pressed PSet (x - Target, v) 'move to the first point Do a$ = inkey$ inkey$ = "" If a$ <> "" Then Target = 0.5 * (Val(a$) - 5) PSet (x - Target, v) End If u = f * (Target - x) - d * v 'u is determined by feedback x = x + v * dt 'This is the simulation v = v + u * dt ' t = t + dt Line -(x - Target, v) 'This displays the result DoEvents Loop Until a$ = "q" ' End End Sub