To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcxOpen lugnet.robotics.rcx in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / 521
520  |  522
Subject: 
VB 6 subprocedure stumper
Newsgroups: 
lugnet.robotics.rcx
Date: 
Mon, 27 Mar 2000 04:14:12 GMT
Viewed: 
2292 times
  
I sure could use some help.  I'm trying to recreate the BugBot program from
the book "Definitive Guide to Lego Mindstorms" in VB 6. It's a simple program
with a tank-like robot that has two "feelers" - one if the robot hits
something on the right; one for the left. At this point I've simplified the
program and there is a main task with an infinite loop - which constantly
calls two subprocedures - one each to check the left sensor and the right
sensor.  The stumper is:  whichever subprocedure is last is the one that
works.  If the check_left procedure is last in the code then just it works; if
the check_right procedure is the last one then just it works.  Strange and
frustrating.  Having the subprocedures above or below the "main" task makes no
difference.  In fact, the really odd thing is that if I comment out the code
in "main" which calls the last subprocedure, that subprocedure still works!

Omitting the normal code for exiting, downloading, etc., here's the heart of
the program:

Private Sub DownPrgm_Click()
With PBrickCtrl
    .SelectPrgm 0
    .SetSensorType SENSOR_1, SWITCH_TYPE
    .SetSensorType SENSOR_3, SWITCH_TYPE

    .BeginOfSub CHECK_LEFT
        .If SENVAL, SENSOR_1, EQ, CON, 0 ' button is out
            .Off MOTOR_0
           .SetRwd MOTOR_2
           .While SENVAL, SENSOR_1, EQ, CON, 0  'button is still out
            'just sorta spin & do nothing - motor_2 still in reverse
           .EndWhile
           .On MOTOR_0
           .SetFwd MOTOR_2
        .EndIf
    .EndOfSub

    .BeginOfSub CHECK_RIGHT
        .If SENVAL, SENSOR_3, EQ, CON, 0 ' button is out
           .Off MOTOR_2
           .SetRwd MOTOR_0
           .While SENVAL, SENSOR_3, EQ, CON, 0  'button is still out
            'just sorta spin & do nothing - motor_0 still in reverse
           .EndWhile
           .On MOTOR_2
           .SetFwd MOTOR_0
        .EndIf
    .EndOfSub

    .BeginOfTask MAIN
        intCounter = 0
        .SetPower MOTOR_0 + MOTOR_2, CON, 3
        .SetFwd MOTOR_0 + MOTOR_2
        .On MOTOR_0 + MOTOR_2
        .Loop CON, forever          'keep looping forever
           .GoSub CHECK_LEFT
           .GoSub CHECK_RIGHT
        .EndLoop
    .EndOfTask  'main
End With
End Sub
'-----------------------
Any suggestions, help would be greatly appreciated!
--Kathy Brooks



Message has 1 Reply:
  Re: VB 6 subprocedure stumper
 
Hi Kathy, My first question would be "What are the values of CHECK_LEFT and CHECK_RIGHT?" If they're the same, that would produce the behavior you're getting. I know I often make a mistake like that when I copy and paste a line of code. You also may (...) (25 years ago, 27-Mar-00, to lugnet.robotics.rcx)

5 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR