View unanswered posts | View active topics It is currently Sat Dec 27, 2014 11:34 am






Reply to topic  [ 3 posts ] 
User Control buttons issue. Syntax issue? 
Author Message
Rookie

Joined: Tue Dec 14, 2010 4:50 pm
Posts: 3
Post 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;
        }
      }
    }
  }
}


Wed Mar 09, 2011 12:02 pm
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post 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;
        }
      }
    }
  }
}

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Wed Mar 09, 2011 12:18 pm
Profile
Rookie

Joined: Tue Dec 14, 2010 4:50 pm
Posts: 3
Post 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.


Wed Mar 09, 2011 2:16 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.