Python Forum
Joystick-controller in threadings
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Joystick-controller in threadings
#1
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 memory
So 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.
Reply
#2
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.
MacTommy likes this post
Reply
#3
you might find this useful.
Reply
#4
(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?

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.
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. :)
Reply
#5
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python and DMX (aka, light controller) ScottAF 4 7,478 Apr-06-2023, 07:09 PM
Last Post: ScottAF
  How can flask find the controller? 3lnyn0 3 2,948 Jul-08-2022, 10:05 AM
Last Post: Larz60+
  Controller Buzzer as Distance Decreases barkster 6 4,476 Nov-01-2021, 03:26 PM
Last Post: barkster
  Pygame with joystick mmagner2022 1 2,712 Aug-06-2021, 07:56 PM
Last Post: SheeppOSU
  Auto re-pair / re-sync Controller via Script? User3000 2 3,757 Nov-30-2020, 11:42 AM
Last Post: User3000
  Tuning PID controller Sancho_Pansa 4 7,371 Nov-09-2020, 07:51 AM
Last Post: Sancho_Pansa
  mapping joystick axis to specific 'channels' in python DashOrion 1 4,600 Jul-07-2020, 04:26 PM
Last Post: DashOrion
  Xbox Controller arki 0 2,544 Jun-30-2020, 10:32 AM
Last Post: arki
  Please help! Akai APC20 midi controller script versusliveact 0 3,154 Feb-14-2020, 05:37 AM
Last Post: versusliveact
  managing command codes for external controller box Oolongtea 0 2,734 Sep-19-2019, 08:32 AM
Last Post: Oolongtea

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.