Monday, December 17, 2012

Programming :: "Shield" Mecanum Drive with motor limit and threshold


#pragma config(Motor,  port4,           frontLeft,     tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port5,           frontRight,    tmotorVex393, openLoop)
#pragma config(Motor,  port6,           backLeft,      tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port7,           backRight,     tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/***************************************************************************

Program for Mecanum Drive
- Left joystick, Y-axis will control robot's forward and backward movement
- Left joystick, X-axis will control robot's left and right strafe movement
- Right joystick, X-axis will control robot's clockwise and counterclockwise rotation

Mount San Antonio College VEX Team

***************************************************************************/

/***************Main Task***************/


task main(){


while (1 == 1)

{
int Y1 = 0, X1 = 0, X2 = 0, threshold=20, motorMax = 100;
if(abs(vexRT[Ch3]) > threshold)Y1 = vexRT[Ch3];
else Y1 = 0;
if(abs(vexRT[Ch4]) > threshold)X1 = vexRT[Ch4];
else X1 = 0;
if(abs(vexRT[Ch1]) > threshold)X2 = vexRT[Ch1];
else X2 = 0;
/*Remote Control Commands */
//Front Right Check
if ((Y1 - X2 + X1) > 100){
motor[frontRight] = motorMax;
}else{
motor[frontRight] = Y1 - X2 - X1;
}
//Back Right Check
if ((Y1 - X2 - X1) > 100){
motor[backRight] = motorMax;
}else{
motor[backRight] = Y1 - X2 + X1;
}
//Front Left Check
if ((Y1 + X2 + X1) > 100){
motor[frontLeft] = motorMax;
}else{
motor[frontLeft] = Y1 + X2 + X1;
}
//Back Left Check
if ((Y1 + X2 - X1) > 100){
motor[backLeft] = motorMax;
}else{
motor[backLeft] = Y1 + X2 - X1;
}
}
}

No comments:

Post a Comment