Thread: Coding
View Single Post
  #6   Spotlight this post!  
Unread 18-03-2014, 18:40
cogbrained3244 cogbrained3244 is offline
Registered User
FRC #3244
 
Join Date: Nov 2012
Location: St.Cloud MN
Posts: 5
cogbrained3244 is an unknown quantity at this point
Re: Coding

I want to make sure that you understand what Arhowk is trying to say, and make sure you made the change correctly. Your if-else statements are sending conflicting signals to the motor controllers. The Java Virtual Machine (JVM) will evaluate the two if statements separately the way you have them written. The first one will be evaluated, and send either a full-speed signal or stop motion signal. Then the second one will be evaluated, sending either a half-speed signal or a stop signal. This results in several possible combinations such as full-speed and zero, half-speed and zero, or full-speed and half-speed. The usual result of the first two is a jumpy motion where the movement stops and then starts again, especially if the button is held down.

Combining the code to have an else-if statement should prevent that paticular kind of jumpy motion. An else-if statement is evaluated as one statement, and will therefore only set your motor to one speed, rather than trying to set it to two speeds at once.

The code for an else-if statement would look like this:
Code:
 if(stickDriverRight.getButton(Joystick.ButtonType.kTrigger)) {
           shooter.set(1);
        }
        else if(stickDriverLeft.getButton(Joystick.ButtonType.kTrigger)) {
            shooter.set(-0.5);
        }
        else {
            shooter.set(0);
        }
It should replace, quite precisely, this block of code:
Code:
 if(stickDriverRight.getButton(Joystick.ButtonType.kTrigger)) {
           shooter.set(1);
        }
        else {
            shooter.set(0);
        }
        
        
        if(stickDriverLeft.getButton(Joystick.ButtonType.kTrigger)) {
            shooter.set(-0.5);
            
        }
        else {
            shooter.set(0);
            
        }
That's the only thing visibly wrong with your teleop code-I've seen this problem exactly with a claw we were working on during build, and experienced the jumpy motion I described earlier. The only other things that I could think of to check are trying different parameters for the .getButton method, in case the one you're using doesn't work (it might be perfectly valid but I've never used it before), and running through wiring debugs.

Also, the more details you give us on what you're looking to do and the problems you're having, the more we can help
Reply With Quote