|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Programming joysticks
Quote:
|
|
#2
|
|||||
|
|||||
|
Re: Programming joysticks
well, the count of buttons on thejoistick does not equal the count of buttons in the program. and it is the odd man out.
|
|
#3
|
||||
|
||||
|
Re: Programming joysticks
The joystick's POV hat takes the place of the "pN_wheel", where N is the number of the joystick port you're using. I can only really speak for the joystick which I have right in front of me (the other is at my house, being used to play TIE Fighter
), so YMMV. The two least significant bits of the value change too erratically to be of any use. Here's a listing of the values of the variable when the POV hat is in different positions:Neutral: 001011xx Up Left: 111111xx Up: 111111xx Up Right: 111111xx Left: 011000xx Right: 110010xx Down Left: 101001xx Down: 100101xx Down Right: 110101xx The x's take the place of the two least significant bits, which, as I said earlier, change randomly (at least with this single joystick). Basically, if you can understand binary, you can take advantage of the POV hat for controlling your robot. Hope this helps. |
|
#4
|
||||
|
||||
|
Re: Programming joysticks
Quote:
|
|
#5
|
|||||
|
|||||
|
Re: Programming joysticks
So the bit masks are:
Code:
const unsigned char Hat_None = 0x2C; const unsigned char Hat_Up = 0xFC; const unsigned char Hat_Left = 0x60; const unsigned char Hat_Right = 0xC0; const unsigned char Hat_Down = 0x94; //Unless values are off, Combos aren't OR'ed const unsigned char Hat_Up_Left = 0xFC; const unsigned char Hat_Up_Right = 0xFC; const unsigned char Hat_Down_Left = 0xA4; const unsigned char Hat_Down_Right = 0xD4; ![]() |
|
#6
|
|||
|
|||
|
I have a question, how could I add the right lines of code to make the POV hats work with the new C language this year? Amonst other things, where would I have to define them and map them to the right IO ports to work with the hex/bin input signal?
|
|
#7
|
||||||
|
||||||
|
Re: Programming joysticks
Quote:
|
|
#8
|
||||
|
||||
|
Re: Programming joysticks
Quote:
Code:
if( (p1_wheel & 0xC0) == 0xC0 )
{
//hat control is pushed right
}
else if( (p1_wheel & 0xA4) == 0xA4 )
{
//hat control is pushed down-left
}
...
et cetera
...
Last edited by deltacoder1020 : 02-02-2004 at 12:49. |
|
#9
|
|||
|
|||
|
Re: Programming joysticks
Thanks, that helped a lot. I am just starting out with C so i'm still a little sketchy with it.
|
|
#10
|
||||
|
||||
|
Re: Programming joysticks
no prob. if you want a review on the syntax of C, you could try the various guides in the whitepapers section, or the guide that I'm working on (see the thread in this forum titled "FIRST Programming Tutorial")
|
|
#11
|
||||
|
||||
|
Re: Programming joysticks
Quote:
If you push the hat up by your code then it will default to the first conditional statement you put in. A more correct way might be to do it this way (using constants provided courtesy of Astronouth7303) Code:
switch (px_wheel & 0xFC) {
case Hat_Up_Left: {
// ... Code here
break;
}
case Hat_Up_Right: {
// ... Code here
break;
}
// etc...
default: {
break;
}
}
|
|
#12
|
||||
|
||||
|
Re: Programming joysticks
Could someone help me out?
What I need is for someone to do out the etc. part of the if( (p1_wheel & 0xC0) == 0xC0 ) { //hat control is pushed right } else if( (p1_wheel & 0xA4) == 0xA4 ) { //hat control is pushed down-left } ... et cetera ... thing so I can do this right. I'm a tad but slow when it comes to binary and hex ![]() |
|
#13
|
||||
|
||||
|
Re: Programming joysticks
here they are in binary, decimal, and hex forms...
Neutral: 001011xx 44 0x2C Up Left: 111111xx 252 0xFC Up: 111111xx 252 0xFC Up Right: 111111xx 252 0xFC Left: 011000xx 96 0x60 Right: 110010xx 200 0xCB Down Left: 101001xx 164 0xA4 Down: 100101xx 148 0x94 Down Right: 110101xx 212 0xD4 Last edited by deltacoder1020 : 16-02-2004 at 00:08. |
|
#14
|
|||
|
|||
|
Re: Programming joysticks
Here's a diagram that gives the full range of values and the value to test with AND is bold.
252-255*252-255*252-255 *96-99***44-47**200-203 164-167*148-151*212-215 |
|
#15
|
||||
|
||||
|
Re: Programming joysticks
Because the last bits are unreliable (from what i've read), how will this affect the program? Should I stick with a general area? example:
Code:
if (p1_wheel >= 42 && p1_wheel <= 46)
// I am neutral
if (p1_wheel >= 250 && p1_wheel <= 254)
// I am upperleft;
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Compatition | Angela06 | Programming | 30 | 08-04-2005 23:12 |
| Could use some help with joysticks . . . | archiver | 2001 | 5 | 23-06-2002 23:36 |
| Pneumatics electrical wiring and programming | archiver | 2001 | 1 | 23-06-2002 23:10 |
| Calibrating speed controllers and joysticks | thedillybar | Technical Discussion | 4 | 11-02-2002 13:24 |
| pbasic programming | punarhero | Programming | 4 | 21-01-2002 23:32 |