Joystick Button Code

I need to find a way to get my code to activate a shooter on the practice bot when a button on the joystick is pressed, but when I push all the buttons on the joystick, the flywheel does not move. I have two snippets so you can see what the problem is.

Snippet 3

Where you initialize the NEO motor in you don’t create a refnum to pass to the I expect you could use a Motor refnum, which you read in teleop (connected where the Motor vi with the slider is).

So for your it appears you attempted to set the motor type. In begin you need to establish a refnum by using a “refnum Registry set” VI. I have done this for you as well as added a safety config. What setting a refnum does is it establishes some data to be referenced later. I have named your motor “Flywheel” though you might want to name it something more precise for later just so that you know exactly what it is that you’re referring to. Such as “ShooterFlywheel6” That way whenever you’re dealing with this specific motor, you know what contraption you’re dealing with, and the CAN bus number associated with it.

As for your I wouldn’t recommend putting VIs inside case structures like that. Also when telling a motor to “output” a value you first need to place down a “refnum registry get” .vi so that you can reference the correct motor. I have done so in the following code.

I would fully recommend having some examples you can refer back to consistently so that you don’t run into problems like this very often. I have included the one I often use because Robotic Eagles do a pretty great job of covering a vast array of topics. I actually was a student once learning LabVIEW with no mentor, and their examples were just so helpful.

Feel free to shoot me a message on here if you need any more help.

1 Like

I did what you said, but the code still does not work. I have two snippets of my updated code so you can see what’s wrong.
Snippet 2
Snippet 3

Why are you using the “Set Motor Type” VI in your begin code? That VI is used to set whether you’re using a brushed or brushless motor but there is nothing wired into the terminal, meaning that it is basically just sitting there taking up space and possibly messing up your code. Also, double check that your CAN bus numbers are correct.

If that isn’t the problem, then there is either some other form of problem going on, the code here should work for what you’re trying to do.

I now have edited the teleop and begin sections, but the code still does not work. How can I fix this?
Snippet 2
Snippet 3
P.S. My instructor now said that the press of a button should move the drivetrain.

The last bit of code you posted should always move the motors labeled as “Drivetrain” by 0.5. This should happen no matter what is being done on the joystick.

Others here have helped you figure out how to create a reference and call that in other parts of the code. (Though, if all you have in a case structure is a constant, replace the structure with a Select so your code is easier to read)

I haven’t seen anyone help you verify you have the correct button. Open up your driver station, click on the USB looking icon on the left side. You should see your Joystick there. Your code uses Joystick0 so click on the item listed first (should be selected already). Press the button you’ve been trying to use to make the flywheels move. Does that illuminate the top box or one further down? If it isn’t the top box, you’re pushing the wrong button based on what you’ve programmed. Those squares are zero indexed. Starting at the top, count 0, 1, 2, etc until you get to the one that lights up when you press the button. In your code, make that value match.