Go to Post It is not for any other team to say what is beyond a person's or a team's capabilities. That's why they have mentors :-) - preussrobotics [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-01-2005, 15:07
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Question encoders

I'm posting this in hope that someone who has actually registered on this site will post something. there are so many people viewing this, but not posting anything. with that said, I thought this would be a nice place for people to discuss encoders. of course, my main motivation is that these things have been my killing me over the past month. I have tried numerous things, and I can never seem to get it to work. Coding, for the most part, I don't think is a problem. I'm using 2004's code written by Mr. Watson that supports encoders and interrupts. I have everything configured, the only thing that could possible be keeping the encoder from working is my code in User_Routines_Fast.c
what the code does is this, when the third joystick is pushed forward, the arm on last year's robot goes up untill the encoder has "clicked" 12 times. then the motor on the arm is set to neutral. it's as simple as that. (for testing purposes).

Code:
	static long lec = 0;            //lec = encoder count
	lec = lec + Get_Left_Encoder_Count();     //add previous count
      //plus the new count
//the static long is supposed to hold the value every loop                                                               
	if (lec >= 12)
	{
	pwm02 = 127;		//set it to neutral
	}
	else
	{
	pwm02 = p3_y;
	}
can you please tell me why this won't work, or if you think it should. please tell me yourself and don't refer me to somewhere. I've spent so much time, and a simple few lines of code would help me to understand this almost completely. (don't forget, Mr. Watson's 2004 encoder code is what I'm using.)

HELP!!!
thanks,
Stephen

Last edited by stephenthe1 : 12-01-2005 at 15:09.
  #2   Spotlight this post!  
Unread 12-01-2005, 15:19
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: encoders

What does the robot do when you move the joystick? Have you tried turning the encoder by hand and printing the value of lec to make sure its being incremented correctly?

Since the call to Get_Left_Encoder_Count() does not reset the internal value, your local variable (lec) will saturate very quickly. Once the encoder moves one tick it will increment lec over 12 almost instantly. You either need to reset the value to 0 or use Get_Left_Encoder_Count() on its own as your counter.
Code:
     if (Get_Left_Encoder_Count() >= 12)    
     {
          pwm02 = 127;
     }
     {
          pwm02 = p3_y;
     }

Last edited by seanwitte : 12-01-2005 at 15:38.
  #3   Spotlight this post!  
Unread 12-01-2005, 15:29
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoders

Quote:
Originally Posted by seanwitte
What does the robot do when you move the joystick? Have you tried turning the encoder by hand and printing the value of lec to make sure its being incremented correctly?

Since the call to Get_Left_Encoder_Count() does not reset the internal value, your local variable (lec) will saturate very quickly. Once the encoder moves one tick it will increment lec over 12 almost instantly. You either need to reset the value to 0 or use Get_Left_Encoder_Count() on its own as your counter.

do you mean set the "Get_Left_Encoder_Count()" function variable to 0? so your saying that Get_Left_Encoder_Count()" function variable holds its value every time it interrupts, even if I call it once and then call it again. that is definitely what Mr. Watson seems to have stated in his code. that makes sense, though I don't see how it holds the total value every time it interrupts without being declared as static.
  #4   Spotlight this post!  
Unread 12-01-2005, 15:33
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: encoders

Quote:
Originally Posted by stephenthe1
do you mean set the "Get_Left_Encoder_Count()" function variable to 0? so your saying that Get_Left_Encoder_Count()" function variable holds its value every time it interrupts, even if I call it once and then call it again. that is definitely what Mr. Watson seems to have stated in his code. that makes sense, though I don't see how it holds the total value every time it interrupts without being declared as static.
Get_Left_Encoder_Count() is a function that interacts with a static variable in encoder.c named Left_Encoder_Count. Since Left_Encoder_Count is not exposed by encoder.h you can only get the value using the supplied function, Get_Left_Encoder_Count(). To change its value use the function Set_Left_Encoder_Count().
  #5   Spotlight this post!  
Unread 12-01-2005, 15:36
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,189
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: encoders

Since the encoder may have ticked before you hit this block of code, you may want to do something like this.

Code:
//define a variable outside the loop called 'temp1'

if(temp1==0)
{
     temp1=Get_Left_Encoder_Count();
}

static long lec = Get_Left_Encoder_Count() - temp1;

if (lec >= 12)
	{
	pwm02 = 127;		//set it to neutral
	}
	else
	{
	pwm02 = p3_y;
	}

Last edited by Tom Bottiglieri : 12-01-2005 at 15:41.
  #6   Spotlight this post!  
Unread 12-01-2005, 16:09
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoders

how do I turn on the compressor in the 2004 default code? thanks. (though I'll be using it in Mr. Watson's 2004 encoder code).
  #7   Spotlight this post!  
Unread 12-01-2005, 16:23
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,189
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: encoders

Hook up your compressor to a spike, so that the red lead is attached to the M+ output and so that the black lead is connected to your ground junction. In your code, turn that relay on and off.

So, if you used relay1, the code would look something like this..

Code:
void TurnOnComp(void)
{
     relay1_fwd=1;
}

void TurnOffComp(void)
{
     relay1_fwd=0;
}
  #8   Spotlight this post!  
Unread 12-01-2005, 16:29
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoders

um, where do I put those functions at? (which file)
  #9   Spotlight this post!  
Unread 12-01-2005, 16:37
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoders

ok, our compressor is hooked up to digital 17. from last year's white sheet with the different wires labeled, it says that the sensor for the relay is hooked up to analog 1. I'm new to the compressor stuff. Is this all of what you need to write the code for it? It is hooked up to a spike. unless this is hard, could you show me the code for this, and tell me where to put it. That would allow me to learn from it as I get confused easily when I have to write things on my own without experience. as soon as you can is best, as I'm at a robotics meeting right now.
thank you for your help,
Stephen

Last edited by stephenthe1 : 12-01-2005 at 16:48.
  #10   Spotlight this post!  
Unread 12-01-2005, 18:19
cbolin's Avatar
cbolin cbolin is offline
Programming & Electrical
FRC #0342 (Burning Magnetos)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Charleston, SC
Posts: 72
cbolin is a splendid one to beholdcbolin is a splendid one to beholdcbolin is a splendid one to beholdcbolin is a splendid one to beholdcbolin is a splendid one to beholdcbolin is a splendid one to beholdcbolin is a splendid one to behold
Re: encoders

Stephen,
Regarding your first code posting
Code:
static long lec = 0;            //lec = encoder count
Did someone explain that if you initialize "lec" every time this function is called, it will always be zerod? You could get rid of the 'lec = 0'...that way it would always remember the last value (which is what you were trying to do).

If you already figured this out or I missed this in the above response...just ignore what I said. :-)

Regards,
ChuckB
__________________
Team 342 Programming & Control Systems
Good luck and have fun!
  #11   Spotlight this post!  
Unread 12-01-2005, 19:52
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: encoders

Quote:
Originally Posted by cbolin
Stephen,
Regarding your first code posting
Code:
static long lec = 0;            //lec = encoder count
Did someone explain that if you initialize "lec" every time this function is called, it will always be zerod? You could get rid of the 'lec = 0'...that way it would always remember the last value (which is what you were trying to do).
Actually, Chuck, because lec is declared static, it will only be initialized once, not every time the function is called.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #12   Spotlight this post!  
Unread 12-01-2005, 20:34
CJO's Avatar
CJO CJO is offline
Emeritus Pain in the $@#$@#$@#
AKA: Christopher J. O'Connell
None #1097 (Site 3 Engineering)
Team Role: Alumni
 
Join Date: Feb 2003
Location: Latrobe (over the rainbow), CA
Posts: 217
CJO will become famous soon enoughCJO will become famous soon enough
Re: encoders

On the compressor, I would do something like this:

"if (p1_wheel => 127)
{
relay1_fwd = 1
)
else
{
relay1_fwd = 0
)
"

The setup should be as follows:

You should have a joystick connected to port 1. You should have a spike sonnected to relay port 1.

When you rotate the throttle (the big wheel) on the joystick away from you all the way the compressor will turn on, otherwise, the compressor will not turn on.
__________________
Team 1097 -- Site 3 Engineering
~~~~~~~~~~~~~~~~~~~~
2003 Sacramento Rookie All Star
2003 Silicon Valley Rookie All Star
2004 Sacramento Engineering Inspiration Award
2004 Sacramento Visualization Award
2004 Outstanding Volunteer Award (G. Glasser)
2004 Silicon Valley Sportsmanship Award
2004 National Visualization Runner Up
2004 Cal Games Finalist
2005 Sacramento Sportsmanship Award
2005 Sacramento #1 seed
2005 Sacramento Finalist

2005 Silicon Valley Sportsmanship Award
2005 Silicon Valley #1 Seed
2005 Silicon Valley Finalist

  #13   Spotlight this post!  
Unread 12-01-2005, 20:45
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: encoders

Quote:
Originally Posted by seanwitte
What does the robot do when you move the joystick?
Stephen,

We're still looking for a description of the symptoms. (I asked too in the "What do you think about how easy theyre making programming?" thread.) All you've told us so far is that "the encoder doesn't work."

Have you tried what Sean suggested?:
Quote:
Originally Posted by seanwitte
Have you tried turning the encoder by hand and printing the value of lec to make sure its being incremented correctly?
You mention you're using Kevin's 2004 encoder code. The version I have has a fairly complete read-me file included in the .zip file. Have you read it? If you don't have the read-me, maybe you should get Kevin's latest version, and use it instead of the old one.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #14   Spotlight this post!  
Unread 12-01-2005, 21:34
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Lightbulb Re: encoders

thanks guys. actually, I found out in this thread that the Get_Left_Encoder_Count() function sends its returned value to the "Left_Encoder_Count" variable, which IS static. therefore I don't need the (poorly named) "lec" (left encoder count, but left count is being used for the arm this time, with the tick delta set to +1).

however, all I need for the compressor is to turn it on, but thanks for the wheel idea, as I'll try that out. It'll make testing more practical. thanks again!
  #15   Spotlight this post!  
Unread 12-01-2005, 22:36
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: encoders

Quote:
Originally Posted by stephenthe1
thanks guys. actually, I found out in this thread that the Get_Left_Encoder_Count() function sends its returned value to the "Left_Encoder_Count" variable, which IS static. therefore I don't need the (poorly named) "lec" (left encoder count, but left count is being used for the arm this time, with the tick delta set to +1).
however, all I need for the compressor is to turn it on, but thanks for the wheel idea, as I'll try that out. It'll make testing more practical. thanks again!
Don't use the wheel input to control the compressor! The pressure switch output is open (0) when the pressure drops below a threshold, then closes (1)when it hits 120 psi. It stays closed (1) until the pressure drops below the threshold again. That means there is no logic involved in turning the compressor on and off, just grab the value from the switch. Its right there in Default_Routine(). The compressor is connected to relay 8 and the pressure switch to digital input 18:

Code:
relay8_fwd = !rc_dig_in18;  /* Power pump only if pressure switch is off. */
relay8_rev = 0;
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mechanical Wheel Encoders? Jaine Perotti Electrical 15 04-12-2004 22:46
Shaft Encoders wun Programming 3 12-10-2004 16:40
encoders? what kind and where from? ajlapp Electrical 1 03-02-2004 01:49
Who used wheel encoders CyberWolf_22 Technical Discussion 12 04-05-2003 15:37


All times are GMT -5. The time now is 13:14.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi