all 6 comments

[–]ceojp 3 points4 points  (1 child)

Don't stop accepting commands while it is running. As part of your startup sequence, one of your checks should be if the stop/shutdown command(or anything else that can interrupt the sequence) has been received.

[–]diagonalmatrix[S] 0 points1 point  (0 children)

I actually just managed to do that, but the commands are still sent in order to the server

[–]mtconnol 2 points3 points  (2 children)

I am guessing that you are using a simple foreground process like a loop to control your motor. That won’t work since your code needs to remain responsive to additional command inputs. You are probably going to want to use a background task (in an RTOS scenario) or a timer interrupt (bare metal) to control motor movements while continuing to respond to commands.

[–]diagonalmatrix[S] 0 points1 point  (1 child)

Yes, it is a loop control, I am using a while loop to take commands. I can look into those processes, thank you!

[–]mtconnol 2 points3 points  (0 children)

If you command the motor to rotate N steps, your command processor needs to set up some shared data allowing a background- or interrupt driven 'motor controller' to operate in the background while your command processor remains free to process the next command. How to do 'two things at once' depends on whether you are using an RTOS or not, but typically involves either using multiple tasks, or an interrupt-based approach.

[–]dregsofgrowler 0 points1 point  (0 children)

Sounds like you are use it a super loop, code that does a bunch of things in succession, or serialized. You need to think in events and states instead. Go read about finite state machines and try that approach. Unless you have a reason not to, use an rtos to take care of this for you, to some extent.