Code: #pragma config(Motor, port1, leftMotor, tmotorVex393, openLoop, reversed) #pragma config(Motor, port6, clawMotor, tmotorVex393, openLoop, reversed) #pragma config(Motor, port7, armMotor, tmotorVex393, openLoop, reversed) #pragma config(Motor, port10, rightMotor, tmotorVex393, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*----------------------------------------------------------------------------------------------------*\ |* - Clawbot Single Joystick Control - *| |* ROBOTC on VEX 2.0 Cortex *| |* *| |* This program uses a single joystick, either right or left to drive the robot. Use notes below *| |* to reconfigure which joystick is used. The joystick buttons are used to raise and lower the arm. *| |* The joystick buttons are used to open and close the claw. *| |* *| |* ROBOT CONFIGURATION *| |* NOTES: *| |* 1) Ch1 is the X axis and Ch2 is the Y axis for the RIGHT joystick. *| |* 2) Ch3 is the Y axis and Ch4 is the X axis for the LEFT joystick. *| |* 3) Button 5U and 5L are on the front left side of the joystick. *| |* 3) Button 6U and 6L are on the front right side of the joystick. *| |* *| |* MOTORS & SENSORS: *| |* [I/O Port] [Name] [Type] [Description] *| |* Motor - Port 2 rightMotor VEX 393 Motor Right drive motor *| |* Motor - Port 6 clawMotor VEX 393 Motor w/ Motor Controler 29 Claw motor *| |* Motor - Port 7 armMotor VEX 393 Motor w/ Motor Controler 29 Arm motor *| |* Motor - Port 10 leftMotor VEX 393 Motor Left drive motor *| \*----------------------------------------------------------------------------------------------------*/
//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++ task main () { 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[armMotor] = (vexRT[Ch3])/2; // Left Joystick Y value / 2. } else // If the left joystick is within the threshold: { motor[armMotor] = 0; // Stop the left motor (cancel noise) }
if(abs(vexRT[Ch4]) > threshold) // If the right joystick is greater than or less than the threshold: { motor[clawMotor] = (vexRT[Ch4])/2; // Right Joystick Y value / 2. } else // If the right joystick is within the threshold: { motor[clawMotor] = 0; // Stop the claw motor (cancel noise) } motor[leftMotor] = (vexRT[Ch2] + vexRT[Ch1])/2; // (y + x)/2 motor[rightMotor] = (vexRT[Ch2] - vexRT[Ch1])/2; // (y - x)/2 // Raise, lower or do not move arm // * old line of code motor[armMotor] = (vexRT[Ch3] + vexRT[Ch3])/2; // (y + x)/2
// Open, close or do not more claw // * old line of code motor[clawMotor] = (vexRT[Ch4] + vexRT[Ch4])/2; // (y + x)/2 } } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |