Go to Post When we got it tuned to the point where we were (reasonably) confident it wouldn't slam into Dave's ankle, we quit for the evening. - Kevin Watson [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, 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
  #2   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)
  #3   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.
  #4   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.
  #5   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.
  #6   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.
  #7   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
  #8   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
  #9   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
  #10   Spotlight this post!  
Unread 04-26-2012, 12:11 AM
taichichuan's Avatar
taichichuan taichichuan is offline
Software Mentor
AKA: Mike Anderson
FRC #0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Herndon, VA
Posts: 328
taichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud of
Send a message via AIM to taichichuan
Re: Arduino and kop encoder

Actually, the Arduino mega maxes out at about 30,000 PPS. It can easily read 3500-5000 RPM depending on your encoder. Rather than sample at 1x/second, you might try sampling at 100x/second and adjusting the RPM accordingly. Here's an example:

/***
File : turret.pde (opens in arduino IDE www.arduino.cc)
Description : Counts digital pulse on External Interrupt 0 (Digital pin 2) for 100 mseconds and prints the value via UDP
Date : 18th March 2012
Author : Mike Anderson FRC Team #116
Contact : manderson13@cox.net
***/

// include the library code:
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include <SimpleTimer.h>

// Conversion of Analog value to degrees using U.S. Digital
#define ANALOG_TO_DEGREES 2.84

// Number of pulses per revolution on the shaft encoder
#define SHAFT_ENCODER_PPR 64.0

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 1, 16, 9);
static uint8_t crio_ip[4] = { 10,1,16,2 };
unsigned int remPort = 8888;
unsigned int distance = 0;

unsigned int localPort = 8888; // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

int iTestPin=13; //Pin which generates test pulses, this is not needed when actual pulse is available for measurement
int iPulsePin = 2; //Pin serving as external interrupt (INT 0) to count the pulses
static int siPulseCounter=0; //Variable keeping track of pulse counts
static int reportInterval=1;

static int multiplierFactor = 60 / reportInterval;

int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int tmpDegrees = 0;
int oldDegrees = 0;
float tempFloat = 0.0;

SimpleTimer rpmTimer;
SimpleTimer hoodAngleTimer;

void sendRPM() {
tempFloat = (siPulseCounter / SHAFT_ENCODER_PPR) * 600.0;
Serial.println(siPulseCounter, DEC);
sprintf(packetBuffer, "1 %d\n\0", (int)(tempFloat));
// send a reply, to the IP address and port that sent us the packet we received
// Serial.write(packetBuffer);
Udp.beginPacket(crio_ip, remPort);
Udp.write(packetBuffer);
Udp.endPacket();

siPulseCounter=0; //Reset counter values for next minute cycle

}

void sendHoodAngle() {
sensorValue = analogRead(sensorPin);
tmpDegrees = (int) (sensorValue / ANALOG_TO_DEGREES);

sprintf(packetBuffer, "2 %d\n\0", tmpDegrees);
// send a reply, to the IP address and port that sent us the packet we received
// Serial.write(packetBuffer);
Udp.beginPacket(crio_ip, remPort);
Udp.write(packetBuffer);
Udp.endPacket();
oldDegrees = tmpDegrees;

}

void setup(void)
{

// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);

pinMode(iPulsePin, INPUT); // Set Pulsepin to accept inputs

digitalWrite(iPulsePin, HIGH);
pinMode(iTestPin, OUTPUT); // Test signal generator pin as output. Can be ignored if the actual digital signal is available
attachInterrupt(0, count, RISING); // Caputres external interrupt 0 at iPulsepin at rising edge and calls funtion count defined below
Serial.begin(115200); // Begin Serial communication at baudrate 115200 bps
Serial.println(" Initialising, Please wait...");
rpmTimer.setInterval(100, sendRPM);
hoodAngleTimer.setInterval(250, sendHoodAngle);

}

void loop(void)
{
rpmTimer.run();
hoodAngleTimer.run();

/*** Following 4 lines just generate pulses for testing purposes.
All the 4 lines Can be ignored if the actual digital signal is available ***/
//
// digitalWrite(iTestPin, HIGH); // sets the iTestPin ON
// delay(1); // waits for a second
// digitalWrite(iTestPin, LOW); // sets the iTestPin off
// delay(1); // waits for a second

}

void count() // Function called by AttachInterrupt at interrupt at int 0
{
siPulseCounter++; //increment the pulse count
}


/* End of turret.ino */

Last edited by taichichuan : 04-26-2012 at 12:13 AM.
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