![]() |
| Joystick-controller in threadings - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Joystick-controller in threadings (/thread-43642.html) |
Joystick-controller in threadings - MacTommy - Dec-05-2024 Sitting in a small Raspberry Pi project to controll stuff in lightingconsoles with a Joystick. Has some issue with timing and wondering if I should separate the part that reads the position of the joystick and the part that sends OSC-commands to my lightconsoles. My first test when everything was in the same loop, I wasn't happy with the timing. Short version of my project, because I don´t wnat someone to solve my project. Just give me some hints. ;) import OSC import threading #initialize OSC send_to_adress = '10.101.11.27', 8000 c = OSC.OSCClient() c.connect(send_to_adress) def send_OSC() # Read floating joystick value for X and Y if -0.2 <= LeftJoystickX <= 0.2: # Send OSC for X-movment threading.Thread(target=send_OSC).start() while True: # Save floating joystick value for x and y to memorySo I have my own thread´s that checks if values is outside dead limit´s on my joystick and start sending OSC. Don´t bother the if < and >... I solved it in the final release. ;) What is the fastest way to move floating values between my "while True:" and my "def send_OSC():"? Do it work with globals or should I memory allocate my values (if I can do that in Rasperry Pi)? EDIT: Because I only need to send value 1 and -1 to my lightingconsoles I'am going to let my joystickposition be a "timertrigger" when to send my next OSC-command that says 1 or -1. RE: Joystick-controller in threadings - deanhystad - Dec-05-2024 It is unclear from your description, but it sounds like the joystick will be some kind of integrator. The longer you hold the joystick up/down, the more it changes some value. Is that correct? If so, I think your problem is opposite what you state. I think you need to add a delay to reading the joystick and sending the osc command. Something that makes the time between consecutive commands the same. I would use a threading timer to periodically call the send_OSC() function. As far as sharing information, you can do that with a globally scoped variable, or you could write your code using classes and use instance variables. If you don't like either of those, you can use a mutable container object, like a list or dictionary. A dataclass would be a great choice for this, but I don't think those are available in micropython. RE: Joystick-controller in threadings - Larz60+ - Dec-05-2024 you might find this useful. RE: Joystick-controller in threadings - MacTommy - Dec-06-2024 (Dec-05-2024, 03:23 PM)deanhystad Wrote: It is unclear from your description, but it sounds like the joystick will be some kind of integrator. The longer you hold the joystick up/down, the more it changes some value. Is that correct?All Joystick I tried so far send a float value from -1 to 1 with zero in middle for X and Y (like a potentiometer). My normal proffesion is technician on a theater with a motorized hoist system. They use a square pulse to sync the movment between couple of motors to synchronize them. My idea is recalculate my float-value to trig against a square pulse and send my value 1 or -1... or if i just use couple of time variables, but I would keep my latecy as low as possible. :) RE: Joystick-controller in threadings - MacTommy - Dec-06-2024 (Dec-05-2024, 04:27 PM)Larz60+ Wrote: you might find this useful. Try diffrent Joystick controller package, but they have some issues all of them if the Joysticks has more axle then X and Y. Now I just would keep down the latecy between reciving axis-value to send my OSC-command. |