Go to Post Well, there goes our bare aluminum corner tracking full field navigation system... - Whippet [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 09-12-2004, 15:38
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
encoder vs. motor

I have a robot with a mechanical encoder attatched to an arm with a motor to lift the arm.

the encoder is at 50 resolution
the arm motor is attatched to pwm_02
the encoder is attatched to rc_dig_in06
I calculated that the encoder will "click" or turn on and off 10.7 times for the distance I need.(the encoder is 50 resolution).

basically I need the source so the motor attatched to pwm_02 will stop once the encoder "ticks" 10.7 (or eleven) times. Please keep it simple. I don't have time to go through a tutorial right now. thank you so much for the help.

oh yeah, it would be nice If I could have the arm lift at the touch of a trigger on a joystick attatched to p1_sw_trig. and have the arm go back down at the touch of the trigger again. does the operator interface controller provide a way to simply shut everything down immediately in the event of a disaster?
please help.
thanks,
Stephen

Last edited by stephenthe1 : 09-12-2004 at 15:43.
  #2   Spotlight this post!  
Unread 09-12-2004, 15:52
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: encoder vs. motor

Stephen,

I think it would be best for you to attempt to write this code yourself. It is very simple (count to 11)...

If you post your code, I'm sure that one of us will critique it for you before you load it into a robot.

Regards,

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #3   Spotlight this post!  
Unread 09-12-2004, 15:54
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

can you look at this and tell me if you see any errors.

Code:
	//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	unsigned int encoder;
	if (p2_sw_trig == 1)
	pwm_02 = 220;
	if (rc_dig_in06 == 1)
	encoder = encoder + 1;
	if (encoder == 11)
	pwm_02 = 128;
  #4   Spotlight this post!  
Unread 09-12-2004, 16:04
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,910
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
can you look at this and tell me if you see any errors.

Code:
	//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	unsigned int encoder;
	if (p2_sw_trig == 1)
	pwm_02 = 220;
	if (rc_dig_in06 == 1)
	encoder = encoder + 1;
	if (encoder == 11)
	pwm_02 = 128;
Couple of problems, such as,
"encoder" needs to be static or a global, so it retains it's value from call to call.
The check on rc_dig_in06 will increment "encoder" more often than every "tick"
"encoder" might shoot right past 11 and keep going.

But first what model encoder are you using?
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #5   Spotlight this post!  
Unread 09-12-2004, 16:05
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: encoder vs. motor

Quote:
Originally Posted by stephenthe1
can you look at this and tell me if you see any errors.

Code:
	//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	unsigned int encoder;
	if (p2_sw_trig == 1)
	pwm_02 = 220;
	if (rc_dig_in06 == 1)
	encoder = encoder + 1;
	if (encoder == 11)
	pwm_02 = 128;
You only want to increment the encoder variable when rc_dig_in06 goes from 0-1 or from 1-0 (pick one). So you need to keep track of the previous value and the current value, then increment only when when it changes.
  #6   Spotlight this post!  
Unread 09-12-2004, 16:05
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
can you look at this and tell me if you see any errors.

Code:
	//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	unsigned int encoder;
	if (p2_sw_trig == 1)
	pwm_02 = 220;
	if (rc_dig_in06 == 1)
	encoder = encoder + 1;
	if (encoder == 11)
	pwm_02 = 128;
Stephen,

A good start.

First of all, you have not initialized your counter (maybe this is done in your actual code... I don't know).

Second, what happens the next time through the loop? I'm assuming that you will want to perform this maneuver again and again (once again, I may be mistaken). For now, I will assume that this is a one shot deal...

Here is what I think will happen: When the encoder hits 11, the arm is turned off but the encoder micro-switch is still "closed". The count will increase to 12 and the arm will continue to travel. You might want the last test to be "encoder > 11"...

Does this make sense to you?
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #7   Spotlight this post!  
Unread 09-12-2004, 16:23
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
how about this code.

we tried to keep the motor speed down so the encoder will read each tick before the program refreshes. so the motor doesn't "beat" the program before it reads the encoder.

Code:
//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	static unsigned int encoder;
	static unsigned int pressedornot;
	if (p1_sw_trig == 1)
{
	if (encoder <= 10)
{
    pwm_02 = 150;
	if (rc_dig_in06  == 1)
{
	encoder = encoder + 1;
	if (encoder > 10)
{
	pwm_02 = 127;
}
}
}
}
  #8   Spotlight this post!  
Unread 09-12-2004, 16:37
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,910
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: how about this code.

Could work.

You still need to initialize "static unsigned int encoder= 0;" as Mike mentioned.

I still think you're going to count each encoder tick more than once and your arm will end up short of the expected position.

( I have to pickup my daughter and will check back later)
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #9   Spotlight this post!  
Unread 09-12-2004, 16:51
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: how about this code.

Quote:
Originally Posted by stephenthe1
we tried to keep the motor speed down so the encoder will read each tick before the program refreshes. so the motor doesn't "beat" the program before it reads the encoder.

Code:
//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	static unsigned int encoder;
	static unsigned int pressedornot;
	if (p1_sw_trig == 1)
               {
	   if (encoder <= 10)
                  {
                   pwm_02 = 150;
                   if (rc_dig_in06  == 1)
                     {
	         encoder = encoder + 1;
	         if (encoder > 10)
                        {
	            pwm_02 = 127;
                        }
                     }
                  }
               }
Stephen,

You can see I attempted to reformat your code to make it more readable. Now you can see how your code nests...

I agree with Mark. I'm not worried about you missing an encoder ping but rather that you will get multiple hits at one ping.

You should consider implementing a state machine. Do you have a mentor on your team (what team are you with anyway?) who can teach you what a state machine is?
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #10   Spotlight this post!  
Unread 09-12-2004, 18:51
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

thanks for the help and tips. I'll have to look into state machines. Today I was in a kind of hurry (which was probably obvious). but now I've got more time to think things through. Our team doesn't really have any mentors for programming. We never have, last year we had a wiz kid, and this year its kinda up to me and another guy. neither of us have much experience. I programmed with c#, but that was with Windows, which tends to behave much differently than a robot . our team number is, I'm not sure. we're team "lugnut" though, from Ohio.
  #11   Spotlight this post!  
Unread 09-12-2004, 18:54
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: how about this code.

Quote:
Originally Posted by Mark McLeod
Could work.

You still need to initialize "static unsigned int encoder= 0;" as Mike mentioned.

I still think you're going to count each encoder tick more than once and your arm will end up short of the expected position.

( I have to pickup my daughter and will check back later)
if I initialize it as zero, won't the program simply reset encoder to zero every time it rereads the code?
  #12   Spotlight this post!  
Unread 09-12-2004, 18:55
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,910
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
Our team doesn't really have any mentors for programming. We never have, last year we had a wiz kid, and this year its kinda up to me and another guy. neither of us have much experience.
We'll be your mentors. There are quite a few of us to help you out.

Quote:
Originally Posted by stephenthe1
if I initialize it as zero, won't the program simply reset encoder to zero every time it rereads the code?
That declaration only takes effect when the program starts. The use of "static" fixes it permanently in memory and that line will not get executed each time the routine is called. Without the "static" the variable would get initialized each time the routine is called.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 09-12-2004 at 18:58.
  #13   Spotlight this post!  
Unread 09-12-2004, 18:56
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

lol. great! yeah, this chiefdelphi site has been an awesome help.
well, the encoder is an EC202AXXX (with 50 resolution)

Last edited by stephenthe1 : 09-12-2004 at 19:00.
  #14   Spotlight this post!  
Unread 09-12-2004, 19:33
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

so like with this code

Code:
//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	static unsigned int encoder = 0;
	if (p1_sw_trig == 1)
{
	if (encoder <= 10)
{
    pwm_02 = 254;
	if (rc_dig_in06  == 1)
{
	encoder = encoder + 1;
	if (encoder > 10)
{
	pwm_02 = 127;
}
}
}
}
I assigned a value of zero to encoder, however, every time the code is reread (every 30 milliseconds or something?), the value for encoder will be set back to zero, making its function useless. wish there was a way to make it so the thing didn't reread the code every amount of time, but rather go over it once and remember everything, and do everything from there. that's the way it is in most programming languages isn't it. anyway, do you see what I mean? or will it only assign the value of zero to it once and then when it reanalyzes the code, it will use the last assigned value. I don't think it works that way though.
  #15   Spotlight this post!  
Unread 09-12-2004, 19:35
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
lol. great! yeah, this chiefdelphi site has been an awesome help.
well, the encoder is an EC202AXXX (with 50 resolution)
Steve,

What you have is not a mechanical encoder. It is an optical encoder made by CUI.

Here is a spec sheet: EC202A050A2(S or T)D. As you can see, it comes in two flavors a horizontal or vertical mount.

More importantly, it has a quadrature output so that you can determine direction in your code.

Team 177 used a very similar device last year. I very, very strongly suggest that you download Kevin Watson's example code for optical encoders at http://kevin.org/frc/ and download the file edu_encoder.zip open it up and examine his code very carefully.

What Kevin did is for the edubot. You will have to do the same stuff to the RC code. However, over 50% of the work has been done for you.

It works like a charm. Trust me...
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
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
[OCCRA]: motor brush springs greencactus3 OCCRA Q&A 1 28-09-2004 20:56
Multiple Motors phrontist Motors 12 21-06-2004 23:05
Mounting the drill motor Veselin Kolev Motors 11 26-04-2004 14:27
WHich motor to lift and for arm thoughtful Motors 8 25-02-2004 10:34
Thermal Protection archiver 2000 1 23-06-2002 23:27


All times are GMT -5. The time now is 17:35.

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