0

If this seems familiar, it's because this is a more-specific rework of a bad question.

Currently coding with gpiozero, but I'm not wedded to it. If I have mixed activities, such as compute tasks and real-world activities, how do I synchronise them?

For example, if I send a position command to a servo, i may want to wait for it to reach its new position before proceeding — or I may want to let it complete asynchronously while I perform some other task, and then then come back and

  1. Wait for the servo to complete the earlier request,
  2. Check to see if the servo has completed its request and take appropriate action, or
  3. Issue a new command regardless of whether the previous one has completed.

(Among other options.)

Is there anything built into gpiozero, or other libraries, that allow real-world activities to be 'farmed out' and then rendezvous with them after other stuff has been done and the RW activity is now a gating factor? Or do I need to write my own?

[edit]
I'm currently unhappy with pigpio because of its apparently hard-coded assumption of single-process access to the dæmon it uses to coördinate GPIO access. I.e., I cannot use it to experiment with multiple cooperating processes.

For now, I'm playing with subclassing AngularServo from gpiozero, whose class description says (with some inclarity) that the developer should determine the appropriate values for min_angle and max_angle empirically, moving the servo to the extremes and determining the appropriate values therefrom. Similarly, for now, I'm willing to determine the approximate rotation speed (s/°) from observation and add some slop in order to calculate the approximate duration any particular angular change is likely to take.

I'm doing this as an exercise, and until I find some library mechanism to do it.

7
  • 1
    That is an unfortunate example as hobby servos do not provide any information as to where they are or where they are going (if anywhere). They go to the commanded angle as quickly as possible and then stop (unless they are commanded to go somewhere else in the meantime).
    – joan
    Jul 25, 2023 at 21:37
  • I wouldn't use gpiozero for a servo. While gpiozero is an excellent piece of software it has no support for hardware PWM. Use pigpio, either on its own or as factory for gpiozero.
    – Milliways
    Jul 25, 2023 at 22:45
  • @joan Let's assume I have reasonably accurate figures for the servo's angular speed, under load or otherwise. The question of how to synchronise remains.
    – RoUS
    Jul 26, 2023 at 1:05
  • @Milliways: I'm not sure what you mean by 'use it as a factory for gpiozero, unless you mean the pin factory aspect. I looked into that, but my experimentation indicated it a) just complicated matters, and b) dragged in the single-process GPIO issue which is keeping me away from pigpio in the first place. See the edits I made to the question. The synchronisation question seems unanswered.
    – RoUS
    Jul 26, 2023 at 1:09
  • I meant pin factory. I admit I have rarely used these - if I want to use pigpio I use it directly. There are servo examples on @joan site which I have used and I also use my own PWM code. AFAIK gpiozero only supports software PWM because RPi.GPIO doesn't have hardware PWM - which results in servo jitter.
    – Milliways
    Jul 26, 2023 at 2:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.