go away spammer

Author Topic: Community project: Encoder wheel  (Read 12204 times)

0 Members and 1 Guest are viewing this topic.

Offline sonictj

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
    • Tim's Workshop
Re: Community project: Encoder wheel
« Reply #30 on: June 09, 2009, 02:56:18 AM »
you have the option of going to 10Hz which may help (100ms sampling time)

I just clean installed windows on this laptop so I haven't had time to write the PID code yet.  I'll try and get to it soon.

essentially though you need to create a timer interrupt that triggers the pid algorithm.

//this function and another for the other wheel will be called via a timer interrupt.  The period of time is up to you, but an interrupt is nessicary to keep the time //consistent.

PID_leftMotor()
{

//might need float values
// you will have to determine kp, ki and kd
int kp = 1, ki = .01, kd = 3;

P_error   = desired_num_of_ticks - acctual_num_of_ticks;
I_error += P_error;
D_error  = P_error - prevP_error;

prevP_error = P_error

int duty = P_error*kp + Ithe _error*KI + D_error*kd;

analogWrite(leftMotor,duty);
}
end pseudo code

The way to tune the controller is to copy the encoder clicks per each sample in a array say 200 samples per motor.  This means two byte arrays of 200.  make a test function that allows for 200 PID cycles then it should (not required) stop the motors.  Then you can send out all of the data stored via uart to Hyper terminal on your PC.  If you use println() for each piece of data you can simple copy the data and paste it in excel to make a graph of the motor speed.  All you have to do in excel is select the first 200 lines of data and compare them to their respective time.  The time that each sample is know because you chose the frequency of the PID controller.

example of what data should look like in excel assuming 50ms sampling (.05s)

time s   encoder clicks
.05       0
.10      20
.15      30
.20      35
......


Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #31 on: June 10, 2009, 04:48:36 AM »
what would a suitable mcu be for this project, are we using a universal mcu or can we chose our own

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Community project: Encoder wheel
« Reply #32 on: June 10, 2009, 05:30:08 AM »
well, from what ive heard most people involved in building modules are using the attiny2313..
but it is completely up to you, the microcontroller can be changed later with not much effort.
Howdy

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #33 on: June 10, 2009, 05:33:17 AM »
great thanks for the clarification smash

Offline sonictj

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
    • Tim's Workshop
Re: Community project: Encoder wheel
« Reply #34 on: June 10, 2009, 12:30:25 PM »
I would recommend one of the atmega48/88/168 because they have more flash and sram.  my encoder code was too big for an attiny2313 even with full optimization.

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #35 on: June 15, 2009, 05:46:49 AM »
is this shematic correct

E = infared emitter

D= infared detector
« Last Edit: June 15, 2009, 05:48:27 AM by Joker94 »

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Community project: Encoder wheel
« Reply #36 on: June 15, 2009, 05:51:33 AM »
mate, get eagle! ;D i cant tell a thing by looking at that (no offense) although i don't know too much about encoders, do "E" and "D" stand for "emitter" and "detector? and by "atmega88" do you mean "atmega8"?
when you say "pin out to mother board" you mean I2C correct?
sorry for all the questions but im new to encoders too, and its hard to tell from the non-eagle file :D
if you want i could knock up a quick schematic of what you are saying?
« Last Edit: June 15, 2009, 05:59:00 AM by SmAsH »
Howdy

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #37 on: June 15, 2009, 06:06:43 AM »
i have eagle but i can not get a 28 pin chip on to my shematic.

the atmega88 is the chip sonictj recommendedand i did mention that e stands for emitter and d stands for detector

and if you were able to knock up a shematic and email me the jpg and eagle file that would be great

if you have any other questions of info i have left out just PM me

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Community project: Encoder wheel
« Reply #38 on: June 15, 2009, 06:16:30 AM »
the atmega88 is the chip sonictj recommendedand i did mention that e stands for emitter and d stands for detector
lol at your spelling ;D i take a look at the mega88, have you considered the 168?
Quote
i have eagle but i can not get a 28 pin chip on to my shematic.
oh ill find it, don't you worry about that *gets evil look in eyes*
Quote
and if you were able to knock up a shematic and email me the jpg and eagle file that would be great
ill get on that now... should be done in 5-10 mins ;D
Howdy

Offline sonictj

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
    • Tim's Workshop
Re: Community project: Encoder wheel
« Reply #39 on: June 15, 2009, 08:59:21 AM »
the atmega88 and atmega168 are of the same family which is why I recommended them.  I believe that they have the same features with the exception of flash memory.

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #40 on: June 16, 2009, 05:34:08 AM »
Thanks for the shematic smash, and now i know how to work eagle ;D

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Community project: Encoder wheel
« Reply #41 on: June 16, 2009, 06:47:54 AM »
any time mate :) if you need any more help give me a whistle ;)
Howdy

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #42 on: June 19, 2009, 07:10:25 PM »
1)Do i have to hook up the emitters and detectors to different  ports, eg. emitters to D pins and detectors to the B pins

2)will i have to be able to program the encoder through my mcu or can are you able to program it from the mother board.

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Community project: Encoder wheel
« Reply #43 on: June 19, 2009, 07:34:02 PM »
1. No, you tie the emitters to GND and through a resistor to Vcc. The detectors are tied to GND and to the microcontroller pin. You eighter need a pull up resistor there or turn ON the internal pull up resistors. I usually use external ones.

2. Yes, you need to program the microcontroller to read the encoders, eighter by polling or by interrupts.

Chat?
Check out the uBotino robot controller!

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #44 on: June 25, 2009, 11:21:37 PM »
sorry this is taking a while, this project has hit the back burner for the moment

in may be a week or a month untill i can get back into it

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #45 on: June 26, 2009, 02:49:31 AM »
what is an average robot velocity so i  can make some quick caulculations before i got any further with the mechanics

oh and wheel size
« Last Edit: June 26, 2009, 02:50:53 AM by Joker94 »

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #46 on: June 26, 2009, 03:04:27 AM »
Attached is the wheel design

Diameter =35 mm / 1.378"
Clicks=16
Space between clicks 6.78 mm
expected slip =5%

in my calculations i will use square numbers. 1 m/s robot velocity/, 100 mm /4" diameter wheel

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Community project: Encoder wheel
« Reply #47 on: June 26, 2009, 05:23:39 AM »
Velocity(m/s) = RPS * Wheel circumference(m)
Wheel circumference(m) = Pi(3.14) * Diameter(mm) / 1000
RPS = RPM / 60


If targeted Velocity is 0.5 m/s, RPM is 60 (standard servo) results a Wheel circumference of 0.5 m, or 500 mm. This is way too big for a servo. Let's calculate the other way around. The wheels that I have are 66.88 mm in diameter, that means the circumference is 210 mm or 0.21 m. For the same targeted velocity, the RPM should be Velocity * 60 / Wheel circumference, that is 0.5 m/s * 60 / 0.21 m = 142.857.

Now to calculate the encoder pulses. For the 210 mm wheel circumference, to have a traveled distance of 5 mm per click, I need 42 clicks per rotation. That means 21 white and 21 black stripes, or 21 holes in the wheel. I would like to have more precision than that, so I will try to mount the encoders directly on the back shaft of the motor that spins 51 times faster (that's the gear ratio) than the output shaft.
Check out the uBotino robot controller!

Offline Joker94Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: Community project: Encoder wheel
« Reply #48 on: June 26, 2009, 05:36:09 AM »
brilliant ;D

thanks Ro-Bot-X

Offline sanketjog

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: Community project: Encoder wheel
« Reply #49 on: July 01, 2009, 02:36:34 AM »
Can anyone please share the  encoder wheel feedback diagram using PID.....

 


Get Your Ad Here

data_list