|
@@ -1,7 +1,13 @@
|
|
|
#!/usr/bin/env python
|
|
|
+#-*- coding:utf-8 -*-
|
|
|
|
|
|
"""
|
|
|
- A base controller class for the Arduino microcontroller
|
|
|
+ Copyright: 2016-2020 www.corvin.cn ROS小课堂
|
|
|
+ Description: A base controller class for the Arduino DUE microcontroller
|
|
|
+ Author: corvin
|
|
|
+ History:
|
|
|
+ 20200704:当超过给下位机发送控制移动命令时间后,不需要再发送pwm控制0的命令.
|
|
|
+ 因为在arduino代码会根据超时自己会执行pwm清零停止电机移动的命令.
|
|
|
"""
|
|
|
import os
|
|
|
import rospy
|
|
@@ -14,6 +20,7 @@ from nav_msgs.msg import Odometry
|
|
|
from tf.broadcaster import TransformBroadcaster
|
|
|
from std_msgs.msg import Int32
|
|
|
|
|
|
+
|
|
|
""" Class to receive Twist commands and publish wheel Odometry data """
|
|
|
class BaseController:
|
|
|
|
|
@@ -165,7 +172,14 @@ class BaseController:
|
|
|
rospy.logerr("Encoder exception count: " + str(self.bad_encoder_count))
|
|
|
return
|
|
|
|
|
|
- # Calculate odometry
|
|
|
+ #当读取到最新的编码器计数为0,说明下位机已经将计数清零,那上位机保存的上一次编码器计数也得清零
|
|
|
+ if aWheel_enc == 0:
|
|
|
+ self.enc_A = 0
|
|
|
+
|
|
|
+ if bWheel_enc == 0:
|
|
|
+ self.enc_B = 0
|
|
|
+
|
|
|
+ #根据编码器两次反馈的差值来计算车轮移动的距离
|
|
|
dist_A = (aWheel_enc - self.enc_A)/self.ticks_per_meter
|
|
|
dist_B = (bWheel_enc - self.enc_B)/self.ticks_per_meter
|
|
|
|