Go Down

Topic: Help with this code and its algorithm¡¡¡¡¡¡ (Read 375 times) previous topic - next topic

Dani_Juarez

Good thing I'm new on this page to post hope to get it right hehe;
in short I have a code that I can not quite understand. It is a code to move a robot arm by serial port with the keyboard and store the variables and then execute them and save them if you want. what I can not understand is very well how it works every "Void" that has the code so if someone can give me a hand with a good explanation would help me a lot so I can develop their own code based on the understanding of this; here I leave them to go down I hope they can help me I would thank them very much  :)  :)  :)  :)  :)

PaulS

Quote
every "Void" that has the code
There are no "Void"s in your sketch. There are FUNCTIONS. That the return type is void matters not a whit.

The code seems relatively straight-forward. It is obvious that you didn't write the code. It seems equally obvious that you are trying to understand it so you can palm it off as your own.

So, you need to explain to us what YOU think it does, and we'll tell you whether you are right or wrong.
The art of getting good answers lies in asking good questions.

Dani_Juarez

There are no "Void"s in your sketch. There are FUNCTIONS. That the return type is void matters not a whit.

The code seems relatively straight-forward. It is obvious that you didn't write the code. It seems equally obvious that you are trying to understand it so you can palm it off as your own.

So, you need to explain to us what YOU think it does, and we'll tell you whether you are right or wrong.
exactly I did not write it and what I look for is to understand each void as they work and the algorithm that uses to move the servomotors what I am looking for is to keep degrees of each servo of my arm to save a box in principle
but my goal would be for my robot arm to be able to save 3 types of boxes of 3 different types of size so that I tell you what kind of box the 3 is and move in such a way that I save it where I program it but for that I want to understand this code so I would like very much if you can help me to understand it well to the letter

slipstick

If you don't understand any of it at all, not even that voids aren't called voids or what if or include mean, then you have no chance of successfully changing it to do something different without a lot of studying. Have you done any programming? In C++? Or what computer language?

BTW in English we use some CAPITAL letters. Also we write in sentences with punctuation. Without them it is very difficult to understand what you are trying to say.

Steve

jremington

#4
Oct 10, 2017, 02:07 am Last Edit: Oct 10, 2017, 02:08 am by jremington
Quote
what I look for is to understand each void function as they work
For a beginner, that may take hours or even days of study.

Do not be discouraged, and if you have specific questions about particular lines of code, post them on this forum.

Dani_Juarez

If you don't understand any of it at all, not even that voids aren't called voids or what if or include mean, then you have no chance of successfully changing it to do something different without a lot of studying. Have you done any programming? In C++? Or what computer language?

BTW in English we use some CAPITAL letters. Also we write in sentences with punctuation. Without them it is very difficult to understand what you are trying to say.

Steve
If I have programmed in C in C ++ and Arduino programmed it is programmed something I understand what I do not understand is the algorithm that uses in the "void execute_automata ()" and in the "void array ()" the others I understand them inside all good but those two Voids lock me in the program

jremington

Please read and carefully follow the directions in the "How to use this forum" post.

Dani_Juarez

For a beginner, that may take hours or even days of study.

Do not be discouraged, and if you have specific questions about particular lines of code, post them on this forum.
the "void execute automata ()" and in the "void translation matrix ()" I can not understand them completely well but I'll leave them here if I can help

Code: [Select]

void matriz_de_traslacion()
{
  Serial.print("\n\t\t\t\t\t\t\t\tCALCULO DE MATRIZ");Serial.print(figura);
  //convierte la EEPROM en matriz
  for(EE=0;EE<5;EE++)
  {
    memor[EE]=EEPROM.read(eprom);
    eprom++;
  }
  EE=0;
  //calcular diferencias
  diferencia[0] = abs (registro[0]-memor[0]);
  diferencia[1] = abs (registro[1]-memor[1]);
  diferencia[2] = abs (registro[2]-memor[2]);
  diferencia[3] = abs (registro[3]-memor[3]);
  diferencia[4] = abs (registro[4]-memor[4]);
  // se elimino la sección de filtrado (no hay vibraciones causadas por los potencio metros)
  //calcular limite de secciones (la mayor distancia)
  limite = max(diferencia[0],diferencia[1]);
  limite = max(limite,diferencia[2]);
  limite = max(limite,diferencia[3]);
  limite = max(limite,diferencia[4]);
  Serial.print("\n\t\t\t\t\t\t\t   LIMITE=");Serial.print(limite);
  //calcula dirección e incremento en grados de cada sección
  if(registro[0]>memor[0]) direccion[0]=(0-diferencia[0])/limite; else direccion[0]=diferencia[0]/limite;
  if(registro[1]>memor[1]) direccion[1]=(0-diferencia[1])/limite; else direccion[1]=diferencia[1]/limite;
  if(registro[2]>memor[2]) direccion[2]=(0-diferencia[2])/limite; else direccion[2]=diferencia[2]/limite;
  if(registro[3]>memor[3]) direccion[3]=(0-diferencia[3])/limite; else direccion[3]=diferencia[3]/limite;
  if(registro[4]>memor[4]) direccion[4]=(0-diferencia[4])/limite; else direccion[4]=diferencia[4]/limite;
  Serial.print("\n\t\t\t\t\t\t\t\tEJECUTANDO_MEMORIA ");Serial.print(figura);
  primer_seccion=false;
}

and this


void ejecutar_automata()
{
  if(seccion<=limite)
  {
    Serial.print("\n\t\t\t\t\t\t\t\tSECCION="); Serial.print(seccion);
    seccion++;
    if(seccion == 1)              time = retardo*4;      
    else if(seccion == 10)        time = retardo*3;  
    else if(seccion == 20)        time = retardo*2;
    else if(seccion == 30)        time = retardo*1;
    if(seccion == limite-40)      time = retardo*2;
    else if(seccion == limite-30) time = retardo*3;
    else if(seccion == limite-20) time = retardo*4;
    else if(seccion == limite-10) time = retardo*5;
    registro[0]+=direccion[0];
    registro[1]+=direccion[1];
    registro[2]+=direccion[2];
    registro[3]+=direccion[3];
    registro[4]+=direccion[4];
    servo1.write(registro[0]);
    servo2.write(registro[1]);
    servo3.write(registro[2]);
    servo4.write(registro[3]);
    servo5.write(registro[4]);
  }
  else
  {
    limite=0;
    seccion=1;
    figura++;
    primer_seccion=true;
  }


Those two Voids that are inside the program that let them down and see are those who can not understand their algorithm

AWOL

There seems to be a void (a hole, a gap) in your understanding.

Functions are called functions or subroutines, they are not called voids.

Please stop calling functions "voids"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up