|
Page 1 of 1
|
[ 4 posts ] |
|
| Author |
Message |
|
Cie1321
Rookie
Joined: Mon Sep 07, 2009 7:29 pm Posts: 3
|
 Encoder help
This is our failed encoder attempt. we can't figure out whats wrong, if anyone could either tell us what what we did wrong or post a working code.
#pragma config(Hubs, S1, HTMotor, HTServo, none, none) #pragma config(Motor, motorA, motorA, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, PIDControl, reversed, encoder) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, PIDControl, encoder) #pragma config(Servo, srvo_S1_C2_1, , tServoNormal) #pragma config(Servo, srvo_S1_C2_2, , tServoNormal) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() {
nMotorEncoder[motorE] = 0; nMotorEncoder[motorD] = 0;
nMotorEncoderTarget[motorE] = 100; nMotorEncoderTarget[motorD] = 100;
motor[motorE] = 100; motor[motorD] = 100;
while(nMotorEncoder[motorE] > 100); { motor[motorE] = 0; motor[motorD] = 0; }
}
|
| Tue Feb 16, 2010 9:39 pm |
|
 |
|
l0jec
Expert
Joined: Mon Oct 27, 2008 9:59 pm Posts: 137
|
 Re: Encoder help
Your while condition at the end will not execute because it is false from the beginning (the encode could not have reached 100 yet). I assume you wanted to wait until the encode reached 100 and then set the motors to zero and exit? If so, you could change this: to something like this:
|
| Wed Feb 17, 2010 2:15 pm |
|
 |
|
Cie1321
Rookie
Joined: Mon Sep 07, 2009 7:29 pm Posts: 3
|
 Re: Encoder help
That did work, but now we are having another problem... it will not turn, can you help us with this one?  |  |  |  | Code: #pragma config(Hubs, S1, HTMotor, HTServo, none, none) #pragma config(Motor, motorA, motorA, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, PIDControl, reversed, encoder) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, PIDControl, encoder) #pragma config(Servo, srvo_S1_C2_1, , tServoNormal) #pragma config(Servo, srvo_S1_C2_2, , tServoNormal) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { nMotorEncoder[motorE] = 0; nMotorEncoder[motorD] = 0;
wait1Msec(1); motor[motorE] = 100; motor[motorD] = 100;
while(nMotorEncoder[motorE] < 3000); { wait1Msec(1); } motor[motorE] = 0; motor[motorD] = 0;
wait1Msec(1);
nMotorEncoder[motorE] = 0; nMotorEncoder[motorD] = 0;
wait1Msec(1); motor[motorE] = 100; motor[motorD] = -100;
while(nMotorEncoder[motorE] < 5000); { wait1Msec(1); } motor[motorE] = 0; motor[motorD] = 0;
wait1Msec(3000);
|  |  |  |  |
|
| Wed Feb 17, 2010 8:46 pm |
|
 |
|
LennyB
Rookie
Joined: Thu Feb 25, 2010 2:34 am Posts: 2
|
 Re: Encoder help
You code looks like it should work. Did you resolve the problem? If not, how did it fail, e.g. by going straight?
|
| Thu Feb 25, 2010 2:53 am |
|
|
|
Page 1 of 1
|
[ 4 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|