VBA : Radar

ftComputing : Programme für die fischertechnik-Interfaces und -konstruktionskästen
  
ftComputing.de
Home
Back
Sitemap
Index
Links
Impressum
Mail
 

Scan der Umgebung mit ROBO TX und Excel VBA

Drehkranz angetrieben durch Motor an M1 mit Endtaster an I1 und Impulstaster an C1. UltraschallSensor (ersatzweise auch Photowiderstand) an I8, sowie rote Lampe an O3

Programm RadarTurm :
Der Turm oszilliert zwischen Position 0 und 100. Dabei wird alle 10 Impulse der am Ultraschallsensor gemessene Abstandswert in cm ausgegeben. Bei Unterschreiten einer vorgegebenen Distanz wird die rote Lampe eingeschaltet.

 

Programm RadarTurm Fall :

Private tx As New FishFace50

Private Const mTurm        = 1
Private Const sFull        = 512
Private Const dLinks       = 1
Private Const dRechts      = 2
Private Const dAus         = 0
Private Const oLampe       = 3
Private Const cImpuls      = 1
Private Const iEndtaster   = 1
Private Const iDistance    = 8
Private Const Schrittweite = 10
Private Const DistLimit    = 16

Private Sub cmdAction_Click()
  Dim res, i As Long
  res = tx.OpenController(39)
  If res <> 0 Then
    lblStatus = "FAILED"
    Exit Sub
  End If
  tx.SetMotor mTurm, dLinks
  tx.WaitForInput iEndtaster
  tx.SetMotor mTurm, dAus
  Do
    For i = 0 To 100 Step Schrittweite
      Distance dRechts, i
    Next
    For i = 100 To 0 Step -Schrittweite
      Distance dLinks, i
    Next
  Loop Until tx.Finish()
  tx.CloseController
  lblStatus = "--- FINIS ---"
End Sub

Private Sub Distance(ByVal turn&, ByVal pos&)
  Dim dist, diff As Long
  If tx.Finish() Then Exit Sub
  dist = tx.GetDistance(iDistance)
  If dist < DistLimit Then
    tx.SetLamp oLampe, True
  Else
    tx.SetLamp oLampe, False
  End If
  lblStatus = "Position : " & pos & " Distanz : " & dist
  DoEvents
  tx.StartRobMotor mTurm, turn, sFull, Schrittweite
  diff = tx.WaitForMotor(mTurm)
  lblHinweise = "Abweichung : " & diff
End Sub

Anmerkungen : 
- cmdAction : Herstellen der Verbindung zum TX Controller an COM39 (auf eigenen Wert ändern)
- Anfahren der Home-Position linksdrehend
- Drehen um Schrittweite nach rechts, Anzeige der aktuellen Position und der festgestellten Entfernung
   in Sub Distance
- Zurückdrehen in Schrittweite.
- Beenden durch ESC-Taste 

Download 

Sources enthalten in FishFaceVBA.ZIP

Weitere Radartürme sind auf radar.htm und radarex.htm zu bewundern.

Stand : 29.08.2010