View unanswered posts | View active topics It is currently Wed Aug 20, 2014 10:38 am






Reply to topic  [ 6 posts ] 
Paradoxes 
Author Message
Rookie

Joined: Tue Apr 09, 2013 4:44 pm
Posts: 3
Post Paradoxes
Could someone please help me with fixing this paradox in the script below.

if(joy1Btn(4) == 1)
{
motor[motorB] = 25;
}
else
{
motor[motorB] = 0;
}
if(joy1Btn(3) == 1)
{
motor[motorB] = -25;
}
else
{
motor[motorB] = 0;
}


Thanks,
Coog1 :-)


Tue Apr 09, 2013 4:49 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3188
Location: Rotterdam, The Netherlands
Post Re: Paradoxes
What's the paradox? What do you expect will happen when you press button 4 and 3 at the same time? What do you want to happen when you press those two buttons at once?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Apr 10, 2013 3:50 am
Profile WWW
Rookie

Joined: Tue Apr 09, 2013 4:44 pm
Posts: 3
Post Re: Paradoxes
The problem is that the first part of the program ( e.g. if(joy1Btn(4) == 1) {motor[motorB] = 25;}else{motor[motorB] = 0;} ) is conflicting with the second part ( e.g. if(joy1Btn(3) == 1){motor[motorB] = -25;}else{motor[motorB] = 0;} ) by telling motorB to not move when button 3 is not pressed, but hten when I press button 4 without pressing button 3 then the program needs to fight itself.


Wed Apr 10, 2013 4:13 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3188
Location: Rotterdam, The Netherlands
Post Re: Paradoxes
So how will you fix that problem? What do you want to happen when both buttons are pressed? Nothing? Anything?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Apr 10, 2013 4:31 pm
Profile WWW
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 22
Location: Pittsburgh, Pa
Post Re: Paradoxes
One way to not have it switch from 25 to -25 rapidly is to have it do something else when both buttons are pushed at the same time:
Code:
if 1st button pressed and(&&) 2nd button pressed
   do thing 3; (or nothing depending what you want to happen)
else if 1st button pressed
   do thing 1;
else if 2nd button pressed
   do thing 2;
else
   do thing 3;


Another way to prevent this is to check whether only one button is pushed:
Code:
if 1st button pressed and 2nd button not pressed
      do thing 1;
else if 2nd button pressed and 1st button not pressed
   do thing 2;
else
   do thing 3;


And if you want to keep your code then try:
Code:
if 1st button pressed and 2nd button not pressed
   do thing 1;
else
   do thing 3;
if 2nd button pressed and 1st button not pressed
   do thing 2;
else
   do thing 3;


There are a few ways to check that a button is not pressed.
Try:

Code:
joy1Btn(number) != 1

or

joy1Btn(number) == 0

_________________
SHARP
Sarah Heinz Advanced Robotics Program

VEX 889A and FIRST 3260

Pittsburgh Champions Aerial Assist 2014
Pittsburgh and Buckeye Finalist Ultimate Ascent 2013
Toss Up Champions and Excellence-Pittsburgh
Toss Up Champions-Northwest Maryland VRC


Wed Apr 10, 2013 7:09 pm
Profile
Rookie

Joined: Tue Apr 09, 2013 4:44 pm
Posts: 3
Post Re: Paradoxes
Thanks so much Kevin, it worked like a dream.

Coog1


Sat Apr 13, 2013 11:08 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.