VERSION 5.00 Begin VB.Form Form1 BackColor = &H00C0FFFF& Caption = "Form1" ClientHeight = 7710 ClientLeft = 60 ClientTop = 390 ClientWidth = 11130 LinkTopic = "Form1" ScaleHeight = 7710 ScaleWidth = 11130 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() 'Screen 12 Show Cls f = 2 'feedback d = 2 'damping Form1.Scale (-40, 10)-(40, -10) Line (-40, 0)-(40, 0), vbBlue Line (0, -10)-(0, 10), vbBlue Form1.SetFocus Print "Simulation of closed-loop system with `live input'" Print "Phase-plane is shown - velocity against position" Print Print "Press number keys 0 to 9 to change the target, q to quit" ' dt = 0.05 'Make dt larger to speed up running b = 0.1 x = 40 'Initial values v = 0 t = 0 Target = 0 'until a key is pressed PSet (x, v) 'move to the first point Do a$ = inkey$ inkey$ = "" If a$ <> "" Then Target = 4 * Val(a$) - 20 u = f * (Target - x) - d * v 'u is determined by feedback x = x + v * dt 'This is the simulation v = v + b * u * dt ' t = t + dt Line -(x, v) 'This displays the result DoEvents Loop Until a$ = "q" End ' End Sub