|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Problem programming buttons
We need buttons 1-4 on our game controller to set two different motors to the same speed when each button is pressed; each button is a different speed setting. Only one of them works properly for some reason (more on that in a minute), but the other three are identical as far as I can tell other than the button number and speed assignment.
The one that works: Button 1--> Case structure: two true constants of -.67 and two false constants of 0-->WPIMotorControlSetOutput.vi (a separate one for each constant) --> WPIMotorControlRefNum Registry Get.vi (a separate one for each set output) -->motor names (since I lack creativity their names are "motor 1" and "motor 2") The ones that don't work are exactly the same except the button numbers are different and the true constants in the case structure are different. As I said, the button 1 programming works: it runs the motor at 2/3 speed. Buttons 2, 3, and 4 either don't work at all or make the motor twitch a little. Some of the things we've tried and what happened: -Use different game controller: no difference -Use different motor: no difference -Use different PWMs: no difference -Change speed in the button 1 code: button 1 sets motor to whatever speed we specified -Disable code for buttons 3 and 4: button 1 still works and button 2 does not At this point I'm not sure what I did, but I think I messed something up or accidentally deleted something, so I'm not too sure how credible this next piece of troubleshooting was; thankfully I had my pre-troubleshooting code saved elsewhere; I'll try it again tomorrow with that. Anyway, my next step: -With buttons 3 and 4 still disabled, I changed the button assignment for the piece of code that we know works from button 1 to button 3. After this, none of the buttons worked. Any ideas on what could be wrong? Thanks in advance for your input. Last edited by Martian86 : 07-02-2013 at 02:15. |
|
#2
|
|||||
|
|||||
|
Re: Problem programming buttons
If I understand what you're describing, you have four essentially independent Case Structures. Each of them sets the same motors in the True case. What do the False cases do? It sounds like they all set the motors to zero.
I think you've made a common programming error. If the second button is pressed, its True case sets the motors to the value you want -- but because the first button is not pressed, its False case immediately sets the motors to zero. Having multiple Motor Set functions is a recipe for this sort of race condition. Instead of having the Case do everything, just have it produce the values you want to run the motor with, and put a single RefNum Get and Motor Set Value outside the Case Structures. Chain the Case Structures together so that the False case just feeds its inputs straight through to its outputs without change, and the True case ignores the inputs and wires the desired constants to its outputs. Feed zeros into the first Case Structure so that the motors will be off when no buttons are pressed. Or you can use Select functions instead of Case structures. Or you can get fancy and encode the four buttons into a number, then use that number to select among many different Cases in a single structure. |
|
#3
|
|||
|
|||
|
Re: Problem programming buttons
Out team did the same thing - used T/F case structures each having a motor set. It mostly worked at .6 and the others would just move the motor in small increments. After thinking about it we came up with the same conclusion as above - all non pressed buttons are F and setting the motor to 0 while the pressed one is setting it to .6 for example. I'm not sure why .6 seems to work for us and many others that tried this method. My guess is that is has something to do with PWM, the motor frequency, and the DS communication packet delivery.
We moved to using cascaded select statements and it works fine. |
|
#4
|
|||
|
|||
|
Re: Problem programming buttons
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|