How to implement an operation loop and maintain a GUI responsive (PyQt)

asked 2020-01-30 09:08:37 -0500

Hyperion gravatar image

updated 2020-01-30 16:06:51 -0500

HI,

My problem is to develop a cartesian robot. I already finished the communication with the robot, but when I apply a certain group of coordinates, due the time needed for complete a loop/cycle to determine if the points is reached, a GUI made by me in PyQt freezes until the robot finish the trajectory. I solved this part by adding a QThread to the class responsible to do the movement, but other problem appears...the robot now only can perform the first coordinate and cannot publish the second and the next coordinates due a problem:

raise ROSException("publish() to a closed topic")

For me, the thread maintain publish occupied with first coordinate and don't leave the process. Even using QMutex can't solve the problem.

I used this tutorial: http://www.aizac.info/the-easiest-way...

..to base me in use of rospy.spin() (because the rospy.spin() prevent the PyQt GUI to even open) but no success.

In resume: my robot works with coordinates passed, but freezes GUI; Using QThreads, the freeze problem is solved, but lock the publish.

Thanks in advance and sorry for my bad english.

edit retag flag offensive close merge delete

Comments

This is rospy. You don't need to run spin(). It does nothing but sleep.

If this was roscpp, things would be different (and you could use an AsyncSpinner fi).

gvdhoorn gravatar image gvdhoorn  ( 2020-01-30 10:32:38 -0500 )edit

I already done that. Removed the rospy.spin(), works ok. But the problem is not this, is the loop I need to place inside to do the operations. The robot (and proccess) need to do this:

  1. Start a conveyor to work and move an object to be palletized;
  2. Receive the object and activate a pneumatic stopper to stop the movement of this object;
  3. Stop conveyor;
  4. Calculate the trajectory (all coordinates) to approach the object (this project has more than 36 different objects with different sizes);
  5. Catch the object with vaccum;
  6. Remove the object from conveyor;
  7. Place the object above a pallet according to the points calculated by the size of object and pallet;
  8. Repeat this proccess until the pallet reach the maximum capacity for current object;
  9. Wait someone to remove the pallet full.

This loop is not infinite, but requires a certain time. That's why the GUI freezes. I ...(more)

Hyperion gravatar image Hyperion  ( 2020-01-30 15:59:21 -0500 )edit