简体   繁体   English

Raspberry pi 使用按钮作为伺服开关

[英]Raspberry pi using a button as a toggle for a servo

I have a raspberry pi using pigpio to control two servos with two buttons.我有一个树莓派,它使用 pigpio 来控制两个带有两个按钮的伺服系统。 Right now I have to hold the button to make the servo move.现在我必须按住按钮才能使伺服移动。 I want the buttons to toggle the servos between the two positions, but my attempts fail.我希望按钮在两个位置之间切换伺服系统,但我的尝试失败了。

I'm on mobile so i put a picture of my code, sorry I couldn't paste it.我在手机上,所以我放了一张我的代码图片,抱歉我无法粘贴它。 Code Picture代码图片

Note: the commented code is from when i was using gpiozero to control the servos, but it caused jittering so I switched to pigpio.注意:注释代码来自我使用 gpiozero 控制舵机时的代码,但它引起了抖动,所以我切换到 pigpio。 The comments are there just in case I have to switch back for whatever reason.这些评论是为了以防万一我出于任何原因不得不切换回来。

To toggle between positions you need to know when the positions are reached.要在位置之间切换,您需要知道何时到达位置。

  • Do you have limit switches?你有限位开关吗?
  • Can you measure the increase in current when the motor reaches the limit?当电机达到极限时,你能测量电流的增加吗?
  • Can you send the motor to a position by setting an angle?您可以通过设置角度将电机发送到 position 吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM