View unanswered posts | View active topics It is currently Fri Apr 18, 2014 10:38 am






Reply to topic  [ 9 posts ] 
Robot Trouble 
Author Message
Rookie

Joined: Mon Nov 07, 2011 2:01 pm
Posts: 5
Post Robot Trouble
Having trouble codeing my teams robot for VEX. The arms and gripping device are not following command to the Duel joystick controller. They continue to move even after the buttons are released :breakcomputer: . If anyone can help me PLEASE HELP


Mon Nov 07, 2011 2:06 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Robot Trouble
The more detail that you give, the more help that you will get. What exactly do you want the robot to do? What have you already tried? Post the code that you have tried so we can see if that is the source of the problem.

_________________
sudo rm -rf /


Mon Nov 07, 2011 2:29 pm
Profile
Rookie

Joined: Mon Nov 07, 2011 2:01 pm
Posts: 5
Post Re: Robot Trouble
i want to make it to where if you release the button it stops and if you press the button it goes


while (true)
{
{
int threshold = 10; // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)
// feel free to change this to match your needs.

while(1 == 1)
{
if(abs(vexRT[Ch3]) > threshold) // If the left joystick is greater than or less than the threshold:
{
motor[leftMotor] = (vexRT[Ch3]); // Left Joystick Y value / 2.
}
else // If the left joystick is within the threshold:
{
motor[leftMotor] = 0; // Stop the left motor (cancel noise)
}

if(abs(vexRT[Ch2]) > threshold) // If the right joystick is greater than or less than the threshold:

motor[rightMotor] = (vexRT[Ch2]); // Right Joystick Y value / 2.

else // If the right joystick is within the threshold:
{
motor[rightMotor] = 0; // Stop the right motor (cancel noise)
}
while(vexRT[Btn5D] == 1){
motor[port2] = 127;
motor[port9] = -127;
}

while(vexRT[Btn5U] == 1){
motor[port2] = -127;
motor[port9] = 127;}



while(vexRT[Btn6D] == 1){
motor[port8] = 60;

}

while(vexRT[Btn6U] == 1){
motor[port8] = -60;


}


Mon Nov 07, 2011 2:57 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Robot Trouble
Fist of all, lets put your code into properly spaced formatting so that it's easier to see what is in the scope of what:
Code:
while (true)
{
  {
    int threshold = 10; // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)
    // feel free to change this to match your needs.

    while(1 == 1)
    {
      if(abs(vexRT[Ch3]) > threshold) // If the left joystick is greater than or less than the threshold:
      {
        motor[leftMotor] = (vexRT[Ch3]); // Left Joystick Y value / 2.
      }
      else // If the left joystick is within the threshold:
      {
        motor[leftMotor] = 0; // Stop the left motor (cancel noise)
      }

      if(abs(vexRT[Ch2]) > threshold) // If the right joystick is greater than or less than the threshold:

      motor[rightMotor] = (vexRT[Ch2]); // Right Joystick Y value / 2.

      else // If the right joystick is within the threshold:
      {
        motor[rightMotor] = 0; // Stop the right motor (cancel noise)
      }
      while(vexRT[Btn5D] == 1){
        motor[port2] = 127;
        motor[port9] = -127;
      }

      while(vexRT[Btn5U] == 1){
      motor[port2] = -127;
      motor[port9] = 127;}

      while(vexRT[Btn6D] == 1){
        motor[port8] = 60;
      }

      while(vexRT[Btn6U] == 1){
        motor[port8] = -60;


      }


The reason that your motors do not stop when you release the button, is because you never tell your motors to stop. The motors will keep doing what you told them to do last until you tell them otherwise. You have to explicitly set them to 0 when the button is released. Also, you may want to look into why you have two while loops.
Just as a side note, after looking at this code, I have to wonder if more than one person worked on this, as you have different coding customs in the same piece of code. Not that there is anything wrong with that, but it might be easier to understand if everything in a single program is formatted the same way.

_________________
sudo rm -rf /


Mon Nov 07, 2011 5:47 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Robot Trouble
Fist of all, lets put your code into properly spaced formatting so that it's easier to see what is in the scope of what:
Code:
while (true)
{
  {
    int threshold = 10; // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)
    // feel free to change this to match your needs.

    while(1 == 1)
    {
      if(abs(vexRT[Ch3]) > threshold) // If the left joystick is greater than or less than the threshold:
      {
        motor[leftMotor] = (vexRT[Ch3]); // Left Joystick Y value / 2.
      }
      else // If the left joystick is within the threshold:
      {
        motor[leftMotor] = 0; // Stop the left motor (cancel noise)
      }

      if(abs(vexRT[Ch2]) > threshold) // If the right joystick is greater than or less than the threshold:

      motor[rightMotor] = (vexRT[Ch2]); // Right Joystick Y value / 2.

      else // If the right joystick is within the threshold:
      {
        motor[rightMotor] = 0; // Stop the right motor (cancel noise)
      }
      while(vexRT[Btn5D] == 1){
        motor[port2] = 127;
        motor[port9] = -127;
      }

      while(vexRT[Btn5U] == 1){
      motor[port2] = -127;
      motor[port9] = 127;}

      while(vexRT[Btn6D] == 1){
        motor[port8] = 60;
      }

      while(vexRT[Btn6U] == 1){
        motor[port8] = -60;


      }


The reason that your motors do not stop when you release the button, is because you never tell your motors to stop. The motors will keep doing what you told them to do last until you tell them otherwise. You have to explicitly set them to 0 when the button is released. Also, you may want to look into why you have two while loops.
Just as a side note, after looking at this code, I have to wonder if more than one person worked on this, as you have different coding customs in the same piece of code. Not that there is anything wrong with that, but it might be easier to understand if everything in a single program is formatted the same way.

_________________
sudo rm -rf /


Mon Nov 07, 2011 5:47 pm
Profile
Rookie

Joined: Mon Nov 07, 2011 2:01 pm
Posts: 5
Post Re: Robot Trouble
More than one person worked on this and thank you for helping


Mon Nov 07, 2011 5:52 pm
Profile
Rookie

Joined: Mon Nov 07, 2011 2:01 pm
Posts: 5
Post Re: Robot Trouble
would it be too much to ask someone to edit my code to make buttons 5U and 5D and 6U and 6D stop when buttons not being pressed. we don't have any programmers on our team.


Mon Nov 07, 2011 8:33 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Robot Trouble
Try replacing this part of your code:
Code:
while(vexRT[Btn5D] == 1){
        motor[port2] = 127;
        motor[port9] = -127;
      }

      while(vexRT[Btn5U] == 1){
      motor[port2] = -127;
      motor[port9] = 127;}

      while(vexRT[Btn6D] == 1){
        motor[port8] = 60;
      }

      while(vexRT[Btn6U] == 1){
        motor[port8] = -60;


      }


With this:
Code:
      if(vexRT[Btn5D] == 1){
        motor[port2] = 127;
        motor[port9] = -127;
      }
      else if(vexRT[Btn5U] == 1){
        motor[port2] = -127;
        motor[port9] = 127;
      }
      else{
        motor[port2] = 0;
        motor[port9] = 0;
      }

      if(vexRT[Btn6D] == 1){
        motor[port8] = 60;
      }
      else if(vexRT[Btn6U] == 1){
        motor[port8] = -60;
      }
      else{
        motor[port8] = 0;
      }

_________________
sudo rm -rf /


Mon Nov 07, 2011 9:59 pm
Profile
Rookie

Joined: Mon Nov 07, 2011 2:01 pm
Posts: 5
Post Re: Robot Trouble
Thank you alot this will help alot.


Mon Nov 07, 2011 10:04 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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:  
cron



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