|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Wondering if anyone else is having an issue with Joysticks
I'm writing some code to help the team prototype some drivetrain ideas. As a quick hack, I defined 2 joysticks and was going to use the joystick triggers to control some steering motors. I'm using the WindRiver workbench, and I used the simple template. In the OperatorControl() function I created 2 Joystick objects, and used GetTrigger(). Doing something like this:
Code:
Joystick *left_stick, *right_stick;
left_stick = Joystick::GetStickfromPort(1);
right_stick = Joystick::GetStickfromPort(2);
while(isOperatorControll()) {
if(left_stick->GetTrigger()) {
left_steer.Set(.5);
right_steer.Set(.5);
}
else {
left_steer.Set(0.0);
right_steer.Set(0.0);
}
if(right_stick->GetTrigger()) {
left_steer.Set(-.5);
right_steer.Set(-.5);
}
else {
left_steer.Set(0.0);
right_steer.Set(0.0);
}
}
The odd thing is that the left_stick trigger works just fine (turning on/off the motors), but the right_stick trigger doesn't work at all. Commenting out the left_stick GetTrigger() block of code, and now the right trigger starts working. I've tried allocating the joystick on the stack, using new directly, etc. Bottom line is that I can get only one trigger working at a time. I'm using the KOP joysticks. I'm going to hook up a serial port and put some debug prints but was curious if anyone else is seeing the same thing. I do know that the the GetAxis functions are working because, using the same declarations for the joysticks, I was able to get the TankDrive() function to work properly. |
|
#2
|
|||||
|
|||||
|
Re: Wondering if anyone else is having an issue with Joysticks
Try this:
Code:
Joystick *left_stick, *right_stick;
left_stick = Joystick::GetStickfromPort(1);
right_stick = Joystick::GetStickfromPort(2);
float SetValue = 0;
while(isOperatorControll()) {
SetValue = 0;
if(left_stick->GetTrigger()) SetValue = .5;
if(right_stick->GetTrigger()) SetValue = -.5;
left_steer.Set(SetValue);
right_steer.Set(SetValue);
}
|
|
#3
|
||||
|
||||
|
Re: Wondering if anyone else is having an issue with Joysticks
You don't have to declare them like this
Code:
Joystick *left_stick, *right_stick; left_stick = Joystick::GetStickfromPort(1); right_stick = Joystick::GetStickfromPort(2); Code:
Joystick left_stick(1);//type joystick, variable name left_stick, port 1 Joystick right_stick(2); |
|
#4
|
|||
|
|||
|
Re: Wondering if anyone else is having an issue with Joysticks
Quote:
Obvious logic problem with the second logic block, which will stop the motor via the else clause because only one trigger was pushed, at a time. And you get the results I was seeing. One trigger works. As a side note, I had already changed to code to something similar to what you proposed, and it does indeed work because it removes the logic flaw, and has nothing to do with the frequency of the call to the set method. Although, now I'm curious about timing issues with the OperatorControl() function. Do you need to control update rates? And to byteit101, I'm aware that there are several methods, no pun intended, for declaring and allocating variables. One is allocated on the stack, the other is a pointer and is allocated in memory. Either method works just fine. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is anyone else having this problem | hpman247 | Programming | 10 | 11-27-2008 02:57 AM |
| Anyone Else Having Problems with Q&A on FIRST? | Windwarrior | General Forum | 6 | 01-25-2006 10:54 AM |
| Anyone else having trouble keeping up with work? | D. Gregory | General Forum | 36 | 03-28-2004 04:55 PM |
| Anyone else having trouble with Yahoo mail services? | Elgin Clock | IT / Communications | 12 | 03-20-2004 04:59 PM |
| Anyone else having trouble with the pneumatics manual? | Stu Bloom | Pneumatics | 15 | 01-13-2004 01:13 AM |