| |
TeachIn with Industry Robots : easy
Nice, complicated and large program you will some on this site, but this is a
simple one. It works like a greater one and is easy to do. This is a Visual
Basic version : step by step.
- What you need for it :
+ Visual Basic 6.
+ An fischertechnik Industry Robot : Rob3 or Rob4.
+ An fischertechnik interface (parallel (universal) or serial (Intelligent))
+ An simple analogous JoyStick with X- and Y-Axis and four buttons.
or alternatively use mouse and num. keyboard.
+ The FishFa50.OCX.
- Starting the VB6 Project
+ A new standard project with a simple form
+ Mark FishFace Control 5.0 (FishFa50.OCX) in project | components. If
you can't find it : click to search an mark it in the file list (should
be in \Windows\System bzw. \WinNT\System32).
+ place the controls FishFace and FishJoy / FishKey on the form and neme
them ft and jy /ky.
+ In addition some more buttons and labels are requested, look for tips
later on.
- Global data
Option Explicit
Dim PortName$
Dim Takte(1 To 100, 1 To 4) As Long, TaktAnz&
The array Takte (steps) contains the robot positions noted during
the teachin. TaktAnz = number of steps
- Initialize
Private Sub Form_Load()
With ft.MotCntl
.Name(1) = "Säule"
.EndPosition(1) = 240
.Name(2) = "ArmHorizontal"
.EndPosition(2) = 140
.Name(3) = "ArmVertikal"
.EndPosition(3) = 112
.Name(4) = "Greifer"
.EndPosition(4) = 26
End With
TaktClear
End Sub
The object ft.MotCntl (part of FishFa50) contains a compressed
description of the robot. Only the entries are listed which are not
default. That are Name of the robot component, number of impulses the
component can move off from the end switch (noted are the values for
Rob3). The end switches are 1, 3, 5, 7 and the impulse switches are 2,
4, 6, 8, the motors are 1 - 4. The motors should be connect in a manner
to run to the end switch if clicke on L on the InterfacePanel
(ft.ShowPanel or stand alone program). TaktClear sets the array Takte to
their start values.
- Starting the Interface
Done with button cmdAction (Caption : START) place it on the
form. cmdAction_Click :
If ft.OpenInterface("COM1") = ftifehler Then
MsgBox "Interface-Problem", vbCritical + vbOKOnly,_ App.ProductName
Exit Sub
End If
Connection to the interface ("COM1" change it if there
is an other). If OpenInterface fails sub is exited with a message.
From here only the joystick version is described, the keyboard version
is nearly the same. Both versions are to be found with the FishFa50
samples.
- Conneting the JoyStick
Set jy.FishFaceControl = ft
Connects the base control ft (FishFace) and the joystick control
jy (FishJoy). Operating the joystick will drive the robot (one component
each time).
- Drive to Home position
ft.MoveHome
That means all components of the robot will go simultaneously to
there appropriate end switch.
- Activate the joystick
jy.StartJoy
Starts an internal timer which polls (ft.ControlInterval) the
joystick positions. Motors are started and stopped in accordance
to the joystick position.
- Preserving of robot positions
Private Sub cmdAdd_Click()
TaktAdd
End Sub
A new buton Speichern (Store : cmdAdd_Click) add the actual
position to the array Takte on position TaktAnz (it will be
incremented).
Private Sub TaktAdd()
If TaktAnz > UBound(Takte) Then Exit Sub
TaktAnz = TaktAnz + 1
Takte(TaktAnz, 1) = ft.MotCntl.Position(1)
Takte(TaktAnz, 2) = ft.MotCntl.Position(2)
Takte(TaktAnz, 3) = ft.MotCntl.Position(3)
Takte(TaktAnz, 4) = ft.MotCntl.Position(4)
lblTaktAkt = TaktAnz
End Sub
The actual value of TaktAnz (number of steps) is displayed in
Label lblTaktAkt. Steps only can be added at the end of the array.
- Clear the Takte array
Private Sub TaktClear()
TaktAnz = 1
Takte(1, 1) = 0
Takte(1, 2) = 0
Takte(1, 3) = 0
Takte(1, 4) = 0
lblTaktAkt = TaktAnz
End Sub
The values 0 represent the home position as well.
Call it with the new Button Löschen (Clear) (cmdClear_Click)
Private Sub cmdClear_Click()
TaktClear
End Sub
- Running to the learned positions
Private Sub cmdRun_Click()
Dim i&
ft.NotHalt = False
For i = 1 To TaktAnz
If ft.MoveTo(Takte(i, 1), Takte(i, 2), Takte(i, 3), Takte(i, 4)) _
= ftifehler Then Exit Sub
lblTaktAkt = i
Next i
End Sub
Start it with the new button Run (cmdRun_Click). ft.NotHalt is
set to false to clear a pending end request. In For Next loop the method
ft.MoveTo fetched the actual position values from the Takt array an runs
it. If an error happens ore a manual ending request occurs (e.g.
ESC.Key) the sub ends.
That is (nearly all).
- The End
Private Sub cmdHalt_Click()
jy.StopJoy
ft.NotHalt = True
cmdHalt.Enabled = False
cmdEnde.Enabled = True
End Sub
The new button HALT ends the joystick mode, rises an ending
request and some button are enabled again. It is essential to end the
program completely, otherwise only the form is unloaded but the loop is
working always in the background.
- And : some additional display
Private Sub PositionAkt()
lblPos(0) = ft.MotCntl.Position(1)
lblPos(1) = ft.MotCntl.Position(2)
lblPos(2) = ft.MotCntl.Position(3)
lblPos(3) = ft.MotCntl.Position(4)
End Sub
Private Sub ft_OnFishPosition()
PositionAkt
End Sub
Private Sub jy_OnJoyPosition()
PositionAkt
End Sub
The Sub PositionenAkt displays the actual position of the robot
components counted in impulses. In is done with the event routines
ft_OnFishPosition(FishFace) and jy_OnJoyPosition(FishJoy).
Now we are complete and you can start to a greater, nicer and more
complicated own program. |