Limit Swtich Help

So could I do something like



axis = Xbox.getRawAxis(someaxis); // Do I need float or double?

if(axis == 1) {
     victor1.set(1);
     victor2.set(1);
}

Sorry if thats way off Im still a bit confused.

Your getting there! It can be hard to learn this stuff remotely without someone experienced there to help.

Your code is actually really close. Joystick axis values are returned as doubles, but that’s a good question! There is often a lot of confusion between float and double, as they appear to be basically the same. In situations like thiszits useful to look at the javadoc For the object your using. A quick search turned up a copy here: FRC JavaDocs for 2022 go there and click on “Joystick” in the class listing on the left. You can then scroll through all of the methods in the joystick class, find the one you’re using, get a short description of it, and see its return type. Pretty handy!

With the code you posted, the elevator will go up only if you have the joystick pushed full forward so the return value is 1. Pushing it halfway, so you get 0.5, wouldn’t move it. Additionally, if you aren’t pushing perfectly straight, you won’t get a return value of 1! Take a piece of graph paper, draw a set of axis, and then draw a circle with a radius of 1, centered on the origin. Everything inside that circle is a value that can be returned by the joystick. If you push the joystick forward, you could get 0 for the x axis and 1 for the y axis… Or you could get something just a little less than 1 for the y axis and a little greater or less than 0 for the x axis, if you aren’t perfectly straight.

So the only problem with your code is that it demands perfection from the driver to work. It would be much better to do something like “axis > 0.5” (pick an appropriate number) so you have a range on the joystick where pushing it forward makes it move. That way your driver doesn’t have to be perfect!

Will this work?


double axis = Xbox.getRawAxis(*));

if(axis  > 0.5) {
     victor1.set(1);
     victor2.set(1);

}

That looks good to me. Give a try, see if it does what your expecting!

Okay thanks for the help so far I will test it tonight.

I am having a problem where my relay is stuck in forward (showing a green light) or off (showing no light) when I press a button. Here’s the code.

if(xbox.getRawButton(4)) {
            	spike1.set(Relay.Value.kForward);
            	spike2.set(Relay.Value.kForward);
            } else if(xbox.getRawButton(1)) {
            	spike1.set(Relay.Value.kReverse);
            	spike2.set(Relay.Value.kReverse);     
            } else {
            	spike1.set(Relay.Value.kOff);
            	spike2.set(Relay.Value.kOff);            	
            }
    	}
    }

When I read that, it looks like it says “while button 4 is pushed, go forward. While button 1 is pushed, go in reverse. If neither button is pushed, stop” is that not what’s happening? Your description of the behavior isn’t really complete to tell us what you want to have happen.

Take a look at the user manual for the spike, found here: http://content.vexrobotics.com/docs/spike-blue-guide-sep05.pdf

It describes the operation of the LED. It’s been a while since my team has used one, but I believe it says kForward is green, kReverse is red, kOff is Orange, kOn is blank.

Double check the wiring and make sure it isn’t shorting something when you push button 1, I’ve seen a short cause the LED to turn off before.

The issue is when I press button 1 one relay goes in reverse and the other goes to kOn (LED BLANK) and when I press button 4 it goes in kForward(GREEN). Also the spike is stuck in kForward because it’s always green unlike the other which is yellow.

Double check the orientation of the PWM wire, both in the spikes and in the relay ports on the RoboRio. I have a suspicion that one is plugged in backwards or in the wrong location all together.

No I just checked everything looks good the black cable is closest to the edge on the roboRIO and it is facing the correct way on the spike.

I’m trying to figure out exactly what the behavior is that you are describing. I think it would help to use the two variable names like spike1 and spike2.

When you press button 1, spike1 goes in reverse and spike2 goes to kOn?

When you press button 4, which spike goes to kForward: spike1 or spike2? What does the other do?

Whichever goes to kForward, are you saying that it is now stuck in the kForward state no matter which buttons you push?

When you say yellow, is that possibly orange? The manual says that the possible colors are red, green, and orange. Do you see all three of those colors and a yellow?

In addition to checking the orientation of the PWM cable, check the power leads (both into the spikes and then out of the spikes) so that you are correctly getting power to power and ground to ground.

Sorry for the confusion, basically when I press button 1 spike1 goes in kReverse and this is good, however, spike2 sets it self to kOn(No LED). When I release button 1 spike1 goes to the orange color but spike2 goes in kForward. When I press button 4 spike1 goes in kForward and this intended but spike2 also is in kForward but it was not activated by the button because it is always in kForward unless I press button 1 then it enters kOn until I release the button.

This is really sounding like a wiring issue, it’s definitely not something in the code you posted. Can you post a pic of your wiring?

Tomorrow afternoon I will post one.

I agree 100% with Jon…you construct the two objects in the same way (so they should default to the same settings) and you call the same methods on the objects under the same conditions. When you look at the wires, check all power inputs and outputs as well as the PWM wires. I hate to be a software guy that blames the hardware, but…

I just pulled a spike out of last years bot and it works.

Sweet! Congrats on successfully troubleshooting the problem. I hope that you haven’t torn too much hair out :slight_smile:

lol yeah It’s just a part of the process I guess… anyway thanks for all of the help.

I have one final question, I noticed that when my victors are set in reverse and I press the limit switch the victors don’t stop very well. Is there anyway to fix this or is it fine the way it is. Here’s the code


public void operatorControl() {
    	
    	while (isOperatorControl() && isEnabled()) {
    	    double leftaxis = xbox.getRawAxis(1);
            robot.arcadeDrive(stick.getY() * 0.5, stick.getX() * 0.5); //Change the 0.5 for sensitivity, I removed get throttle I may need it again.
            limitPressed = limit.get(); 
            limitPressed2 = limit2.get();
            limitPressed3 = limit3.get();
            limitPressed4 = limit4.get();
            
            /*limitPressed will be the bottom of the lead screw.
             * limitPressed2 will be the top of the lead screw.
             * limitPressed3 will the for the left minimum arm distance.
             * limitPressed4 will be for the max arm distance.
             * The print lines are helpful for testing boolean states.
            //System.out.println("limitPressed=" + limitPressed); //Read the RoboRIO log for some values.
            //System.out.println("limitPressed2=" + limitPressed2);
            //System.out.println("limitPressed3=" + limitPressed3);
            //System.out.println("limitPressd4=" + limitPressed4);
            */

            if(limitPressed || limitPressed2 == false || limitPressed3 == false || limitPressed4 == false) {
            	victor1.set(0);
            	victor2.set(0);
            } else if (-leftaxis > 0.5) {
            	victor1.set(1);
            	victor2.set(1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            if(leftaxis > 0.5) {
            	victor1.set(-1);
            	victor2.set(-1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            if(xbox.getRawButton(4)) {
            	spike1.set(Relay.Value.kForward);
            	spike2.set(Relay.Value.kForward);
            } else if(xbox.getRawButton(1)) {
            	spike1.set(Relay.Value.kReverse);
            	spike2.set(Relay.Value.kReverse);     
            } else {
            	spike1.set(Relay.Value.kOff);
            	spike2.set(Relay.Value.kOff);            	
            }
    	}
    }

Is the jumper set for coast or brake? If coast, try changing it to brake.