Go to Post Tank tracks are one of those things that keep showing up on FIRST robots, in ways that I dont understand. - KenWittlief [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 01-02-2004, 16:26
Zee Zee is offline
Registered User
no team
 
Join Date: Jan 2004
Location: USA
Posts: 8
Zee is an unknown quantity at this point
Encoder Counts/time period to PWM value

Hey guys, I have no clue how to do this. How do I convert the number of counts I receive from the encoder over a given time period to a corresponding PWM value?

Thanks
  #2   Spotlight this post!  
Unread 01-02-2004, 17:16
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Zee
Hey guys, I have no clue how to do this. How do I convert the number of counts I receive from the encoder over a given time period to a corresponding PWM value?

Thanks
Well, what does the encoder count tell you? It can tell you how far you've gone. So, how do you convert that into a PWM value? Well, if you know that you want to go 3 feet, and your encoders tell you that you've only gone 2 feet, then you send your motors a value telling them to go forward. For a specific algorithm, I suggest using PID control. You can search these forums, or the internet in general for an explanation of this.
  #3   Spotlight this post!  
Unread 01-02-2004, 17:37
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Zee
Hey guys, I have no clue how to do this. How do I convert the number of counts I receive from the encoder over a given time period to a corresponding PWM value?

Thanks
Is this to calculate the velocity error in PWM units?

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #4   Spotlight this post!  
Unread 01-02-2004, 20:09
Zee Zee is offline
Registered User
no team
 
Join Date: Jan 2004
Location: USA
Posts: 8
Zee is an unknown quantity at this point
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Kevin Watson
Is this to calculate the velocity error in PWM units?

-Kevin
Yes, it is. I'd also like to know how many encoder counts/time period for a given PWM value.
  #5   Spotlight this post!  
Unread 01-02-2004, 20:36
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Zee
Yes, it is. I'd also like to know how many encoder counts/time period for a given PWM value.
You can only do this if the motor is unloaded (and even then it's shakey, at best). In general you can't directly correlate a PWM value to a rotational rate. As noted elsewhere, you are better off commanding a velocity and letting a control loop set the PWM value. There are likely to be motor control examples in the white paper and programming areas.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #6   Spotlight this post!  
Unread 02-02-2004, 11:51
Zee Zee is offline
Registered User
no team
 
Join Date: Jan 2004
Location: USA
Posts: 8
Zee is an unknown quantity at this point
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Kevin Watson
You can only do this if the motor is unloaded (and even then it's shakey, at best). In general you can't directly correlate a PWM value to a rotational rate. As noted elsewhere, you are better off commanding a velocity and letting a control loop set the PWM value. There are likely to be motor control examples in the white paper and programming areas.

-Kevin
This is why I ask. My PID closed loop control is based on SilverStar's algorithm. He isn't accepting private messages or I'd ask him directly. I have a function:

int PID(int request, int actual, int *lastActual, signed int *sum)

In my code, request and actual will be PWM values from 0-255. The request PWM value will come from input from the joystick. The actual PWM value will come from the encoder. My question is, the encoder produces counts/time period. How do you get an actual PWM value from this. Or am I going about it all wrong?
  #7   Spotlight this post!  
Unread 02-02-2004, 12:52
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Encoder Counts/time period to PWM value

what you could try instead is if you wanted to use PID to make the PWMs function on a more linear scale, measure your top speed (when the PWM is set to 254) and then take any speed, divide it by the top speed, and multiply by 254 - this becomes your "actual" pwm. that way, the PID loop would result in the PWM control being more linear.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #8   Spotlight this post!  
Unread 02-02-2004, 13:17
Zee Zee is offline
Registered User
no team
 
Join Date: Jan 2004
Location: USA
Posts: 8
Zee is an unknown quantity at this point
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by deltacoder1020
what you could try instead is if you wanted to use PID to make the PWMs function on a more linear scale, measure your top speed (when the PWM is set to 254) and then take any speed, divide it by the top speed, and multiply by 254 - this becomes your "actual" pwm. that way, the PID loop would result in the PWM control being more linear.
I will give this a try. Thanks.
  #9   Spotlight this post!  
Unread 02-02-2004, 23:37
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: Encoder Counts/time period to PWM value

Correct me if I'm wrong (which is entirely possible) but I think this is the idea of the PID loop.

First of all, it is impossible to do a straight conversion between target encoder counts/second to pwm output, since there are always going to be external forces acting on your robot to either speed it up or slow it down.

You need to compare actual encoder counts/sec with a target encoder counts/sec, and use that to adjust your pwm output. Something like this.

pwmOut += (targetEncoderCps - actualEncoderCps) * P_CONSTANT

I would convert your joystick input to a target encoder counts/sec. So if your top speed is 10 rev/sec and you have an encoder with 100 counts/rev (for the sake of simplicity I know encoders don't come like that) then at top speed you would be getting 1000 counts/sec. So I would do:

targetEncoderCps = (p1_y - 127) / 127 * 1000

First step is to center the joystick at 0, then convert it to the range [-1,1], then convert it to the range [-1000,1000]. Of course, if you are dealing with integer math (highly recommended), then do this:

targetEncoderCps = ((long)p1_y - 127) * 1000 / 127

The cast is necessary to make p1_y signed and to make sure *1000 does not overflow.
  #10   Spotlight this post!  
Unread 03-02-2004, 12:01
Zee Zee is offline
Registered User
no team
 
Join Date: Jan 2004
Location: USA
Posts: 8
Zee is an unknown quantity at this point
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Jay Lundy
Correct me if I'm wrong (which is entirely possible) but I think this is the idea of the PID loop.

First of all, it is impossible to do a straight conversion between target encoder counts/second to pwm output, since there are always going to be external forces acting on your robot to either speed it up or slow it down.

You need to compare actual encoder counts/sec with a target encoder counts/sec, and use that to adjust your pwm output. Something like this.

pwmOut += (targetEncoderCps - actualEncoderCps) * P_CONSTANT

I would convert your joystick input to a target encoder counts/sec. So if your top speed is 10 rev/sec and you have an encoder with 100 counts/rev (for the sake of simplicity I know encoders don't come like that) then at top speed you would be getting 1000 counts/sec. So I would do:

targetEncoderCps = (p1_y - 127) / 127 * 1000

First step is to center the joystick at 0, then convert it to the range [-1,1], then convert it to the range [-1000,1000]. Of course, if you are dealing with integer math (highly recommended), then do this:

targetEncoderCps = ((long)p1_y - 127) * 1000 / 127

The cast is necessary to make p1_y signed and to make sure *1000 does not overflow.
This is the answer I needed. Thanks.
  #11   Spotlight this post!  
Unread 04-02-2004, 01:41
Guest
 
Posts: n/a
Re: Encoder Counts/time period to PWM value

Quote:
Originally Posted by Jay Lundy
Correct me if I'm wrong (which is entirely possible) but I think this is the idea of the PID loop.

First of all, it is impossible to do a straight conversion between target encoder counts/second to pwm output, since there are always going to be external forces acting on your robot to either speed it up or slow it down.

You need to compare actual encoder counts/sec with a target encoder counts/sec, and use that to adjust your pwm output. Something like this.

pwmOut += (targetEncoderCps - actualEncoderCps) * P_CONSTANT

I would convert your joystick input to a target encoder counts/sec. So if your top speed is 10 rev/sec and you have an encoder with 100 counts/rev (for the sake of simplicity I know encoders don't come like that) then at top speed you would be getting 1000 counts/sec. So I would do:

targetEncoderCps = (p1_y - 127) / 127 * 1000

First step is to center the joystick at 0, then convert it to the range [-1,1], then convert it to the range [-1000,1000]. Of course, if you are dealing with integer math (highly recommended), then do this:

targetEncoderCps = ((long)p1_y - 127) * 1000 / 127

The cast is necessary to make p1_y signed and to make sure *1000 does not overflow.
A few points:

If you use the suggested equation(s) in this message, you will only be using the 'P' in PID. As in, the pwm01 is being changed only by a proportion of the error. You need to track the integral (sum) of the error, and the derivative (change/time) of the error and consider these in creating a PWM value to be sent to the motors.
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
Some EDURobotics Problems squide Robotics Education and Curriculum 9 20-01-2004 10:27
pwm 13-15 wayne 05 Programming 2 04-10-2003 12:08
PWM and burning out motors patrickrd Technical Discussion 7 19-06-2003 15:30
Loss of signal in PWM cables. archiver 2001 6 23-06-2002 23:29


All times are GMT -5. The time now is 23:57.

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