fallo programa particular para mover el robot Escornabot

95 zobrazení
Přeskočit na první nepřečtenou zprávu

Francisco Casasola del Pozo

nepřečteno,
28. 11. 2021 8:40:1128.11.21
komu: accelstepper
Hola he descubierto el robot Escornabot, me parece fantástico, lo he imprimido y montado y he hecho un programa, el cual adjuntaré.

 Utilizo un teclado con cinco pulsadores, cada uno de ellos tiene asociado un CHAR: Padelante 'A', Patras 'R', Pderecha 'D', Pizquierda 'I' y la tecla Pactiva sirve para activar el movimiento.

Los caracteres los introduzco en una matriz i una vez introducidos  poniendo Pactiva en HIGH, un ciclo FOR  en el cual he implementado la función SWITCH....CASE va leyendo la secuencia  de carácteres introducida i en la matriz[i] que he creado y llamando a las funciones voidADelante(), voidATras(), etc....

 Bien, este es el funcionamiento que he pensado (que se ajusta a mis conocimientos básicos de programación), pero ocurre que cuando  ejecuto el programa solo activa la primera entrada que una vez ejecuta el robot se para, parece que no encuentra el camino para ejecutar la segunda entrada.
Una apreciación este programa lo he utilizado con otro robot y motores DC y me ha funcionado bien, tiene el inconveniente de la dificultad de regular la velocidad.

Espero que el programa que os envío se entienda y cualquier ayuda será bienvenida.

Saludos cordiales.

Francisco Casasola

Ejemplo CUATRO libreria AccelStepper SWITCHCASE.doc
Ejemplo_CUATRO_libreria_AccelStepper_SWITCHCASE.ino

Ian Bowden

nepřečteno,
28. 11. 2021 12:38:4528.11.21
komu: accels...@googlegroups.com

Hola Francisco,

The line after  matriz[i]=0;  

i=0;      It will make only one step, i=0.  This is the problem.  Remove i=0;


Ian.

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/227af24a-b044-48e9-b0a8-38e913741afan%40googlegroups.com.

Francisco Casasola del Pozo

nepřečteno,
28. 11. 2021 14:26:3628.11.21
komu: accelstepper
Thanks, I already saw this problem, I have already removed it but it does not work. The program continues not working, it only executes the first instruction that I enter.
Thanks.

gjgsm...@gmail.com

nepřečteno,
28. 11. 2021 17:01:2928.11.21
komu: accelstepper
Hi Francisco,

I see two possible issues.
  1.  the 'for loop' for your 'switch' statement only counts 2 times (0 to 1) out of 4 possible cases.
  2.  the input pins for your direction control could be floating unless you have pull_down resistors.
    This might cause a random input result.
My preference for the input pins would be to make them HIGH on boot using...
... pinMode(Pizquierda,INPUT_PULLUP);
and then pull them LOW when the button is pressed.
(Of course, the buttons would need to be connected to Vcc via a 1Kohm resistor)

The code will then also need to changed...
    if ( digitalRead(Pizquierda) == HIGH )    //pulsador para retroceder
will change to...
    if ( digitalRead(Pizquierda) == LOW)

Geoff


Google translation...
_________________________________________________________________________________________________________
Hola francisco

Veo dos posibles problemas.
1. El 'bucle for' para su declaración 'switch' solo cuenta 2 veces (0 a 1) de 4 casos posibles.
2. Los pines de entrada para su control de dirección podrían estar flotando a menos que tenga resistencias pull_down.
Esto puede provocar un resultado de entrada aleatorio.

Mi preferencia por los pines de entrada sería hacerlos HIGH en el arranque usando ...
... pinMode (Pizquierda, INPUT_PULLUP);
y luego tire de ellos LOW cuando se presione el botón.
(Por supuesto, los botones deberían estar conectados a Vcc a través de una resistencia de 1Kohm)

El código también deberá cambiarse ...
     if (digitalRead (Pizquierda) == HIGH) // pulsador para retroceder
cambiará a ...
     if (digitalRead (Pizquierda) == LOW)

Geoff

Jim Larson

nepřečteno,
29. 11. 2021 0:19:5629.11.21
komu: accelstepper
Francisco -
Tracing through your code makes me think that your problem really has nothing to do with the AccelStepper library and everything to do with managing your instruction queue. Sadly, I am an American and speak and read only English, so I haven't really read your original post. I'm assuming your goal is to be able to input a series of desired moves, then press the Action button to have them execute in sequence. If that is correct, then your programming logic won't work. The first command will be read, then it and all subsequent commands will be deleted and nothing more will happen. You should, by the way, have a "default" clause in your switch statement to alert you when no command is found.
I strongly suggest you take a step back and get your logic working, then add the AccelStepper commands. What you want to do is interesting, but not trivial. I plan to look further at it, but I wanted you to know the basic problem as I see it.
BTW, Geoff's suggestions are good, they seem to make the circuit simpler.
One other point: calling setSpeed() when you are using run() is pointless. The speed will be set by maxSpeed , acceleration, and distance to the target and recalculated each time run() or move() is called.
HTH!

gjgsm...@gmail.com

nepřečteno,
29. 11. 2021 0:54:3929.11.21
komu: accelstepper
Francisco  and Jim,

I had another look and it does look like some pins are not being read and any 'actions' and/or functions relating to STOP and MOVE appear to be missing.

I have attached my english 'translation' of the code in cpp file format (the file extension can be manually changed to ino) but it is very handy to load into Notepad++ or PlatformIO app for greater ease of editing rather than using the Arduino IDE.

Geoff

Ejemplo CUATRO libreria AccelStepper SWITCHCASE_GJS.cpp

Jim Larson

nepřečteno,
29. 11. 2021 19:24:0729.11.21
komu: accelstepper
Here is a working version of the code that does what Francisco wanted to do - at least, I think it's what he wanted.
Comments and questions are welcome if it's not clear what's going on.
UnoAccelStepperForumEjemploTest1.ino

Francisco Casasola del Pozo

nepřečteno,
9. 12. 2021 14:10:5709.12.21
komu: accelstepper
Sorry for not answer your email, next Monday I will be available for testing your code. We will continu next week one once I have tested your code.

Thanks very much.

Francisco Casasola del Pozo

nepřečteno,
16. 12. 2021 12:31:4816.12.21
komu: accelstepper
I think I understand how your program works. Tell me, if my explication is right: Initially, Initially, the values ​​are assigned to the first four positions of the array. The state variable is assigned the READ_CMD case. As i = 0, the program goes to the Advance () function, from here it reads the contents of Advance () and executes RUN_CMD. The motor rotates until both reach the indicated position, then the IF function is fulfilled, then it returns to READ_CDM increasing the variable "I" which becomes i = 1; Sorry for my Google English.

Jim Larson

nepřečteno,
16. 12. 2021 23:46:2116.12.21
komu: accelstepper
Again, I apologize for my poor Spanish - I won't even try. I hope you can translate this OK. Please ask again if it's not clear.

Hardware configuration:
There are 5 buttons, 4 of them are commands to move to a position - the 5th is the Activate button.

Program operation:
In the initial state (GET_CMDS), each button is read if it is pressed. The associated commands will be placed in sequence into the matrix. Up to 29 commands can be entered. (Note that I don't check to see if there is an attempt to enter more. That should be an error!) Once you are done entering commands, press the Activate button and the state will be changed to READ_CMD.
In the READ_CMD state, each entry in the array is examined and the appropriate routine will be called to set up the desired moves, one command at a time. The state will then be changed to RUN_CMD.
In the RUN_CMD state, run() is called for each motor until they both reach there programmed positions. Then the state is changed back to READ_CMD.
In the READ_CMD state, another command is read and RUN_CMD is entered again. This continues until all the commands in the matrix have been read. Then a null(0) will be read and this will cause the matrix to be initialized to all 0 (null) and GET_CMDS state will be entered to read commands again and repeat the process.
The STOP_CMD state is never entered unless something strange happens.

Francisco Casasola del Pozo

nepřečteno,
18. 12. 2021 12:08:4318.12.21
komu: accels...@googlegroups.com
Thanks Jim, I have tried to follow your indications, at the moment I still don't have a satisfactory solution. 
Thanks.

You received this message because you are subscribed to a topic in the Google Groups "accelstepper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/accelstepper/PfUfpb5WxVw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/95fa1042-0b3c-4f22-b437-4a58c8ae327en%40googlegroups.com.

Jim Larson

nepřečteno,
18. 12. 2021 23:58:3918.12.21
komu: accelstepper
Here is a user's view of the program, Francisco. Perhaps it will help you understand it. I will try again if this still doesn't make sense.

How to use the program:
There are two stepper motors. There are five buttons that control the motors.
Four of the buttons (Izquierda, Adelante, Derecha and Patras) program possible motions of the two motors.
When any of these buttons is pressed, the motion for that button will be recorded for future action. Up to 29 presses will be remembered. No action will happen yet.
The fifth button is the Activa button. When it is pressed, the recorded button presses will be activated, one at a time. That means the motion for each button that was pressed will be executed by the motors. The motions will be done one at a time until all the motions that were requested (by pressing the buttons) are executed.
When all the actions are complete, another sequence of buttons may be pressed. When Activa is again pressed, the sequence will be executed.
This can be repeated as desired.

Francisco Casasola del Pozo

nepřečteno,
21. 12. 2021 11:04:3721.12.21
komu: accelstepper
In the program sent by Jim I have added the routine (GET_CMDS) to enter the data of the sequence of movements and the button to activate the movement. If I enter a single movement, for example (A to advance), the program executes, but if I enter two or more movements, the program always executes the last one, skipping the previous ones. I don't know where the problem is. Is it possible that the approach is wrong? This program works for me by replacing the PaP motors with DC motors and the L298N driver. Attached program. Thanks
Ejemplo_CUATRO_libreria_AccelStepper_SWITCHCASE.cpp

Jim Larson

nepřečteno,
21. 12. 2021 16:33:1021.12.21
komu: accelstepper
In the clause
if ( digitalRead(Pactiva)==HIGH) //pulsador para activar el movimiento/ push botton to active movement
                          {  
                             ;
                            state= READ_CMD;
                           }
you must insert the line
i = 0;
You must do that to reset the counter or only the last command you enter will be executed.

Francisco Casasola del Pozo

nepřečteno,
23. 12. 2021 11:42:0523.12.21
komu: accelstepper
I already did this test but initializing to i = 0; no value is loaded (A, R, I or D) and the program does not run. However, I have initialized to i = 1; and the program WORKS. Many thanks to Jim for the suggestion. I am now programming a routine to reset the array [i] = 0 after the entire sequence entered by the keyboard has been executed. I will report on the progress. Thanks.

Francisco Casasola del Pozo

nepřečteno,
23. 12. 2021 13:02:4123.12.21
komu: accelstepper
I have implemented the following solution to clear the contents of the array, reset the counter, and shut down the PAP engines.

case STOP_CMD:

       i=0;// delete counter
       //delete array content
       memset(matriz, 0,30);
       puts(matriz);
       delay(10);
       delay(1000);  
       //turn off PaP
       for (int j=0; j<12;j++)
         {
          digitalWrite(j,LOW);
         }
   
    state=GET_CMDS;
      break;

Ejemplo_CUATRO_libreria_AccelStepper_SWITCHCASE.cpp
Odpovědět všem
Odpověď autorovi
Přeposlat
0 nových zpráv