OCCRA
Go to Post All tools are powered by magic angry noise. - artdutra04 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-22-2012, 05:30 PM
joelg236 joelg236 is offline
Registered User
AKA: Joel Gallant
no team
Team Role: Alumni
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 678
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
VEX Cortex RobotC help

Hello everyone,

I am working on a the code for a VEX robot, using RobotC for Cortex. I have never used C, C++ let alone robotc (Java is my primary language). So far, I am having a tough time understanding how to write the code for our robot.

I'll give you a description of what it is and what I'd like it to do. It is a 4 wheeled robot with an arm controllable by 1 servo (We only had 5 motors and the arm was the only part that only had to move a certain degree). There is an intake that has 1 motor to control it.

So, the tl;dr version is 4 motors for driving, 1 servo to move the arm and 1 motor to do intake.

What I want to do is do tank drive on the 4 motors, have the two triggers (Equivalent to R1 and L1 on PS3) move the arm up and down, and have the "A" button turn on the intake.

I havn't been able to get much past the template. I have the 4 motor tank drive working, but that's it.

Code:
#pragma config(Motor,  port2,           frontRightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port3,           backRightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           frontLeftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port5,           backLeftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port6,           armServo, tmotorServoStandard, openLoop)

task main()
{
  while(1 == 1)
  {
    //Right side of the robot is controlled by the right joystick, Y-axis
    motor[frontRightMotor] = vexRT[Ch2];
    motor[backRightMotor]  = vexRT[Ch2];
    //Left side of the robot is controlled by the left joystick, Y-axis
    motor[frontLeftMotor] = vexRT[Ch3];
    motor[backLeftMotor]  = vexRT[Ch3];
    
    //Servo?
    
    //Intake?
    
  }
}
I can answer any questions that might help you understand what I'm trying to do. Need this to be done this week (5 days) and I don't have enough time in the day to learn a lot of the syntax. All help is appreciated.

Thanks!

Joel
__________________
Team 4334 2012-2014
  #2   Spotlight this post!  
Unread 07-22-2012, 06:29 PM
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
FRC #0033 (Killer Bees)
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,322
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 - Electrical Engineering
Kettering Motorsports
Chrysler Powertrain - Controls and Calibration

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
  #3   Spotlight this post!  
Unread 07-22-2012, 06:58 PM
joelg236 joelg236 is offline
Registered User
AKA: Joel Gallant
no team
Team Role: Alumni
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 678
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: VEX Cortex RobotC help

Thanks for the great response! Could have taken me a while. (Simple solution, wrong mindset)

I will try it out when I get home tonight.
__________________
Team 4334 2012-2014
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:40 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi