ROS之三sunfounder智能小车驱动马达(holl effect feedback)

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值