View Single Post
  #2   Spotlight this post!  
Unread 22-07-2012, 19:29
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: VEX Cortex RobotC help

There are three different pieces of code you want:

-The drivetrain
-The arm
-The roller

They will all run in a while(1) loop.

The drivetrain is fairly simple. Your code is already correct, although it is likely you will need to invert some of the motors (via trial and error).

The arm has two possible control modes with a servo:
-Bumping the position with the two buttons to make it act like a motor that holds position
-Setting specific positions with buttons.
It is also possible that a servo will not have enough torque to move an arm of significant size. Depending on how much motion you need, you can gear it down (you have 180degrees of range on the servo, if you only need 60 you can gear it 12:36).

In the first case, you would do something like this:
Code:
//Outside of task main:
int servopos = 0;//Starting position


//Inside of while(1):
//Add or subtract a constant if the button is pressed
if(vexRT[Btnx]) servopos += 10;
if(vexRT[Btny]) servopos -= 10;
//Limit servopos to +-127 range
if(servopos > 127) servopos = 127;
if(servopos < -127) servopos = -127;
//Set motor to servopos
motor[armServo] = servopos;
In the second case, you would do something like this:
Code:
//Outside of task main:
int servopos = 0;//Starting position


//Inside of while(1):
if(vexRT[Btnx]) servopos = 20;//This is one possible position
if(vexRT[Btny]) servopos = -50;//This is another position
if(vexRT[Btnz]) servopos = 100;//This is yet another position
//You can have more if you want.
//Set motor to servopos
motor[armServo] = servopos;
You should definitely see if you have enough torque to move your arm with a servo, and possibly gear it down if you don't need the full range. You can do this empirically (by trying it and seeing if it works) or mathematically (by calculating the torque you will need based on the design and seeing if it matches up to the servo specs on vexrobotics.com). If you can, I highly recommend using the latex tubing or rubber bands to counterforce the load on the arm, reducing the servo load.

The roller is easy:
Code:
//Inside of while(1):
int roller = 0;
if(vexRT[Btnx]) roller = 127;
motor[rollerMotor] = roller;

Please note that you will need to find the correct button name to put inside vexRT[].
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack