Go to Post If only 5% of American entry level workers are proficient in algebra in 2022, I'm moving to Canada. - PVCpirate [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 04-25-2012, 06:55 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

do i have to divide the rpm by 360 since my encoder has 360 positions in 1 rotation?
  #2   Spotlight this post!  
Unread 04-25-2012, 07:07 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

i noticed that your code resets back to zero after 60,000 rpm. it is reading much faster that actually spinning. what do i do to make it the actual rpm

My encoder is the kop encoder and it has 360 positions in 1 rotation
  #3   Spotlight this post!  
Unread 04-25-2012, 07:28 PM
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,566
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino and kop encoder

Quote:
Originally Posted by SeanPerez View Post
do i have to divide the rpm by 360 since my encoder has 360 positions in 1 rotation?
Actually, I just modified my code. I realized I had a mistake:

Code:
// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo motor1;  // create servo object to control a motor 
Servo motor2;  // ditto
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
float dt;
volatile byte rpmcount;
float rpm;
unsigned long timeold;

 
void setup() 
{ 
  motor1.attach(9);  // attaches motor 1 on pin 9 to the servo object 
  motor2.attach(10); // ditto
  attachInterrupt(0, rpm_fun, RISING);
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  digitalWrite(2, HIGH);
  Serial.begin(9600);
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the motor (value between 0 and 180) 
  
  
  if (rpmcount >= 20) {
    dt = (float)(millis() - timeold)/1000;
    Serial.print(dt);
    rpm = rpmcount/dt*60;
    timeold = millis();
    rpmcount = 0;
    Serial.print(" RPM: ");
    Serial.print(rpm);
    Serial.print(" Pot: ");
    Serial.print(val);
    Serial.print("\n");
  }  
  
  motor1.write(val);                  // sets the motor speed according to the scaled value 
  motor2.write(val);
}

void rpm_fun()
{
  rpmcount++;
}
At any rate, when used as an interrupt, it only counts once per revolution.
  #4   Spotlight this post!  
Unread 04-25-2012, 08:04 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

Quote:
At any rate, when used as an interrupt, it only counts once per revolution.
it may only count once, but i was getting around 8000 rpm.


with your new code, the faster it spins, the lower the rpm.

Last edited by SeanPerez : 04-25-2012 at 08:06 PM.
  #5   Spotlight this post!  
Unread 04-25-2012, 08:06 PM
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,566
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino and kop encoder

Quote:
Originally Posted by SeanPerez View Post
it may only count once, but i was getting around 8000 rpm.


with your new code, the faster it spins, the lower the rpm.
Are you looking at the first column?

If you are, disregard that. That's the "dt" value. Sorry, I didn't make it very legible. Look at the second set of numbers.

0.43 RPM: 2803.74 Pot: 82

means that 0.43 is the time between calculations, 2803.74 is the revolutions per minute, and 82 is the potentiometer value.
  #6   Spotlight this post!  
Unread 04-25-2012, 08:18 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

ok now im reading the right number. but it seems the rpm is way to high then the actual rpm.

im spinning it by hand and its reading around 21,000 rpm. this is way to high. im spinning it at around 60 rpm +or- 10 rpm
  #7   Spotlight this post!  
Unread 04-25-2012, 08:22 PM
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,566
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino and kop encoder

Quote:
Originally Posted by SeanPerez View Post
ok now im reading the right number. but it seems the rpm is way to high then the actual rpm.

im spinning it by hand and its reading around 21,000 rpm. this is way to high. im spinning it at around 60 rpm +or- 10 rpm
You didn't multiply it by 360 did you? If not, The arduino board MIGHT somehow me picking up every encoder tick. If that's the case, divide by 360. (Notice that 21000/360 = 58.3)
  #8   Spotlight this post!  
Unread 04-25-2012, 08:23 PM
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,566
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino and kop encoder

It would make sense, by the way, if it is. My code is for a hall effect sensor being used as an encoder that reads a screw once per revolution.
  #9   Spotlight this post!  
Unread 04-25-2012, 08:27 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

sorry if i was unclear but i was looking for code for a encoder that reads 360 positions per revolution compared to your 1 . no worries, all i did was divide your rpm by 360.
  #10   Spotlight this post!  
Unread 04-25-2012, 08:29 PM
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,566
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino and kop encoder

Quote:
Originally Posted by SeanPerez View Post
sorry if i was unclear but i was looking for code for a encoder that reads 360 positions per revolution compared to your 1 . no worries, all i did was divide your rpm by 360.
So you got it working then? Dividing by 360 would be the solution I think.
  #11   Spotlight this post!  
Unread 04-25-2012, 08:40 PM
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,566
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino and kop encoder

Oh, and I thought I'd caution you. There's a maximum read rate on the arduinos. It takes about 100 microseconds to take a reading, so it can read about 10,000 times/second. Since you're reading all 360 values every rotation, you've got a maximum of 27.78 rev/sec, or 1666.67 RPM. Not really sure what you're using it for, but keep that in mind.
  #12   Spotlight this post!  
Unread 04-25-2012, 09:32 PM
docdavies's Avatar
docdavies docdavies is offline
Doc Davies
FRC #0346 (RoboHawks)
Team Role: Mentor
 
Join Date: Mar 2010
Rookie Year: 1998
Location: Richmond, VA
Posts: 70
docdavies is an unknown quantity at this point
Re: Arduino and kop encoder

Thank you folks. I found this thread very informative and useful.

We are also working to "off-load" more robot functions to an Arduino Mega.

Doc
  #13   Spotlight this post!  
Unread 04-25-2012, 11:32 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

Quote:
Originally Posted by Michael Hill View Post
Oh, and I thought I'd caution you. There's a maximum read rate on the arduinos. It takes about 100 microseconds to take a reading, so it can read about 10,000 times/second. Since you're reading all 360 values every rotation, you've got a maximum of 27.78 rev/sec, or 1666.67 RPM. Not really sure what you're using it for, but keep that in mind.

are you sure its 1666? i went up to as high as 2000 multiple times in a row
  #14   Spotlight this post!  
Unread 04-25-2012, 11:36 PM
SeanPerez SeanPerez is offline
Registered User
FRC #2625 (Arc Reactor)
Team Role: Driver
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Mississauga
Posts: 45
SeanPerez is an unknown quantity at this point
Re: Arduino and kop encoder

i think the fastest i could spin it was 2100rpm
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


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

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