View unanswered posts | View active topics It is currently Wed Oct 22, 2014 12:06 pm






Reply to topic  [ 6 posts ] 
READ UPDATE Control Location of where the arm is?? 
Author Message
Rookie

Joined: Sat Jan 08, 2011 6:56 pm
Posts: 7
Post READ UPDATE Control Location of where the arm is??
Ok So me and my team(We take part in BEST) are working on some possible designs for next years competition.
What we would like to do is be able hit a button and the arm on a robot go to a predetermined location.
As you know with BEST we are not given potentiometers or shaft encoders so we cant use those.
We were thinking about attaching a '+' shaped piece to the smaller of the 2 gears that we will use to move the arm (where the 2 line of the '+' cross would be the center of the gear)
We would use this '+' to hit a Limit switch every time a spoke came around to it.

I want to have some code to be able to tell where the arm is at.
What I was thinking is to having if statements that said something like

if the switch is pushed (resulting in a 1) and the motor value is positive then add 1 to the variable 'position'
if the switch is pushed and the motor value is negative then subtract 1 from the variable 'position'

that way I can use the variable 'position' later on in the code to tell it where to go.

so can some one help me out with the code for the if statements???

also if this is not a good way to try to do this could you provide an alternate solution to this problem

In the end we want to be able to make our arm go to 4 different positions no mater where its current location (1of the 4 locations) by the push of a button



UPDATE:

OK MagiCode: Your code works great! Thanks You for it!

we werent reall able to get "RobotDesigners" code to work. also we would really like to only use one limit switch

we have however come up with a gear system so that we can have about 64 points instead of the 4 that I first mentioned.

I have come up with some code (it may not be correct at all but it seems like something that could work)


heres the code i came up with to try to make it work with one limit switch.
hopefully you can understand it.


Code:
//lim1 is my limit switch and leftMotor is my motor im using
int armPos = 0; //This is position of the arm. it is found by Task armCount
int dir = 1; // this is the direction for use in Task armCount. (1 its moving clockwise -1 for counter clockwise

void move (int goTo) //this is supposed to be a function for moving my arm while also keeping up with the direction
{
  while (armPos != goTo) // this is supposed to be a while loop that as long as the armPos in not equal to where I want the arm to go
  {
    if (armPos < goTo)  //this is supposed to say if the armPos is less than the number position I want it to go to
    {
      dir = 1;  // this is supposed to make dir equal to 1
      motor[leftMotor] = 127; // this is supposed to make the motor go full powe forward
    }
    else if (armPos > goTo) //this is supposed to say if the armPos is greater than the number position I want it to go to
    {
      dir = -1; // this is supposed to make dir equal to -1
      motor[leftMotor] = -127; // this is supposed to make the motor go full power reverse
    }
    else if (armPos == goTo)
    {
      //Do Nothing
    }
  }
}
   


task armCount() //this is code by "magicode" and seems to work very well
{
 while(true){
    while(SensorValue(lim1) == 0)
    {
      wait1Msec(1);
    }
    while(SensorValue(lim1) == 1)
    {
      wait1Msec(1);
    }
    hogCPU();
    armPos = (armPos + dir); // i edited it right here from armPos++; so that if dir is negitive it subtract one from armPos keeping up with the position of the arm
    releaseCPU();
  }
}


task main()
{
  StartTask(armCount); // this starts the task armCount which it seems to do perfectly
  while(true)
  {
 
    if (vexRT[Btn7U]==1) //this is supposed to make the arm go to position 4 if  Button 7U is pushed
    {
      move(4);
    }
    if (vexRT[Btn7R] == 1) //same as above but to position 2
    {
      move(2);
    }
    if (vexRT[Btn7D] == 1 )// same as above but to positon 6
    {
      move(6);
    }
  }
}
   


Last edited by tcrenshaw4bama on Thu Feb 03, 2011 8:55 pm, edited 1 time in total.



Tue Jan 18, 2011 9:01 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Control Location of where the arm is??
A similar question had come up on the vex forum. My answer to that was:
"If you have a limit switch, it is possible to make an encoder. It won't be extremely precise, but it will get the job done. Take a gear, and screw small standoffs around the circumference at even intervals. Then put this gear on the shaft that drives your motor. Position a limit switch so that it clicks every time a standoff is pushed into it, and then is released when that standoff has passed." using a crossbar might not give you enough resolution, because you only have 4 clicks per revolution, which is hardly useful. As for the code, this might be a situation where you want to use multitasking. Here is the code I would use:
Code:
//the name of the limit switch is "lim"
int armPos = 0;

//keeps count of the armPosition
task encoderCount(){
  while(true){
    while(SensorValue(lim) == 0){
      wait1Msec(1);
    }
    while(sensorValue(lim) == 1){
      wait1Msec(1);
    }
    hogCPU();
    armPos++;
    releaseCPU();
  }
}

task main(){
  StartTask(encoderCount);
  while(armPos < 40){
    motor[arm] = 127;
  }
}


I wrote this straight out of my head without robotC, so some syntax might be off.

Now this will function as an encoder, but it won't be quadrature(it won't give you the direction of motion). just relying on the positive and negative motor values doesn't work, because the motor value "motor[port1]" is what power you're telling the motor to go, not what power it is turning at. so if you set the arm encoder count 12, and it starts lowering because of weight, the motor value will still be zero even though the arm is moving, you didn't assign the motor a power value. I can't think of a simple way to do this without a servo, potentiometer, encoder, color sensor, line follower, or ultrasonics to get quadrature capabilities. Sorry.

_________________
sudo rm -rf /


Tue Jan 18, 2011 10:34 pm
Profile
Novice
User avatar

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Post Re: Control Location of where the arm is??
magicode wrote:
Now this will function as an encoder, but it won't be quadrature(it won't give you the direction of motion). just relying on the positive and negative motor values doesn't work, because the motor value "motor[port1]" is what power you're telling the motor to go, not what power it is turning at. so if you set the arm encoder count 12, and it starts lowering because of weight, the motor value will still be zero even though the arm is moving, you didn't assign the motor a power value. I can't think of a simple way to do this without a servo, potentiometer, encoder, color sensor, line follower, or ultrasonics to get quadrature capabilities. Sorry.

What if you used two limit switches? (The VEX Inventor's Guide insert on the quad encoders give a basic overview of how quad encoders work)

The two switches would be offset by x degrees (it doesn't matter how many, as long as both sensors aren't pressed at the same time). If switch 1 is contacted, then switch 2, the axle is rotating one way. If switch 2 is contacted, then switch 1, the axle is rotating the other way.

Here's a diagram (the red things are limit switches, the black parts are gear/standoff):
Attachment:
File comment: Diagram of encoder
makeshift-encoder.jpg
makeshift-encoder.jpg [ 15.02 KiB | Viewed 2461 times ]


Some code to find the direction (magicode's code would need to be modified to account for multiple directions) (there may be a more efficient way to do what I'm doing, and this was written free-hand):
Code:
//Notes:
//  * Switches are lim and lim2
//  * lim is the upper switch in the diagram, and lim2 is the lower switch

int direction = 0; //0 if not moving, 1 if moving clockwise, 2 if moving counter-clockwise

void waitRelease(int switch)
{
  if (switch == 1)
  {
    while(SensorValue[lim] == 1)
    {
      //Do nothing
    }
  }
  else if (switch == 2)
  {
    while(SensorValue[lim2] == 1)
    {
      //Do nothing
    }
  }
}

task direction()
{
  //These two variables will be equal to 1 or 2, depending on which limit was pressed first.
  int lastPress = 1;
  int pressed = 1;
 
  int i = 0;

  while(true)
  {
    lastPress = pressed;

    if(SensorValue[lim] == 1)
    {
      pressed = 1;
      waitRelease(1);
    }
    else if(SensorValue[lim2] == 1)
    {
      pressed = 2;
      waitRelease(2);
    }
   
    i++;

    if (i=1) exitLoop(); //Not sure what the real code is for this...

    if ((lastPress - pressed) == 1)
    {
      //Clockwise
      direction = 1;
    }
    else if((lastPress - pressed) == -1)
    {
      //Counter-clockwise
      direction = 2;
    }
    else if((lastPress - pressed) == 0)
    {
      //Not moving
      direction = 0;
    }
  }
}

_________________
Check out my website! www.RoboDesigners.com

VRC Team 2190

Twitter: @RoboDesigners


Tue Jan 18, 2011 11:39 pm
Profile WWW
Rookie

Joined: Sat Jan 08, 2011 6:56 pm
Posts: 7
Post Re: READ UPDATE Control Location of where the arm is??
See Update in First Post


Thu Feb 03, 2011 8:57 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: READ UPDATE Control Location of where the arm is??
Congratulations on getting the design to work. I'm glad that I could help out. From what I can see, the code that you've posted should work fine as long as the arm maintains it's position when the motor isn't moving. But think about the following situation: You tell the motor to go at 127 from 0 until the encoder count reaches 20, and then stop. So your dir is positive 1. Then, if the arm starts to go down because of it's own weight, when it hits the limit switch, it will still add to it's position instead of subtracting from it because your dir is still positive.

I would like to say a few things about the code to make your life easier. You should have a Wait1MSec(1) somewhere in your while(true) loop in your main task. This helps multitasking take place. Second, in your move function, you say if(statement) motor = 127, if else statement motor = -127, else do nothing. You should probably have a motor = 0 instead of a do nothing, because there is a chance that the motor will keep on running if it's not explicitly told to stop.

And some tiny probably useless details: when saying x = x + y, you can use x += y. same for -=, *=, /=, and %=. it doesn't rally matter for what you're doing now, but it can simplify things in long ugly equations. And just for future reference, instead of saying if(vexRT[Btn7R] == 1), you can just say if(vexRT[Btn7R]) because the expression will equate to true or false.

_________________
sudo rm -rf /


Thu Feb 03, 2011 11:42 pm
Profile
Rookie

Joined: Sat Jan 08, 2011 6:56 pm
Posts: 7
Post Re: READ UPDATE Control Location of where the arm is??
Ok well the code didnt really work as planed but with some tweaking i finally got it working perfectly.
and as far as the arm moving when it shouldnt. i dont think that will be a big problem because most likely we wont be picking up any thing too heavy
thanks so much for all your help on this magicode!!!


Fri Feb 04, 2011 10:25 pm
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.