by hassenplug » 15 Jul 2011, 19:22
Let me start by saying that I'm not trying to insult your programming. Just suggest ways you can improve it.
Ok, I can tell you a whole bunch of things that are wrong with your program, which combine to create an interesting effect. First, a fundamental "bad technique" used: It's not a good idea to use strings in your case statement. It's easy to make a spelling error that would cause invalid cases. Numbers work better (they're hard to misspell).
Problem 1: in the "check for sensors" case, there appears to be spaces after "Touch 1" (see technique above) That means when touch 1 is pressed, it will skip the touch 1 case, and go to the default case of touch 2
Problem 2: "Touch 2" checks port 1, not port 2. Also, not sure if it's a problem, but there is no port specified for the US sensor. It may already default to 4.
Problem 3: you're using different values for the US sensor range check. In one place, you use 10cm, and another you use 5cm. *note, the US sensor readings are not very accurate below 4", or about 10cm
Comment 1: the Initialize case is pretty much the same as the "drive" case. Personally, I'd just skip to the drive case, so you have one less case.
Comment 2: The "Check For Sensors" case checks all the sensors, then goes through cases that check each sensor. I don't think you need both types of checks.
Comment 3: Not sure if this was intended, but in one place your testing for sensor "bump" while in another place, your testing for "pushed".
Hope that helps.
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->