FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with joysticks

First time programers trying to get our joysticks to make a motor go forward and backwards as well as turn a solenoid on and off.  We have it programmed like the picture below with the joysticks working fine going to our tank drive.  We havent been able to get our trigger and button 2 to work on our joystick to anything else.  Any ideas what could be our issue?

Thanks for any help!

Team 3292

Download All
0 Kudos
Message 1 of 8
(7,076 Views)

Hey Team 3292,

Thanks for posting your code, it helped in troubleshooting.  From the code you posted, it looks like you are trying to get the motor connected to PWM 5 to move in one direction when button 0 on LeftStick is pressed and to move in the other direction when button 1 on RightStick is pressed.

You will need this code in the "Begin" VI.  This code sets up both joysticks and the motor.  I used PWM 8, but you would use PWM 5.

begin_code.png

Next, you will need the following code in the "Teleop" VI.  This code is commented, and what it does is reads the values from each joystick, indexes the 0th button or button 0, and uses some logic to move the motor.

If we look at the logic more closely, we see that when either both buttons are pressed or both buttons are released, the motor does not move at all.  When only one button is pressed, we check if it's the left one.  If it is, we move the motor backward.  If it is not, we know that it's the right one because we know that at least one button is pressed.  We then take this output and wire it to the PWM input of the motor set output vi.

teleop_code.png

Finally, to close everything properly, use the following code in the "Finish" VI.  This will close everything out well.

finish_code.png

This can be a little confusing so let us know what questions you have.

Robots Rule!

-Jim

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 2 of 8
(4,042 Views)

So we added in the codes that was suggested said to add in, and we still don't have any joystick buttons working.

0 Kudos
Message 3 of 8
(4,042 Views)

Hey guys, can you attach the teleop VI or another picure of your code like in the first post.  All the project is is a list of VIs, but does not include any of the code.

Thanks,

-Jim

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 4 of 8
(4,042 Views)

Here are some pictures of our code again.  A quick overview of what we did.  We put the begin code in the begin vi, the teleop code in the teleop vi, and the finish code in the finish code vi but that is under team code.  We also attached our scheduling loop because that is where we were told to put our tank drive after we were having issues.  When we put our tank drive code in the teleop we were getting 1 second intervals spurts of it working.  Basically on and off.  When we put it on the scheduling loop it worked fine. 

Thank you guys for all the help so far!

Tom

Team 3292

Download All
0 Kudos
Message 5 of 8
(4,042 Views)

Hey Tom,

Since we implemented the motor control in the Teleop.vi, remove any subVI that has "MOTOR" at the top and is that orangish color in the Scheduling loop.

Also, we're opening the joysticks twice: once in the Begin.vi and once in the Scheduling Loop.  I would get rid of the "Joystick Open.vi"s outside the loop and keep the ones in Begin.vi.  then, you could call the joysticks by reference just like you currently do in the Teleop.vi.

Finally, if you follow the model we've set up by opening references in the Begin.vi, using those references in the Teleop.vi, and closing everything in the Finish.vi, there shouldn't be a problem moving the drive control to Teleop.vi.

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 6 of 8
(4,042 Views)

I just want to make sure I understand what I need to do. On the scheduling

loop I can delete our Tank Drive System and then move that all over to the

Teleop VI.

I then should delete the open Joystick in the scheduling loop and then when

I right click, create constant, on the get joysticks should I reference

them as USB 0 and USB 1?

Then I don't mean to question to you, but if I delete my motors out of my

scheduling loop, how will the motors know when the joysticks tells them to

move.

0 Kudos
Message 7 of 8
(4,042 Views)

Robot Main VI

0 Kudos
Message 8 of 8
(4,042 Views)