View unanswered posts | View active topics It is currently Thu Jul 31, 2014 3:45 am






Reply to topic  [ 4 posts ] 
Encoder help 
Author Message
Rookie

Joined: Mon Sep 07, 2009 7:29 pm
Posts: 3
Post 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
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post 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:
Code:
motor[motorE] = 100;
motor[motorD] = 100;

while(nMotorEncoder[motorE] > 100);
{
  motor[motorE] = 0;
  motor[motorD] = 0;
}

to something like this:
Code:
motor[motorE] = 100;
motor[motorD] = 100;

while(nMotorEncoder[motorE] < 100);
{
  wait10ms(1);
}

motor[motorE] = 0;
motor[motorD] = 0;


Wed Feb 17, 2010 2:15 pm
Profile
Rookie

Joined: Mon Sep 07, 2009 7:29 pm
Posts: 3
Post 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
Profile
Rookie

Joined: Thu Feb 25, 2010 2:34 am
Posts: 2
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.