View unanswered posts | View active topics It is currently Fri Apr 25, 2014 1:29 am






Reply to topic  [ 2 posts ] 
starting and stopping shaft encoder count 
Author Message
Rookie

Joined: Sun Jul 10, 2011 3:34 pm
Posts: 30
Post starting and stopping shaft encoder count
Hello,
I am very new to using the VEX shaft encoders with Cortex. For a competition robot, I need the optical shaft encoder to start and stop counting when certain conditions are true. I'm not really sure exactly how to put this into code. I put some pseudo code below for further understanding. Thanks in advance for any help!

Please note: I am using C, not natural language. And I am referring to the actual sensors, not the sensors built in with the motor.

if the line follower sees a white surface
start counting

if the line follower sees a black surface
stop counting
and save the value of the pulses counted


Tue Jan 22, 2013 8:15 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: starting and stopping shaft encoder count
You got it almost right with your pseudocode.
Code:
bool isCounting = false;
int startCount = 0;
int finalCount= 0;
while(true){
  if(line is white && !isCounting){
    startCount = sensorValue[encoder];
    isCounting = true;
  }
  if(isCounting && line is black){
    finalCount = sensorValur[encoder] - startCount;
    isCounting = false;
  }
}

_________________
sudo rm -rf /


Wed Jan 23, 2013 4:20 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.