Casey890
Rookie
Joined: Mon Feb 27, 2012 5:26 pm Posts: 20
|
 Encoders help asap please
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none) #pragma config(Sensor, S1, , sensorI2CMuxController) #pragma config(Sensor, S2, Irseeker, sensorHiTechnicIRSeeker1200) #pragma config(Sensor, S3, light, sensorNone) #pragma config(Sensor, S4, sonar, sensorNone) #pragma config(Motor, mtr_S1_C1_1, left1, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C1_2, left2, tmotorTetrix, openLoop, encoder) #pragma config(Motor, mtr_S1_C2_1, right1, tmotorTetrix, openLoop, reversed, encoder) #pragma config(Motor, mtr_S1_C2_2, right2, tmotorTetrix, openLoop, reversed) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c"
task main() { nMotorEncoder[left2] = 0;//reset the value of encoder B to zero nMotorEncoder[right1] = 0;//reset the value of encoder C to zero nMotorEncoderTarget[left2] = 1400;//set the encoder target to 720 nMotorEncoderTarget[right1] = 1400;//set the encoder target to 720 motor[left2] = -32;//turn on motorB at 32% power motor[right1] = -30;//turn on motorB at 30% power motor[left1] = -32;//turn on motorB at 32% power motor[right2] = -30;
while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle); { /* This is an idle loop. The program waits until the condition is satisfied*/} motor[left2] = 0; //Turn off motors motor[right1] = 0; motor[left1] = 0; motor[right2] = 0;
nMotorEncoder[left2] = 0;//reset the value of encoder B to zero nMotorEncoder[right1] = 0;//reset the value of encoder C to zero nMotorEncoderTarget[left2] = 825;//set the encoder target to 825 nMotorEncoderTarget[right1] = 825;//set the encoder target to 825 motor[left2] = 32;//turn on motorB at 32% power motor[right1] = -30;//turn on motorB at 30% power motor[left1] = 32;//turn on motorB at 32% power motor[right2] = -30;
while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle); { /* This is an idle loop. The program waits until the condition is satisfied*/} motor[left2] = 0; //Turn off motors motor[right1] = 0; motor[left1] = 0; // motor[right2] = 0;
nMotorEncoder[left2] = 0;//reset the value of encoder B to zero nMotorEncoder[right1] = 0;//reset the value of encoder C to zero nMotorEncoderTarget[left2] = 2500;//set the encoder target to 2500 nMotorEncoderTarget[right1] = 2500;//set the encoder target to 2500 motor[left2] = -32;//turn on motorB at 32% power motor[right1] = -30;//turn on motorB at 30% power motor[left1] = -32;//turn on motorB at 32% power motor[right2] = -30;
while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle); { /* This is an idle loop. The program waits until the condition is satisfied*/} motor[left2] = 0; //Turn off motors motor[right1] = 0; motor[left1] = 0; motor[right2] = 0;
}
|
Casey890
Rookie
Joined: Mon Feb 27, 2012 5:26 pm Posts: 20
|
 Re: Encoders help asap please
The goal is to go reverse for a set distance, then do a turn, and then go in reverse one time all using encoders. For an odd reason it runs until the encoder reaches the maximum amount of clicks only in reverse and will not execute any other parts of the code.
|
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: Encoders help asap please
This will also cause problems. What you are saying here is 'set the encoder target to +1400, then move the motors in a negative direction'. The motors will turn on and the encoders will move away from the target, not towards it; eventually you will hit what is called the overflow for the encoders, at which point the values will 'roll over' to the opposite amount (for the NXT motors, this amount is -32767 to +32767; once -32767 is reached, the encoders will roll over to +32767). This is why you will see the motors run for a very long time and then suddenly stop; they are moving towards the -32767 rollover point and, once they overflow to +32767, they then stop.
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|