Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   FIRST Tech Challenge (http://www.chiefdelphi.com/forums/forumdisplay.php?f=146)
-   -   [FTC]: Buttons RobotC (http://www.chiefdelphi.com/forums/showthread.php?t=79075)

JohnFogarty 25-11-2009 09:29

[FTC]: Buttons RobotC
 
I am trying to assign buttons to control a Tetrix DC motor when ever i assign 2 functions to control the same motor say one button forward and one backward the motor coughs and jumps and vibrates moving spastically. I attached the code below, how could i solve this problem?




if(joy2Btn(2) )
{
motor[motorF] = 100;
}
else
{
motor[motorF] = 0;
}

if(joy2Btn(1) )
{
motor[motorF] = -100;
}
else
{
motor[motorF] = 0;
}

emmell 25-11-2009 10:53

Re: [FTC]: Buttons RobotC
 
Let's break this down step by step:

Quote:

Originally Posted by John_1102 (Post 884213)
if(joy2Btn(2) )
{
motor[motorF] = 100;
}
else
{
motor[motorF] = 0;
}

What the above "if" is saying is "If Button 2 on Joystick 2 is pushed, set power to motorF to 100%. Otherwise, set it to 0".

Quote:

Originally Posted by John_1102 (Post 884213)
if(joy2Btn(1) )
{
motor[motorF] = -100;
}
else
{
motor[motorF] = 0;
}

This one is saying "if Button 1 on Joystick 2 is pushed, set power to motorF to 100% in reverse. Otherwise, set it to 0".

The problem is not with the if (true) conditions, it's the else conditions that are conflicting with each other. If Button 1 is pressed, then button might or might be pressed, so motorF shouldn't go (the else conditions). Likewise for Button 2.

A better way to right the code is:
Code:

if (joy2Btn(1))
    {
    motor[motorF] = -100;
    }
else if (joy2Btn(2))
  {
    motor[motorF] = 100;
  }
else
    {
    motor[motorF] = 0;
    }

Since the target of the conditional test is the same resource (motorF), you'll have to keep the tests with the target in one condition.

Good luck!

JohnFogarty 25-11-2009 19:13

Re: [FTC]: Buttons RobotC
 
Quote:

Originally Posted by emmell (Post 884224)
Let's break this down step by step:


What the above "if" is saying is "If Button 2 on Joystick 2 is pushed, set power to motorF to 100%. Otherwise, set it to 0".


This one is saying "if Button 1 on Joystick 2 is pushed, set power to motorF to 100% in reverse. Otherwise, set it to 0".

The problem is not with the if (true) conditions, it's the else conditions that are conflicting with each other. If Button 1 is pressed, then button might or might be pressed, so motorF shouldn't go (the else conditions). Likewise for Button 2.

A better way to right the code is:
Code:

if (joy2Btn(1))
    {
    motor[motorF] = -100;
    }
else if (joy2Btn(2))
  {
    motor[motorF] = 100;
  }
else
    {
    motor[motorF] = 0;
    }

Since the target of the conditional test is the same resource (motorF), you'll have to keep the tests with the target in one condition.

Good luck!

Thanks this worked perfectly


All times are GMT -5. The time now is 18:36.

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