Você está na página 1de 3

Hi Irvin !

, The encoders are used to control the real speed of the robot (which is
very useful). I'm working on a code for Open Lamborghino with encoders (It's a
little limited, because I'm only occupying one channel per engine, but I've been
surprised by the capacity it has). The first thing is to use it with
interruptions ... without interruptions, nothing makes sense.

Separating the movements of the robot as angular velocity (that the robot remained
static in the line) and linear speed (like any speed that is applied to the robot
other than to keep it in the line).

Once clear that, you can make a code like this, for linear speed.

void OpenLamborghino::vel() {

timeNow = micros();
if ((timeNow - timeBefore) > (sampletime)) {
velrealiz = ((Drueda * 3.14) / ppr) * (1000000.0 / sampletime) * (PasosIz - n);
velrealde = ((Drueda * 3.14) / ppr) * (1000000.0 / sampletime) * (PasosDe - m);
velprom = (velrealiz + velrealde) / 2;
timeBefore = timeNow;
controlador();
n = PasosIz;
m = PasosDe;
}
}

int OpenLamborghino::controlador() {
FBtimeNow = micros();
if ((FBtimeNow - FBtimeBefore) > (FBsampletime)) {
if (velocid == 0) {
Pow = 0;
}
if (velprom < velocid) {
Pow++;
if (pow > 255) {
pow = 255;
}
} else {
Pow--;
if (pow < 0) {
pow = 0;
}
}
FBtimeBefore = FBtimeNow;
}
return Pow;
}

Si tienes unos buenos encoder, digamos de 1600 cuentas por revolucin a 10.000 rpm,
un buen sampletime es de 1 ms, ya que en ese tiempo, la cantidad de datos
recolectados en ms que suficiente para obtener un feedback preciso de la
velocidad. Ahora, si tus encoder son de 16 cuentas por revolucin del eje, entonces
un sampletime adecuado es de 100 ms. En qu afecta eso?, bueno, mientras ms
pequeo tu sampletime, ms rpido ser el feedback y la correspondiente correccin
de la velocidad.

Otra cosa ms... para procesadores no muy grandes como el atmega328, lo mejor es
corregir velocidad lineal como sale en la funcin controlador(). ya que un pid
requiere de un feedback con ms datos. Esto es rpido y aceptable para comenzar a
trabajar con el nivel 2.

Saludos desde Chile Amigo!


Hi Irvin!, the encoder serve to control the real speed of the robot (which is very
useful). I'm working on a code for open lamborghino with encoders (it's a little
limited, because I'm only occupying an engine channel, but I've been surprised at
the ability it has). The first thing is to use it with interruptions... no
interruptions, nothing makes sense.

Separating robot movements as angular velocity (that the robot stays static on the
line) and linear speed (like any speed that is applied to the robot other than to
keep it on the line).

Once that's clear, you can make a code like this, for linear speed.

VOID OPENLAMBORGHINO :: Vel () {

Timenow = Microphones ();


if ((timeNow - timeBefore) > (sampletime)) {
Velrealiz = ((DRUEDA * 3.14) / PPR) * (1000000.0 / Sampletime) * (pasosiz - n);
Velrealde = ((DRUEDA * 3.14) / PPR) * (1000000.0 / Sampletime) * (pasosde - m);
Velprom = (Velrealiz + Velrealde) / 2;
timeBefore = timeNow;
Controller ();
N = Pasosiz;
M = Pasosde;
}
}

Int Openlamborghino :: Controller () {


Fbtimenow = Microphones ();
if ((FBtimeNow - FBtimeBefore) > (FBsampletime)) {
if (velocid == 0) {
Pow = 0;
}
if (velprom < velocid) {
Pow++;
if (pow > 255) {
pow = 255;
}
} else {
Pow--;
if (pow < 0) {
pow = 0;
}
}
FBtimeBefore = FBtimeNow;
}
return Pow;
}

If you have some good encoder, say 1600 accounts for revolution at 10.000 RPM, a
good sampletime is 1 MS, since at that time, the amount of data collected in more
than enough to get a precise feedback Of the speed. Now, if your encoder is 16
accounts per axis revolution, then a suitable sampletime is 100 MS. What affects
that?, well, the smaller your sampletime, the faster the feedback and the
corresponding speed correction.

One more thing... for not very large processors like the atmega328, the best is to
correct linear speed as it comes out in the controller function (). As a pid
requires feedback with more data. This is quick and acceptable to start working
with level 2.

Greetings from chile friend!

Você também pode gostar