Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add PIO example for servo control#29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
zeroflow wants to merge9 commits intoraspberrypi:master
base:master
Choose a base branch
Loading
fromzeroflow:master

Conversation

@zeroflow
Copy link

Controls one servo at GP16 and additionally the onboard LED
This demonstrates use of two servos.

Controls one servo at GP16 and additionally the LED (to see, if it's doing anything, and to demonstrate usage of two servo outputs)
@aallanaallan added the enhancementNew feature or request labelApr 8, 2021
@aallan
Copy link
Contributor

Could you add aREADME.adoc file and accompanying wiring diagram, similar to that found in other examples, e.g. seethe NeoPixel ring example.

@lurch
Copy link
Contributor

lurch commentedApr 8, 2021
edited
Loading

Nice PIO example 🙂
Just a couple of queries: a) the comments talk about "IRQ4", but the code seems to be using relative IRQs? b) is there a reason for using relative IRQs, or would it make sense to use an absolute IRQ so that a single ServoTrigger could be used for multiple Servos?

@zeroflow
Copy link
Author

I will add a readme.

Regarding IRQs: Sharing the IRQ did not work, so I used relative IRQs.
That way, the Trigger needs to be the SM before the output program, so the IRQs match.

@aallan
Copy link
Contributor

Regarding IRQs: Sharing the IRQ did not work, so I used relative IRQs.
That way, the Trigger needs to be the SM before the output program, so the IRQs match.

Sounds like this should be in the README! :)

@lurch
Copy link
Contributor

Regarding IRQs: Sharing the IRQ did not work, so I used relative IRQs.

I hope you don't mind, but I had a bit of a fiddle.... 😉 (I'm still getting to grips with PIO myself)

I was able to get it working with only a singleServo_Trigger object by changingservo_trigger() to do:

    irq(clear, 4)         # Clear IRQ4, allows servo code to run again    irq(4)                # Set IRQ4 again, ready for the wait in servo code

(which I guess then means I need to change the trig_ctr calculation totrig_ctr = (trig_frq // 1000 * trig_target) - 4), and changingservo_prog() to do:

    wait(0, "irq", 4) .side(0) # Wait here for IRQ to be released by trigger SM

😀

Other comments:

  • As this is purely an example, it might be more useful to change thefor _ in range(2): towhile True: ?
  • IMHO theServo_Trigger class ought to be renamedServoTrigger (which is the typical Python convention)
  • Given the wide variability of servos, it's probably worth addingmin_pulse andmax_pulse arguments to yourServo init-method, and then doing
self.base_pulse = min_pulseself.free_pulse = max_pulse - min_pulse

But of course these are only suggestions, I'll leave the final decision up to you.

@zeroflow
Copy link
Author

I don't mind - I'll check your suggestions later. During my testing, the 1-Trigger 2-Servo code compiled, but the output was garbage.

@zeroflow
Copy link
Author

Thanks! The replacement with IRQ/Clear + Wait did work.

lurch reacted with hooray emoji

@lurch
Copy link
Contributor

When testing the changes that I mentioned above, I had three separate servos all running from a single trigger :) But I had to insert some sleeps between moving each servo individually, because if I tried moving multiple servos at the same time, it tried to pull too much current from my computer's USB port and the Pico reset. (this is fixable by powering the servos from a separate PSU, but I couldn't be bothered to wire that up!)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

enhancementNew feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@zeroflow@aallan@lurch

[8]ページ先頭

©2009-2025 Movatter.jp