Go to Post Gotta love the blurred robots :cool: - Steven Donow [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 12-02-2009, 09:12
mahmosh's Avatar
mahmosh mahmosh is offline
Registered User
FRC #1946
 
Join Date: Jan 2008
Location: israel
Posts: 125
mahmosh is an unknown quantity at this point
problem while programming 2 bottuns in windriver

hey
we are trying to do 2 buttons for the same motor if button 1 pressed move forward .. else stop ... and then if button 2 pressed move backward else stop
here is the code we are using but it doesn't work well :

in the operatorcontrol we put this:
Code:
if(leftjoystick->GetRawButton(1));
{
jaguar->Set(1.0);
}
else{
jaguar->Set(0.0);
}
 
if(leftjoystick->GetRawButton(2));
{
jaguar->Set(-1.0);
}
else{
jaguar->Set(0.0);
}
what is the problem with this ?? if we deleted the second part
Code:
if(leftjoystick->GetRawButton(2));
{
jaguar->Set(-1.0);
}
else{
jaguar->Set(0.0);
}
everything working ok!!

please need answer

Last edited by mahmosh : 12-02-2009 at 09:14.
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2009, 09:27
wt200999's Avatar
wt200999 wt200999 is offline
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 323
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: problem while programming 2 bottuns in windriver

Its a logic error, if you hold down button 1, then that will set the motor to 1, then since button 2 is not held down it will go to that else which will set it back to 0.
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2009, 09:42
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: problem while programming 2 bottuns in windriver

Because you have two separate if...else statements, if the reverse button isn't held down, the output will be zero regardless of the forward button's state.

Also, this:
Code:
if (condition);
has no code to execute because of that trailing semicolon. An "if" will execute the statement immediately after it up until a semicolon, or if you put the code inside {curly braces}, it will execute everything in the first set of braces. If statements don't need any additional semicolons.

A quick rewrite yields this:

Code:
if(leftjoystick->GetRawButton(1))
{
jaguar->Set(1.0);
}
else if (leftjoystick->GetRawButton(2)) {
jaguar->Set(-1.0);
} else {
jaguar->Set(0.0);
}
That will work.

Alan Anderson let me know that I messed up. I misread your code snippet: I didn't realize that the reverse button would drive the motor in reverse... (crosses eyes) I really need some more sleep.

Let me know if you have any more questions or problems.

Jacob
__________________
Aren't signatures a bit outdated?

Last edited by JBotAlan : 12-02-2009 at 17:21. Reason: Oops.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2009, 12:25
mahmosh's Avatar
mahmosh mahmosh is offline
Registered User
FRC #1946
 
Join Date: Jan 2008
Location: israel
Posts: 125
mahmosh is an unknown quantity at this point
Re: problem while programming 2 bottuns in windriver

thank you it works well .... if i have any questions i will ask here
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
WindRiver Programming Template kyungjin C/C++ 0 24-01-2009 16:42
Potentiometer on cRIO, Programming in Windriver sircedric4 C/C++ 3 20-01-2009 06:42
WindRiver Programming dnrobotics11 C/C++ 1 19-01-2009 20:13
WindRiver Programming dnrobotics11 C/C++ 4 19-01-2009 19:43
Problem debugging code with WindRiver LinuxMercedes Programming 3 07-01-2009 11:10


All times are GMT -5. The time now is 02:50.

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