Results 1 to 7 of 7

Thread: QThread or QTimer or something better for port control

  1. #1
    Join Date
    Feb 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QThread or QTimer or something better for port control

    hello, i am controlling with an arm system a GPIO port (similar like parallel port). The Port sends tacts to move step motors.

    My Problem is: If i just control the motors, than GUI doesnt work. Easy solution is: qApp->processEvents(). But than comes another problem. If i interact with my GUI, the motors doesnt running with constant speed, also tact frequency changes because of processEvents().

    I found that QTimer can give tacts till 1khz (also max. every 1 ms) but i need higher frequencies. Should i use a QThread? I have a 400Mhz process. He should be controll the motors and stay GUI "alive" without distortion.

    I also could improve QIODevice anyhow that he sends the commands(tacts) constantly.

    What would you prefer? I didnt found similar applications.
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread or QTimer or something better for port control

    I found that QTimer can give tacts till 1khz (also max. every 1 ms) but i need higher frequencies. Should i use a QThread? I have a 400Mhz process.
    Be warned, that normal PC's, or lets say, OS's, have a resolution of about ~1ms. (on user space level)
    So unless you are running this on a special real time system, you wont be able to get better resolution than 1ms.

    Now, even if you have system that has a micro second resolution, you can't use QTimer, since it has an ms resolution.

    My advice to you, in this case, is not to use Qt for controlling the motors, but just for GUI.
    Use a specializes realtime lib that is designed to control step motors, and run that in a separate thread than your GUI.

    If you still want to use Qt for controlling the motors, then you can either subclass QTimer, or, write your own triggering thread based on QThread (QThread as a usleep() which in microsecond resolution - but this is highly dependent on the system it runs on!)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread or QTimer or something better for port control

    i also saw right now that qthread has usleep(), also in microseconds, which should solve my problem, but i didnt still made a hardware test.

    you mean there is a realtime lib for motor controlling? i couldnt find it, but for me is just important that the motors doesnt stop just because of GUI calls, also i dont expect high resolution.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QThread or QTimer or something better for port control

    I assume you are trying to implement some sort of pulse width modulation or the like (RC servos come to mind). The typical approach to this is hardware timers that run independently, which means low level, timer interrupt driven code that keeps the signals up to the device while providing a higher level interface for a control UI.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread or QTimer or something better for port control

    you mean there is a realtime lib for motor controlling?
    No, (although there might be) I meant what ChrisW67 said.
    Such tasks usually are not done by a high level systems, but very low level, where you use the hardware timers, and/or dedicated PWM modules.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Feb 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread or QTimer or something better for port control

    hello,

    i made some hardware test and didnt get really what i wanted.

    Principal works it alright but the motors (3 of them) running very slowly. Anyway works GUI normal and doesnt affect on motors. If i set the usleep time for 1microsecond, then usleep(1) is almost ignored and GUI affects on the motors. The motors doesnt turning but i hear the sound how its change if i use the GUI.

    I think usleep(1) is just useless.

    Can i make another pause with QMutex or Interrupts something like this? processEvents() is useless also, because it prefers GUI events than Outputevents.

  7. #7
    Join Date
    Feb 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread or QTimer or something better for port control

    i would just declare my solution after months

    The solution is to develope a device driver under linux (char driver). Also user-land applications are not precise enough to control stepmotors.
    I heard that windows will soon enable to programm the device drivers easily like linux.

Similar Threads

  1. Using a QTimer to control a QProgressBar
    By cejohnsonsr in forum Newbie
    Replies: 2
    Last Post: 26th August 2010, 22:34
  2. qthread / qtimer
    By Galen in forum Qt Programming
    Replies: 5
    Last Post: 17th April 2010, 22:57
  3. QThread and QTimer
    By sivrisinek in forum Qt Programming
    Replies: 4
    Last Post: 30th April 2009, 16:41
  4. QThread & QTimer
    By hosseinyounesi in forum Qt Programming
    Replies: 5
    Last Post: 13th April 2009, 08:22
  5. how to control 32 com port through application
    By amit_pansuria in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 06:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.