ROBOTC.net forums
http://www.robotc.net/forums/

User Control buttons issue. Syntax issue?
http://www.robotc.net/forums/viewtopic.php?f=53&t=3097
Page 1 of 1

Author:  D1581A [ Wed Mar 09, 2011 12:02 pm ]
Post subject:  User Control buttons issue. Syntax issue?

So my team is attempting to get our robot to do a specified action during the user control portion of the competition that involves a potentiometer, and a ultrasonic sensor. Could someone just go through this code and see what if anything is wrong with it? Our issue basically is that the robot does nothing when the specified button. I want to rule out a programming issue before we start looking at the robot. When I compile it i get 0 errors so I thought the next best place to look would be here.

Thanks in advance.
Code:
task main()
{
    while (true)
  {
    //Wheel Motors
    motor[leftMotor] = (vexRT[Ch1] + vexRT[Ch3]);      //y-axis value: forward/backward motion
      motor[rightMotor] = (vexRT[Ch3] - vexRT[Ch1]);      //x-axis value: left/right steering
      //Arm Motors
      motor[leftarmMotor] = vexRT[Ch3Xmtr2];
      motor[rightarmMotor] = vexRT[Ch3Xmtr2];
      //Clamp Joystick
      motor[leftclampMotor] = -vexRT[Ch1Xmtr2];
      motor[rightclampMotor] = vexRT[Ch1Xmtr2];
  }

  {
    if (vexRT[btn5U] == 1)
    {
      if (SensorValue[armpotentiometer] < 655) //PLACE HOLDER VALUE: FIX (needs to be value of arm positioned to be just above the low scoring pole)
      {
        motor[leftarmMotor] = 127;
        motor[rightarmMotor] = 127;
      }
      else
      {
        motor[leftarmMotor] = 60; //USE VALUE TO HOLD ARM STEADY
        motor[rightarmMotor] = 60;
        if (SensorValue[ultrasonic] > 25) //PLACE HOLDER VALUE: FIX (needs to be the distance between the robot and the post best suited for immediate scoring
        {
          motor[leftMotor] = 90; //PLACE HOLDER VALUE (?) :FIX (change to speed suitable for moving towards the scoring pole)
          motor[rightMotor] = 90;
        }
        else
        {
          motor[leftMotor] = 0;
          motor[rightMotor] = 0;
        }
      }
    }
  }
}

Author:  bfeher [ Wed Mar 09, 2011 12:18 pm ]
Post subject:  Re: User Control buttons issue. Syntax issue?

Hi D1581A,

Thanks for posting your code nicely to the forum! It seems that your conditionals (checking for button presses) are outside of your while(true) loop.

The while(true) loop will continue forever, which prevents your code from ever getting past line 14 (as posted above).

Try including the if statements within the while(true) loop, by removing the '}' and '{' from lines 14 and 16 and see what happens:
Code:
task main()
{
  while (true)
  {
    //Wheel Motors
    motor[leftMotor] = (vexRT[Ch1] + vexRT[Ch3]);      //y-axis value: forward/backward motion
    motor[rightMotor] = (vexRT[Ch3] - vexRT[Ch1]);      //x-axis value: left/right steering
    //Arm Motors
    motor[leftarmMotor] = vexRT[Ch3Xmtr2];
    motor[rightarmMotor] = vexRT[Ch3Xmtr2];
    //Clamp Joystick
    motor[leftclampMotor] = -vexRT[Ch1Xmtr2];
    motor[rightclampMotor] = vexRT[Ch1Xmtr2];

    if (vexRT[btn5U] == 1)
    {
      if (SensorValue[armpotentiometer] < 655) //PLACE HOLDER VALUE: FIX (needs to be value of arm positioned to be just above the low scoring pole)
      {
        motor[leftarmMotor] = 127;
        motor[rightarmMotor] = 127;
      }
      else
      {
        motor[leftarmMotor] = 60; //USE VALUE TO HOLD ARM STEADY
        motor[rightarmMotor] = 60;
        if (SensorValue[ultrasonic] > 25) //PLACE HOLDER VALUE: FIX (needs to be the distance between the robot and the post best suited for immediate scoring
        {
          motor[leftMotor] = 90; //PLACE HOLDER VALUE (?) :FIX (change to speed suitable for moving towards the scoring pole)
          motor[rightMotor] = 90;
        }
        else
        {
          motor[leftMotor] = 0;
          motor[rightMotor] = 0;
        }
      }
    }
  }
}

Author:  D1581A [ Wed Mar 09, 2011 2:16 pm ]
Post subject:  Re: User Control buttons issue. Syntax issue?

Hi bfeher :)

Thanks for the quick reply, i'll give it a shot later today and see what happens.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/