|
Re: [FTC]: Autonomous
I adjusted the code to work with a simple test setup of an NXT connected to two NXT DC motors. I implemented the changes below and tested them with the Field Management System. I didn't test the servo code, however, you will be able to do this on your robot after making the following changes:
1. startTime should be declared "long", not "short". nPgmTime starts counting when the program starts on the NXT. By the time all four robots are on the field and ready to go and the Field Management System starts the autonomous mode, nPgmTime is a very large number, exceeding the range of the short variable startTime. You can observe the value of nPgmTime (scaled to seconds) in the System Parameters Debug Window while executing the program inside ROBOTC. Also, see next item 2 below.
2. Remove "(short)" in the code where startTime = (short)nPgmTime;
3. Reduce the maximum motor commands. The HiTechnic and NXT motors have a range of -100 to +100.
4. pulleymotor1 and pulleymotor2 are not declared in the Motor Setup. From the ROBOTC task bar select: Robot --> Motors and Sensors Setup. Select the Motors tab and assign pulleymotor1 and pulleymotor2 to a Port.
5. The autonomous code will continue to loop [run again] unless you add a "StopAllTaks():" after the last while loop.
6. Set motor commands to zero when leaving motor and servo while loops. Create a function such as:
void stopMotors()
{
motor[motorD] = 0;
motor[motorE] = 0;
}
You can implement a similar function if you want to stop servo movement:
void stopServos()
{
servoTarget[servo1] = ServoValue[servo1];
}
Replace "servo1" with the name of your servo.
Call the appropriate function(s) after exiting a while loop.
7. Add the stopMotors(); and stopServos(); function calls to the initialization section of the autonomous program. See "void Initialize Robot()" towards the top of the program code.
Michael
|