Need help in vb6 programming

I am using AL5A robot arm. This arm is controlled using VB6. The problem that i am facing now is the robot arm reacts very slow with the coding and i think there is some problem in my coding. here is my coding :

[code]Dim RobotPos(5) As Integer
Dim RobotPoint(5, 20) As Integer
Dim RobotStatus(5) As Integer

Private Sub Command1_Click()
load
End Sub

Private Sub Command2_Click()
fail
End Sub

Private Sub Command3_Click()
pass
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 7
MSComm1.Settings = “115200,N,8,1”
MSComm1.PortOpen = True
RobotPos(0) = 127
RobotPos(1) = 127
RobotPos(2) = 127
RobotPos(3) = 127
RobotPos(4) = 127
RobotPos(5) = 127
End Sub

Private Sub fail()
Static N As Integer
Static M As Integer

RobotPoint(0, 0) = 127
RobotPoint(1, 0) = 180
RobotPoint(2, 0) = 180
RobotPoint(3, 0) = 210
RobotPoint(4, 0) = 140
RobotPoint(5, 0) = 10

RobotPoint(0, 1) = 120
RobotPoint(1, 1) = 56
RobotPoint(2, 1) = 91
RobotPoint(3, 1) = 180
RobotPoint(4, 1) = 160
RobotPoint(5, 1) = 10

RobotPoint(0, 2) = 120
RobotPoint(1, 2) = 30
RobotPoint(2, 2) = 53
RobotPoint(3, 2) = 171
RobotPoint(4, 2) = 160
RobotPoint(5, 2) = 100

RobotPoint(0, 3) = 120
RobotPoint(1, 3) = 30
RobotPoint(2, 3) = 53
RobotPoint(3, 3) = 161
RobotPoint(4, 3) = 110
RobotPoint(5, 3) = 100

RobotPoint(0, 4) = 120
RobotPoint(1, 4) = 60
RobotPoint(2, 4) = 63
RobotPoint(3, 4) = 140
RobotPoint(4, 4) = 110
RobotPoint(5, 4) = 10

RobotPoint(0, 5) = 120
RobotPoint(1, 5) = 150
RobotPoint(2, 5) = 150
RobotPoint(3, 5) = 140
RobotPoint(4, 5) = 110
RobotPoint(5, 5) = 10

RobotPoint(0, 6) = 210
RobotPoint(1, 6) = 180
RobotPoint(2, 6) = 180
RobotPoint(3, 6) = 140
RobotPoint(4, 6) = 110
RobotPoint(5, 6) = 1

RobotPoint(0, 7) = 210
RobotPoint(1, 7) = 68
RobotPoint(2, 7) = 180
RobotPoint(3, 7) = 247
RobotPoint(4, 7) = 110
RobotPoint(5, 7) = 1

RobotPoint(0, 8) = 210
RobotPoint(1, 8) = 68
RobotPoint(2, 8) = 180
RobotPoint(3, 8) = 238
RobotPoint(4, 8) = 160
RobotPoint(5, 8) = 10

RobotPoint(0, 9) = 210
RobotPoint(1, 9) = 170
RobotPoint(2, 9) = 180
RobotPoint(3, 9) = 140
RobotPoint(4, 9) = 160
RobotPoint(5, 9) = 10

RobotPoint(0, 10) = 131
RobotPoint(1, 10) = 180
RobotPoint(2, 10) = 180
RobotPoint(3, 10) = 105
RobotPoint(4, 10) = 160
RobotPoint(5, 10) = 10

RobotPoint(0, 11) = 130
RobotPoint(1, 11) = 180
RobotPoint(2, 11) = 180
RobotPoint(3, 11) = 100
RobotPoint(4, 11) = 160
RobotPoint(5, 11) = 10

M = 0
Do While (M < 12)
DoEvents
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
For g = 1 To RobotPoint(5, M)
DoEvents
Next g
If RobotPos(N) > RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) - 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) + 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
RobotStatus(N) = True
End If

N = N + 1
If N > 5 Then
If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) And (RobotStatus(5)) Then
M = M + 1
’ If M > 11 Then Exit Sub
End If
N = 0

End If
Loop

End Sub
Private Sub load()
Static N As Integer
Static M As Integer

RobotPoint(0, 0) = 120
RobotPoint(1, 0) = 100
RobotPoint(2, 0) = 180
RobotPoint(3, 0) = 200
RobotPoint(4, 0) = 150
RobotPoint(5, 0) = 50

RobotPoint(0, 1) = 120
RobotPoint(1, 1) = 76
RobotPoint(2, 1) = 91
RobotPoint(3, 1) = 180
RobotPoint(4, 1) = 170
RobotPoint(5, 1) = 70

RobotPoint(0, 2) = 120
RobotPoint(1, 2) = 30
RobotPoint(2, 2) = 53
RobotPoint(3, 2) = 171
RobotPoint(4, 2) = 160
RobotPoint(5, 2) = 100

RobotPoint(0, 3) = 120
RobotPoint(1, 3) = 30
RobotPoint(2, 3) = 53
RobotPoint(3, 3) = 161
RobotPoint(4, 3) = 110
RobotPoint(5, 3) = 100

RobotPoint(0, 4) = 120
RobotPoint(1, 4) = 60
RobotPoint(2, 4) = 63
RobotPoint(3, 4) = 140
RobotPoint(4, 4) = 110
RobotPoint(5, 4) = 10

RobotPoint(0, 5) = 130
RobotPoint(1, 5) = 150
RobotPoint(2, 5) = 150
RobotPoint(3, 5) = 160
RobotPoint(4, 5) = 110
RobotPoint(5, 5) = 10

RobotPoint(0, 6) = 210
RobotPoint(1, 6) = 180
RobotPoint(2, 6) = 180
RobotPoint(3, 6) = 150
RobotPoint(4, 6) = 110
RobotPoint(5, 6) = 100

RobotPoint(0, 7) = 210
RobotPoint(1, 7) = 68
RobotPoint(2, 7) = 180
RobotPoint(3, 7) = 247
RobotPoint(4, 7) = 110
RobotPoint(5, 7) = 100

RobotPoint(0, 8) = 210
RobotPoint(1, 8) = 68
RobotPoint(2, 8) = 180
RobotPoint(3, 8) = 238
RobotPoint(4, 8) = 160
RobotPoint(5, 8) = 100

RobotPoint(0, 9) = 210
RobotPoint(1, 9) = 170
RobotPoint(2, 9) = 180
RobotPoint(3, 9) = 140
RobotPoint(4, 9) = 160
RobotPoint(5, 9) = 100

RobotPoint(0, 10) = 131
RobotPoint(1, 10) = 180
RobotPoint(2, 10) = 180
RobotPoint(3, 10) = 155
RobotPoint(4, 10) = 160
RobotPoint(5, 10) = 100

RobotPoint(0, 11) = 130
RobotPoint(1, 11) = 180
RobotPoint(2, 11) = 180
RobotPoint(3, 11) = 100
RobotPoint(4, 11) = 160
RobotPoint(5, 11) = 100

M = 0
Do While (M < 12)
DoEvents
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
For g = 1 To RobotPoint(5, M)
DoEvents
Next g
If RobotPos(N) > RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) - 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) + 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
RobotStatus(N) = True
End If

N = N + 1
If N > 5 Then
If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) And (RobotStatus(5)) Then
M = M + 1
’ If M > 11 Then Exit Sub
End If
N = 0

End If
Loop

End Sub

Private Sub pass()
Static N As Integer
Static M As Integer

RobotPoint(0, 0) = 127
RobotPoint(1, 0) = 180
RobotPoint(2, 0) = 180
RobotPoint(3, 0) = 210
RobotPoint(4, 0) = 140
RobotPoint(5, 0) = 100

RobotPoint(0, 1) = 120
RobotPoint(1, 1) = 56
RobotPoint(2, 1) = 91
RobotPoint(3, 1) = 180
RobotPoint(4, 1) = 160
RobotPoint(5, 1) = 100

RobotPoint(0, 2) = 120
RobotPoint(1, 2) = 30
RobotPoint(2, 2) = 53
RobotPoint(3, 2) = 171
RobotPoint(4, 2) = 160
RobotPoint(5, 2) = 100

RobotPoint(0, 3) = 120
RobotPoint(1, 3) = 30
RobotPoint(2, 3) = 53
RobotPoint(3, 3) = 161
RobotPoint(4, 3) = 110
RobotPoint(5, 3) = 90

RobotPoint(0, 4) = 120
RobotPoint(1, 4) = 60
RobotPoint(2, 4) = 63
RobotPoint(3, 4) = 140
RobotPoint(4, 4) = 110
RobotPoint(5, 4) = 85

RobotPoint(0, 5) = 120
RobotPoint(1, 5) = 150
RobotPoint(2, 5) = 150
RobotPoint(3, 5) = 140
RobotPoint(4, 5) = 110
RobotPoint(5, 5) = 60

RobotPoint(0, 6) = 210
RobotPoint(1, 6) = 180
RobotPoint(2, 6) = 180
RobotPoint(3, 6) = 140
RobotPoint(4, 6) = 110
RobotPoint(5, 6) = 100

RobotPoint(0, 7) = 210
RobotPoint(1, 7) = 68
RobotPoint(2, 7) = 180
RobotPoint(3, 7) = 247
RobotPoint(4, 7) = 110
RobotPoint(5, 7) = 100

RobotPoint(0, 8) = 210
RobotPoint(1, 8) = 68
RobotPoint(2, 8) = 180
RobotPoint(3, 8) = 238
RobotPoint(4, 8) = 160
RobotPoint(5, 8) = 100

RobotPoint(0, 9) = 210
RobotPoint(1, 9) = 170
RobotPoint(2, 9) = 180
RobotPoint(3, 9) = 140
RobotPoint(4, 9) = 160
RobotPoint(5, 9) = 100

RobotPoint(0, 10) = 131
RobotPoint(1, 10) = 180
RobotPoint(2, 10) = 180
RobotPoint(3, 10) = 105
RobotPoint(4, 10) = 160
RobotPoint(5, 10) = 80

RobotPoint(0, 11) = 130
RobotPoint(1, 11) = 180
RobotPoint(2, 11) = 180
RobotPoint(3, 11) = 100
RobotPoint(4, 11) = 160
RobotPoint(5, 11) = 120

M = 0
Do While (M < 12)
DoEvents
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
For g = 1 To RobotPoint(5, M)
DoEvents
Next g
If RobotPos(N) > RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) - 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) + 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
RobotStatus(N) = True
End If

N = N + 1
If N > 5 Then
If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) And (RobotStatus(5)) Then
M = M + 1
’ If M > 11 Then Exit Sub
End If
N = 0

End If
Loop

End Sub
[/code]

Can you tell me how to increase the movement speed of the robot arm??? Thanks…

I took a quick look through and not knowing what you are talking to at the other end of the serial port I can not fully answer.

But it looks like your code moves only one servo, one unit in the desired direction per loop and then it does some form of pause in the loop:

For g = 1 To RobotPoint(5, M) DoEvents Next g
So a couple of things that could help.

  1. decrease the number of times that this G loop goes per iteration.
  2. Maybe do one pass of all of the servos before you go into this loop.
  3. Scale your moves. That is instead of only moving 1 unit in the desired direction such that the moves that are farther take that much longer, maybe instead calculate how far each servo needs to move for each move group, decide on how many iterations you wish the move to take and then increment or decrement by that fraction of units…

Kurt

I think he’s using a MiniSSC-II.

MSComm1.Output = Chr$(255) '<-sync byte MSComm1.Output = Chr$(N) '<- servo to move MSComm1.Output = Chr$(RobotPos(N)) '<- position to move to

Yep you probably are right. :smiley:

Taking a quick look at those docs (as I have not used one). It does look like you can use features of it to do part of the work. That is the upper nibble of the servo byte is a speed control. That is it tells you how many half units to change per 20ms (1/50th of a second).

So the code could be organized that for example if your current location is:
(127, 180, 180, 210, 140) and you are moving to (120, 56, 91, 180, 160)

And for example if you wish for this move to take a 1/4 second (250us) than the absolute deltas for this move are:
(7, 124, 89, 30, 20) and this is about 12.5 cycles of time. So you could easily say that speed for each of the servos in half units might be
(1, 20, 14, 5, 3)

Once you output the new move location/speeds, you could have the code wait until that move should have completed and then output the next set.

Kurt

Oops, the MiniSSC-II didn’t have the speed option. It was only used in the SSC-12.

:blush: In that case you can do the same logic in VB as my 3) in the first post :blush:

The logic is not overly difficult. simply loop through the number of iterations we calculated, add/subtract off the deltas (handle not overrunning). In the previous post the deltas are in 1/2 units so you could either decide that single units are OK or you could use floating point or you could easily scale the units you use internally by a factor of 10. So instead of going from 127 to 120 you are going from 1270 to 1200 (delta 70) if 12 iterations you would delta by 6. When it is time to output divide by 10…

Kurt

i am still in the process of learning vb…so i dont understand the delta part…now, which part of my program i should modify and put in the new codes? actually my robot need to do load a PCB board onto a conveyor,unload it in a pass bin and unload it in the fail bin. Do you have any simpler program than the one i have to do the task? BUt the program must be in VB6.

First some quick suggestions and simple changes. Note, I think all three functions are the same code, except maybe the initialization of the arrays, so I would move the real code off to a separate function that all three call…

First attempt do you need to go into the DoEvent loop for each update for each servo or can you update each servo and then do the wait? Something like:

[code] M = 0
Do While (M < 12)
DoEvents()
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
If RobotPos(N) > RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) - 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
RobotPos(N) = RobotPos(N) + 1
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
RobotStatus(N) = True
End If

        N = N + 1
        If N > 5 Then
            For g = 1 To RobotPoint(5, M)
                DoEvents()
            Next g
            If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) And (RobotStatus(5)) Then
                M = M + 1
                '  If M > 11 Then Exit Sub
            End If
            N = 0

        End If
    Loop

[/code]
If this does not help enough what happens if you change the loop count? ie the elements RobotPoints(5, M) to a smaller number?

The more hard core code might look something like:

[code] Dim Deltas(5) As Integer
Dim RobotPosTimes10(5) As Integer

    For M = 0 To 11
        ' first calculate the delta from our current location to the new location
        ' Maybe element 5 is specified in the number of times we go through this loop...
        ' so Deltas would be specified in it...
        For N = 0 To 4
            Deltas(N) = RobotPoint(N, M) - RobotPos(N)       ' This is the delta from one move to the next
            Deltas(N) = (Deltas(N) * 10) / RobotPoint(5, M) ' factor how much to change in 10ths of unit per iteration
            RobotPosTimes10(N) = RobotPos(N) * 10         ' have in partial units...
        Next

        ' Now loop through the number of iterations...
        For i As Integer = 1 To RobotPoint(5, M)
            For N = 0 To 4
                RobotPosTimes10(N) = RobotPosTimes10(N) + Deltas(N)
                If RobotPosTimes10(N) / 10 <> RobotPos(N) Then
                    RobotPos(N) = RobotPosTimes10(N) / 10
                    MSComm1.Output = Chr$(255)
                    MSComm1.Output = Chr$(N)
                    MSComm1.Output = Chr$(RobotPos(N))
                End If
            Next
            DoEvents();
        Next
        ' Make sure we did not under or over run our location
        For N = 0 To 4
            If RobotPos(N) <> RobotPoint(N, M) Then
                RobotPos(N) = RobotPoint(N, M)
                MSComm1.Output = Chr$(255)
                MSComm1.Output = Chr$(N)
                MSComm1.Output = Chr$(RobotPos(N))
            End If
        Next
        DoEvents();
    Next

[/code]

I have not tested any of this out, but hopefully it helps.

Kurt

Not sure if you understand the meaning. Delta is the technical term given to mean a change. So if a value went from 1500 to 1548 the delta is 48. Calculating the delta for each servo moved is a good starting place to making smooth and coordinated code.

kurte, the codings didnt help me… Actually the N represent the pin where the servo motor is connected. so when i compile the program,it says error in division by zero…

Which version did you try? What line did it complain about?

Kurt

P.S - I did not actually try this out, the idea was to get you going into trying a couple of different approaches.

when i tried the first one,the program ran but was still slow. when i try the second, it show the DoEvents() in red and For i As Integer = 1 To RobotPoint(5, M) in red. Then i changed to For i = 1 To RobotPoint(5, M) and it was fine. The Doevents i changed to DoEvents and it shows fine. and once i start running it it shows error division by zero in :

So what was the value of M when this happened?
i.e. what was the value of RobotPoint(5, M)
Was the outer loop going too far? That is it looked like you filled arrays for elements 0-11 Did you set one of thes to 0?
My guess is that you won’t want as high of values as your initial program, maybe start off with something like 10 and see how it does.

But the real question is do you understand what it is trying to do?

Kurt

Dim RobotPos(5) As Integer
Dim RobotPoint(5, 20) As Integer
Dim RobotStatus(5) As Integer

Private Sub Command1_Click()
dowork
End Sub

Private Sub Command2_Click()
dowork1
End Sub



Private Sub Form_Load()
MSComm1.CommPort = 7
MSComm1.Settings = "115200,N,8,1"
MSComm1.PortOpen = True
RobotPos(0) = 127
RobotPos(1) = 127
RobotPos(2) = 127
RobotPos(3) = 127
RobotPos(4) = 127
RobotPos(5) = 127

RobotPoint(0, 0) = 127
RobotPoint(1, 0) = 180
RobotPoint(2, 0) = 180
RobotPoint(3, 0) = 210
RobotPoint(4, 0) = 140
RobotPoint(5, 0) = 10

RobotPoint(0, 1) = 120
RobotPoint(1, 1) = 56
RobotPoint(2, 1) = 91
RobotPoint(3, 1) = 180
RobotPoint(4, 1) = 160
RobotPoint(5, 1) = 10


RobotPoint(0, 2) = 120
RobotPoint(1, 2) = 30
RobotPoint(2, 2) = 53
RobotPoint(3, 2) = 171
RobotPoint(4, 2) = 160
RobotPoint(5, 2) = 100


RobotPoint(0, 3) = 120
RobotPoint(1, 3) = 30
RobotPoint(2, 3) = 53
RobotPoint(3, 3) = 161
RobotPoint(4, 3) = 110
RobotPoint(5, 3) = 100


RobotPoint(0, 4) = 120
RobotPoint(1, 4) = 60
RobotPoint(2, 4) = 63
RobotPoint(3, 4) = 140
RobotPoint(4, 4) = 110
RobotPoint(5, 4) = 10


RobotPoint(0, 5) = 120
RobotPoint(1, 5) = 150
RobotPoint(2, 5) = 150
RobotPoint(3, 5) = 140
RobotPoint(4, 5) = 110
RobotPoint(5, 5) = 10

RobotPoint(0, 6) = 210
RobotPoint(1, 6) = 180
RobotPoint(2, 6) = 180
RobotPoint(3, 6) = 140
RobotPoint(4, 6) = 110
RobotPoint(5, 6) = 1

RobotPoint(0, 7) = 210
RobotPoint(1, 7) = 68
RobotPoint(2, 7) = 180
RobotPoint(3, 7) = 247
RobotPoint(4, 7) = 110
RobotPoint(5, 7) = 1


RobotPoint(0, 8) = 210
RobotPoint(1, 8) = 68
RobotPoint(2, 8) = 180
RobotPoint(3, 8) = 238
RobotPoint(4, 8) = 160
RobotPoint(5, 8) = 10


RobotPoint(0, 9) = 210
RobotPoint(1, 9) = 170
RobotPoint(2, 9) = 180
RobotPoint(3, 9) = 140
RobotPoint(4, 9) = 160
RobotPoint(5, 9) = 10

RobotPoint(0, 10) = 131
RobotPoint(1, 10) = 180
RobotPoint(2, 10) = 180
RobotPoint(3, 10) = 105
RobotPoint(4, 10) = 160
RobotPoint(5, 10) = 10

RobotPoint(0, 11) = 130
RobotPoint(1, 11) = 180
RobotPoint(2, 11) = 180
RobotPoint(3, 11) = 100
RobotPoint(4, 11) = 160
RobotPoint(5, 11) = 10

End Sub
Private Sub dowork1()
Static N As Integer
Static M As Integer
M = 0
Do While (M < 12)
DoEvents
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
For g = 1 To RobotPoint(5, M)
DoEvents
Next g
If RobotPos(N) > RobotPoint(N, M) Then
 RobotPos(N) = RobotPos(N) - 1
 RobotStatus(N) = False
 MSComm1.Output = Chr$(255)
 MSComm1.Output = Chr$(N)
 MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
 RobotPos(N) = RobotPos(N) + 1
 RobotStatus(N) = False
 MSComm1.Output = Chr$(255)
 MSComm1.Output = Chr$(N)
 MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
  RobotStatus(N) = True
End If

N = N + 1
If N > 4 Then
  If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) Then
  M = M + 1
'  If M > 11 Then Exit Sub
  End If
N = 0

End If
Loop


End Sub


Private Sub dowork()
Static N As Integer
Static M As Integer
M = 0
Do While (M < 12)
DoEvents
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
For g = 1 To RobotPoint(5, M)
DoEvents
Next g
If RobotPos(N) > RobotPoint(N, M) Then
 RobotPos(N) = RobotPos(N) - 1
 RobotStatus(N) = False
 MSComm1.Output = Chr$(255)
 MSComm1.Output = Chr$(N)
 MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
 RobotPos(N) = RobotPos(N) + 1
 RobotStatus(N) = False
 MSComm1.Output = Chr$(255)
 MSComm1.Output = Chr$(N)
 MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
  RobotStatus(N) = True
End If

N = N + 1
If N > 4 Then
  If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) Then
  M = M + 1
'  If M > 11 Then Exit Sub
  End If
N = 0

End If
Loop

End Sub

Above is the original coding before i break it into 3 parts for 3 type of functions. The program above works well without any speed problem. Can you figure out where did i do the mistake in the previous coding that i posted?

hi kurte, thanks for ur coding. using ur coding, i modify it and manage to make the robot to work fast again. Actually, each time my robot detects angle difference, it will add or minus it with the intial position one by one. so it makes the robot arm to move slowly. So,what i did was, i calculated the difference of the movement and then plus it with the robot intial angle to get the new position. This makes the robot to move quickly to the new position.

[code]M = 0
Do While (M < 19)
DoEvents
Label1.Caption = N
Label2.Caption = M
LbPos(N).Caption = RobotPos(N)
For g = 1 To RobotPoint(5, M)
DoEvents
Next g
If RobotPos(N) > RobotPoint(N, M) Then
Deltas(N) = RobotPoint(N, M) - RobotPos(N)
RobotPos(N) = RobotPos(N) + Deltas(N)
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) < RobotPoint(N, M) Then
Deltas(N) = RobotPoint(N, M) - RobotPos(N)
RobotPos(N) = RobotPos(N) + Deltas(N)
RobotStatus(N) = False
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(N)
MSComm1.Output = Chr$(RobotPos(N))
ElseIf RobotPos(N) = RobotPoint(N, M) Then
RobotStatus(N) = True
End If

N = N + 1
If N > 5 Then
If (RobotStatus(0)) And (RobotStatus(1)) And (RobotStatus(2)) And (RobotStatus(3)) And (RobotStatus(4)) And (RobotStatus(5)) Then
M = M + 1
’ If M > 11 Then Exit Sub
End If
N = 0

End If
Loop

End Sub
[/code]

Thanks to everyone who replied to this post and tried to help me out.