Go to Post Off-topic: THIS IS THE REASON WHY I LOVE FIRST! - FlyingD662 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-01-2009, 14:29
mjcoss mjcoss is offline
Registered User
FRC #0303
 
Join Date: Jan 2009
Location: Bridgewater,NJ
Posts: 70
mjcoss is a jewel in the roughmjcoss is a jewel in the roughmjcoss is a jewel in the roughmjcoss is a jewel in the rough
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);
			}
         }
And yes I know that both triggers down isn't being handled.

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.
Reply With Quote
  #2   Spotlight this post!  
Unread 14-01-2009, 18:53
Eric Finn's Avatar
Eric Finn Eric Finn is offline
Registered User
FRC #0166 (Chop Shop)
Team Role: College Student
 
Join Date: May 2006
Rookie Year: 2005
Location: Merrimack, NH
Posts: 101
Eric Finn has a spectacular aura aboutEric Finn has a spectacular aura about
Send a message via AIM to Eric Finn
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);
 }
I recall something about only being able to set speed controllers every (5 or 10, not sure exactly how many) milliseconds. I'm not sure if the Set method will prevent you from setting a motor speed too often, or if that is handled in the FPGA. If this is handled in the Set method, then this should work where the code you showed us didn't.
__________________
It always takes longer than you expect, even when you take into account Hofstadter's Law.
--Hofstadter's Law

Reply With Quote
  #3   Spotlight this post!  
Unread 14-01-2009, 19:00
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
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);
You can do the same like this:
Code:
Joystick left_stick(1);//type joystick, variable name left_stick, port 1
Joystick right_stick(2);
Reply With Quote
  #4   Spotlight this post!  
Unread 15-01-2009, 10:52
mjcoss mjcoss is offline
Registered User
FRC #0303
 
Join Date: Jan 2009
Location: Bridgewater,NJ
Posts: 70
mjcoss is a jewel in the roughmjcoss is a jewel in the roughmjcoss is a jewel in the roughmjcoss is a jewel in the rough
Re: Wondering if anyone else is having an issue with Joysticks

Quote:
Originally Posted by Eric Finn View Post
I recall something about only being able to set speed controllers every (5 or 10, not sure exactly how many) milliseconds. I'm not sure if the Set method will prevent you from setting a motor speed too often, or if that is handled in the FPGA. If this is handled in the Set method, then this should work where the code you showed us didn't.
I'm an idiot.

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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is anyone else having this problem hpman247 Programming 10 27-11-2008 02:57
Anyone Else Having Problems with Q&A on FIRST? Windwarrior General Forum 6 25-01-2006 10:54
Anyone else having trouble keeping up with work? D. Gregory General Forum 36 28-03-2004 16:55
Anyone else having trouble with Yahoo mail services? Elgin Clock IT / Communications 12 20-03-2004 16:59
Anyone else having trouble with the pneumatics manual? Stu Bloom Pneumatics 15 13-01-2004 01:13


All times are GMT -5. The time now is 13:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi