|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
I am a relatively new programmer on a second year team. I was wondering if anyone knows if it is possible to program a window motor using the joystick buttons. What our team would like to do is to program our joystick so that when we press one button, the arm motor goes forward. When we press another button, we want the motor to go back. I do not know how to translate the relay outputs to a pwm output which would make the motor move. I tried writing an if statement that makes the pwm produce an output if a button is pressed, however nothing happens. I have performed countless searches for this information. The only threads I found talked about operating pnuematics using the joystick buttons, not motors. I do not know how to wire or program the relays so as to get a pwm output. I would appreciate any help. Thanks. ![]() Lead Programmer, Team 1474 |
|
#2
|
|||||
|
|||||
|
Re: Programming motors with joystick buttons
you have the right idea about using an if statment.
what you can try is something like this: Code:
if(p1_sw_trig==1)
{
pwm01=254;
}
else if(p1_sw_top==1)
{
pwm01=0;
}
else
{
pwm01=127;
}
|
|
#3
|
|||||
|
|||||
|
Re: Programming motors with joystick buttons
Same sort of thing would work if you have the window motor on a spike.
Code:
if (p1_sw_trig==1)
{
relay2_fwd = 1;
relay2_rev = 0;
}
else if (p1_sw_top==1)
{
relay2_fwd = 0;
relay2_rev = 1;
}
else
{
relay2_fwd = 0;
relay2_rev = 0;
}
|
|
#4
|
|||||
|
|||||
|
Re: Programming motors with joystick buttons
Or, alternatively:
Code:
pwmxx = (127 + (127*p1_sw_top) - (127*p1_sw_trig)); Replace xx with the pwm output you'll be using for the motor. In this case, pressing p1_sw_top will make the motor go full forward, p1_sw_trig will make it full reverse, and pressing both will do nothing. ![]() |
|
#5
|
|||
|
|||
|
Re: Programming motors with joystick buttons
hey,
I always wandered, when you press a button on a joystick (say the top button or trigger), does it "remember" it was pressed and hold a value of 1? I don't really understand this. otherwise, for the guy who posted this forum, he would have to be holding down the trigger, which seems like it would be problematic. do you know what I mean? how does that work. |
|
#6
|
||||
|
||||
|
Re: Programming motors with joystick buttons
Quote:
The flag would be set to one when the button is pressed which would enable code controlling relay ouputs or pwms. Once a desired outcome happens, the flag would have to be reset. The outcome could be a pot position being reached, an encoder count value, a set amount of time from either Kevin's clock or a clock variable incremented every program cycle, or even the ORIGINAL BUTTON pressed on the joystick. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using the extra buttons on the joystick. | Code\\Pilot | Programming | 7 | 04-12-2004 19:30 |
| problem with joystick buttons (top left one) | Richomundo | Programming | 5 | 15-02-2004 17:16 |
| Programming the second joystick in PBASIC | archiver | 2001 | 2 | 24-06-2002 00:25 |
| Looking for practice motors & extra tape drive parts? | archiver | 2000 | 1 | 23-06-2002 22:54 |
| "Motors and Drive train edition" of Fresh From the Forum | Ken Leung | CD Forum Support | 6 | 29-01-2002 12:32 |