please refer to: https://raspberrypi.stackexchange.com/questions/14105/how-does-python-gpio-bouncetime-parameter-work #!/usr/bin/env python import RPi.GPIO as GPIO import motor from socket import * from time import ctime import rospy from std_msgs.msg import String import time from std_msgs.msg import String import RPi.GPIO as GPIO # Set the GPIO modes #GPIO.setmode(GPIO.BCM) #GPIO.setwarnings(False) busnum = 1 #hall efffect on motor #find and use the pin on raspi board C1=19 C2=21 ... def C1_callback(channel): global c1_count,cnt,cmd c1_count=c1_count+1 print("C1=",c1_count) print("Cnt=", cnt) def C2_callback2(channel): global c2_count c2_count=c2_count+1 print("C2=",c2_count) #set up the interrupt for pin 19 21 def setup_interupt(): GPIO.setup(C1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(C2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(C1, GPIO.FALLING, callback=C1_callback, bouncetime=1) GPIO.add_event_detect(C2, GPIO.FALLING, callback=C2_callback2, bouncetime=1) rospy.init_node('driver') setup() rospy.Subscriber('command', String, CommandCallback) rospy.spin() print('Shutting down: stopping motors') GPIO.cleanup()
ROS之三sunfounder智能小车驱动马达(holl effect feedback)
最新推荐文章于 2024-07-12 13:26:07 发布