We are trying to program our robot so that if you hold down the trigger on one joystick then the motor goes forward, and if you hold down the trigger on the other joystick the motor goes in reverse. we have tried while loops and they simply stop our drive train and nothing works. when we have tried to put in multiple if loops then the drive works but it goes in one direction and continues until we shut our bot down.
You have not stated explicitly what you want the motor to do when neither of the joystick buttons have been depressed. I assume that you want the motor to stop. This may also be the problem with the code.
i.e. Have you programmed the motor speed to be zero when neither of the buttons are pressed?
Incidentally, the Motor Control Set Speed.vi uses an input range from -1, 1]. If you want a range from [0-255], then you use the Set Value.vi in the WPI Robotics Library->IO->PWM->Set Value.vi You can right click on the VI and select Help for additional details about each VI.
well i’m trying to get it so that when you press button one on controller one, the motor turns one way. and then when you press button one on controller two, that the motor turns the other way. and when you don’t press either of them it stops.
i tried this program below, but nothing on the bot works!!!
oh and by the way, thank you for any advice you can give and thank you nate for showing me the pwm stuff, i knew it was out there but i couldn’t find it!
The latest picture doesn’t make it clear which joystick is being read, especially for the top portion.
Anyway, as mentioned before, you really have four possible combinations, three of which you have to define.
Neither button pressed – motor off (128 for value I guess).
Only J1 pressed – motor one direction (255)
Only J2 pressed – motor other direction (0)
Both J1 and J2 pressed – ??? (may I suggest motor off)
Keep in mind that when you set a motor speed/power, it stays at that setting until you change it. So if you never set it to 128, your motor never stops.
There are many ways to write the logic once you decide what you want. The important thing to do is to walk through your code for each of the above combinations and determine what the result is – does it match your desired outcome. If it gets too complicated or doesn’t seem to do what you want, use probes to verify all your assumptions.