WARobotics
Rookie
Joined: Tue Feb 22, 2011 5:58 pm Posts: 1
|
 NXT Motors crossing with DC motors, please help
Hello my team and I are having a problem with coding an autonomous program. During the program out Nxt motor must dispense batons, while running the program when the NXT motor is supposed to run the right drive motors turn the robot instead. We have looked over this code and can not find what the problem is, any suggestions help, thanks.
This is the bugged program. #pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, none) #pragma config(Motor, motorA, eject, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C1_1, right, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, left, tmotorNormal, openLoop, reversed) #pragma config(Motor, mtr_S1_C2_1, dab, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C2_2, dispense, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// // D -> right void forward(int clicks, int speed = 30) { nMotorEncoder[right]=0; nMotorEncoder[left]=0; while(nMotorEncoder[right] < clicks) { motor[right] = speed; motor[left] = speed; } if(nMotorEncoder[right] >= clicks) { nMotorEncoder[right]=0; nMotorEncoder[left]=0; motor[right] = 0; motor[left] = 0; }
return; }
void backward(int clicks, int speed = -30) { nMotorEncoder[right]=0; nMotorEncoder[left]=0; while(nMotorEncoder[right] > clicks) { motor[right] = speed; motor[left] = speed; } if(nMotorEncoder[right] <= clicks) { nMotorEncoder[right]=0; nMotorEncoder[left]=0; motor[right] = 0; motor[left] = 0; }
return; }
void turn(int clicks, string dir) { int speed = 30; //string dir = "right"; nMotorEncoder[right]=0; nMotorEncoder[left]=0; if(dir == "left") { while(nMotorEncoder[right] < clicks) { motor[right] = speed; motor[left] = -speed; } if(nMotorEncoder[right] >= clicks) { nMotorEncoder[right]=0; nMotorEncoder[left]=0; motor[right] = 0; motor[left] = 0; } }else if(dir == "right") { while(nMotorEncoder[left] < clicks) { motor[right] = -speed; motor[left] = speed; } if(nMotorEncoder[left] >= clicks) { nMotorEncoder[right]=0; nMotorEncoder[left]=0; motor[right] = 0; motor[left] = 0; } }else{ return; }
return; }
task main() {
//toward goal forward(3000); //turn along goal turn(2300, "left"); //dispense //tilt arm back motor[dab] = -50; wait1Msec(500); motor[dab] = 0; //kick battons out { motor[dispense] = -100; motor[eject] = 50; } wait1Msec(3000); //forward to next pipe forward(200); //dispense again { motor[eject] = 50; } wait1Msec(3000); //towards mountain forward(2700);
//go over mountain forward(8000);
}
|
jorge_the_awesome
Rookie
Joined: Sun Dec 05, 2010 11:58 am Posts: 28
|
 Re: NXT Motors crossing with DC motors, please help
I didn't know -variable worked. I thought it had to be -1*variable. I could easily be wrong, but you might want to check it. Where does the program go wrong? How far into the program does the robot get before errors occur? Could you give a specific function or line number?
|