openUC2 / UC2-REST

UC2 code for using the REST API with electronic modules (LED, motors, etc.)
Other
8 stars 3 forks source link

Must add delay when switching the movement-axis of the Stepper Motor #3

Closed SaeedSobhi closed 2 years ago

SaeedSobhi commented 2 years ago

Using the class ESP32Client from ESP32RestSerialAPI to control the stepper motor, one should add at least 3 seconds delay when switching the movement axis (x to y or y to x) otherwise the motor won't be able to respond to new moving order.

PS. the issue could be the Stepper Motor response time, not necessarily a bug in the JSON file or in the Python code.

beniroquai commented 2 years ago

Interesting, I think the code should work such that it waits until the action was performed. Did you set "isblocking" to true?

Am Do., 10. Feb. 2022 um 11:56 Uhr schrieb Sobhi Saeed < @.***>:

Using the class ESP32Client from ESP32RestSerialAPI to control the stepper motor, one should add at least 3 seconds delay when switching the movement axis (x to y or y to x) otherwise the motor won't be able to respond to new moving order.

PS. the issue could be the Stepper Motor response time, not necessarily a bug in the JSON file or in the Python code.

— Reply to this email directly, view it on GitHub https://github.com/openUC2/UC2-REST/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5OBFYRSSQDXCEKMN4WLU2OKT5ANCNFSM5OAKHPLA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

SaeedSobhi commented 2 years ago

"Is_blocking" was set to True, but I still have the same problem, I suggest a delay time of "max(3, steps-number//1000)" in the master code since we have to wait for the movement to be done before acquiring new data.

beniroquai commented 2 years ago

Hey, i have updated large parts of the code. Can you please follow the README and install the Arduino firmware and update the python code?;)

On Mon, Feb 14, 2022, 11:52 Sobhi Saeed @.***> wrote:

"Is_blocking" was set to True, but I still have the same problem, I suggest a delay time of "max(3, steps-number//1000)" in the master code since we have to wait for the movement to be done before acquiring new data.

— Reply to this email directly, view it on GitHub https://github.com/openUC2/UC2-REST/issues/3#issuecomment-1038930878, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5OBY2ZPTURORNN6FEOTU3DMHFANCNFSM5OAKHPLA . You are receiving this because you commented.Message ID: @.***>

SaeedSobhi commented 2 years ago

The new code works perfectly, no need to add any delay :) There's a small mistake in the python test code, still using "axis =1 or 2" even though we should use "steps = (x-steps, y-steps, z-steps)" instead

beniroquai commented 2 years ago

Hey, I have updated large parts of the arduino and python code. Would you mind testing it? It's important to outcomment only the line #include "pindef_STORM_Berlin.h" in the Main ino file. Can you check if this works?

This will also work with ImSwitch. Though I have to document this properly I guess..

SaeedSobhi commented 2 years ago

Hi, I tried the new code, it is working, although there are some issues:

  1. When out-commenting #include "pindef_STORM_Berlin.h" we have to add another "identifier_setup" otherwise we won't be able to compile the Arduino Code.
  2. The stepper motor is not responding to the first moving order, I had this error "Casting json string from serial to Python dict failed" but after the first order, it works fine, for example: if we have this code:

from ESP32RestSerialAPI import ESP32Client serialport1 = 'COM7' Motor = ESP32Client(serialport=serialport1) print("Move in X") Motor.move_stepper(steps=(2000, 0, 0), speed=100, is_absolute=False, is_blocking=True) print("Move in Y") Motor.move_stepper(steps=(0, 2000, 0), speed=100, is_absolute=False, is_blocking=True)

The motor will only response to the movement in Y direction, and the output would be: Move in X Casting JSON string from serial to Python dict failed Move in Y

  1. Please modify this line in the python test code: "esp32.move_stepper(axis=2, steps=100, speed=100, is_absolute=False, is_blocking=True)" "axis" is not defined in ESP32Client.move_stepper it should be: "esp32.move_stepper((steps=(0, 100, 0), speed=100, is_absolute=False, is_blocking=True)"
beniroquai commented 2 years ago

Hey, did you manage to get it working @SaeedSobhi ? Sorry, it'S still work-in-progress. @ranranking is also getting it to work in the meantime. Eventually he could help you.

Regarding your questions:

When out-commenting #include "pindef_STORM_Berlin.h" we have to add another "identifier_setup" otherwise we won't be able to compile the Arduino Code.:

Well yes, the pindef_*.h files gives you some hints about the configuration. The code can run many different hardware arrangements. I could add one for your ptychography setup if you want. You can now outcomment //#include "pindef_ptychography.h" and see if it works.

  1. Can you please test the new code? The message Casting JSON string from serial to Python dict failed should be fine. Just a warning..

  2. Indeed I changed the API. Thanks for pointing that out! :)

SaeedSobhi commented 2 years ago

Hi Bene, thanks for updating the code, the new code works perfectly!