Welcome new user! You can search existing questions and answers without registering, but please register to post new questions and receive answers.
Welcome to JeVois Tech Zone, where you can ask questions and receive answers from other members of the community.

How to interrupt a while loop with an external command

0 votes
I am using the JeVois A33 cam for object detection and recognition and I have a Python problem. I want to interrupt a while loop with an external command via 4-Pin Hard serial from an Arduino. Inside this loop the parseSerial will not function. Do I have another possibility to receive a comand (f.e. the string "stop")  inside the while loop in my JeVois cam software, coming from the Arduino, so I can interrupt the loop in my A33 software?

I tried also import serial, but I got an error message.

Perhaps someone can help me with my problem. Thank you very much.
asked Jan 28 in Programmer Questions by Peter (260 points)

1 Answer

0 votes
Could you post a code snippet?

From what you've said, I'd look at using signal https://docs.python.org/2/library/signal.html
answered Jan 28 by PeterQuinn (940 points)
Thank you for your time. I tried the example but it did produce an error in the JeVois environment. Have you tried it in the environment of JeVois? If yes, be so kind and send me an example. Do you have another idea too?
Greetings
Peter
yes, or you could also think of letting jevois run your main loop. If you are running your own main loop, then indeed you are 1) blocking serial inputs as you noticed, 2) dropping camera frames, and 3) choking the video output to USB (if your module does that). Have a look here for how the main loop works http://jevois.org/doc/Concepts.html section on "operation with streaming video output".

This is a bit like having Qt, OpenGL, or other graphics/GUI toolkits run the main loop for you. You should then restructure your code so that the main loop is run by JeVois, and it calls process() on every loop iteration. You can then do in process() what you used to do inside your loop, and get rid of the loop.

Based on your post, I would implement parseSerial() to handle the "stop" command and just set a flag (a member variable of your class), say, "stopRequested" to true. In your class constructor you initialize stopRequested to false. Then in process() you would check the value of stopRequested and act accordingly.
Well. Perhaps I have to explain what I am doing. I use the JeVois cam for face detection and recognition and I always want to have the face in the middle of the picture. Therefor I use 2 servos for moving the cam. The problem now is, that the face recognition works perfect, but very slowly. So I use first the face detection (it is realy faster than the recognition) to bring the cam in the right position. After this I change from face detection to face recognition and then I see witch person I can see and the cam is looking to him. Here I use a while loop to see, wether the cam stays  in the middle position (with the values for x and y of the face). If the person moves, the while loop is automatically finished (x and y leaves the middle of the picture) and I can change from recognition to detection. So the cam can follow the person quickly  until the face is again in the middle of the picture. Now I change again from detection to recognition. That all is functioning perfect. My only problem now is. If the face is in the middle of the picture, I am inside the while loop and here I need a possibility, to leave this loop by an external command from the Arduino (this means that I want to leave the recognition part and want to do other things).
Here I need an Idea.
Greetings Peter
OK. I found a solution. It is not the best but it functions. Thank you for all tries to help me.
Best regards
Peter
...