|
@@ -11,6 +11,8 @@
|
|
|
20210913:为增加两轮平衡车模式优化代码.
|
|
|
20220927:将电机编码器计数的参数获取改为一个参数motor_encoder_cnt,直接为
|
|
|
CHANGE模式四倍频的总计数1320个,不使用减速比和编码器分辨率参数.
|
|
|
+ 20220929:删除在init函数中,发送清除编码器计数值操作,因为上下位机建立通信时,
|
|
|
+ 会自动的将下位机程序初始化,编码器计数值自然为0.
|
|
|
"""
|
|
|
import os,rospy,roslib
|
|
|
import dynamic_reconfigure.client
|
|
@@ -19,7 +21,6 @@ from math import sin, cos, pi
|
|
|
from std_msgs.msg import Int32
|
|
|
from nav_msgs.msg import Odometry
|
|
|
from geometry_msgs.msg import Quaternion,Twist
|
|
|
-from tf.broadcaster import TransformBroadcaster
|
|
|
from ros_arduino_python.balance_mode import BalanceMode
|
|
|
|
|
|
|
|
@@ -67,9 +68,6 @@ class BaseController:
|
|
|
self.accel_limit = rospy.get_param('~motor_accel_limit', 0.1)
|
|
|
self.max_accel = self.accel_limit*self.ticks_per_meter
|
|
|
|
|
|
- now = rospy.Time.now()
|
|
|
- self.old_time = now
|
|
|
-
|
|
|
|
|
|
self.enc_A = 0
|
|
|
self.enc_B = 0
|
|
@@ -83,7 +81,9 @@ class BaseController:
|
|
|
|
|
|
self.v_des_AWheel = 0
|
|
|
self.v_des_BWheel = 0
|
|
|
-
|
|
|
+
|
|
|
+ now = rospy.Time.now()
|
|
|
+ self.old_time = now
|
|
|
self.last_cmd_time = now
|
|
|
|
|
|
|
|
@@ -93,15 +93,8 @@ class BaseController:
|
|
|
if self.isBalance:
|
|
|
self.balanceControl = BalanceMode()
|
|
|
|
|
|
-
|
|
|
- if self.use_serial:
|
|
|
- self.arduino.reset_encoders()
|
|
|
- else:
|
|
|
- self.arduino.i2c_reset_encoders()
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
self.odomPub = rospy.Publisher(self.odom_name, Odometry, queue_size=5)
|
|
|
- self.odomBroadcaster = TransformBroadcaster()
|
|
|
|
|
|
|
|
|
if self.debugPID:
|
|
@@ -117,7 +110,6 @@ class BaseController:
|
|
|
self.AWheel_Kd = pid_params['AWheel_Kd']
|
|
|
self.AWheel_Ki = pid_params['AWheel_Ki']
|
|
|
self.AWheel_Ko = pid_params['AWheel_Ko']
|
|
|
-
|
|
|
self.BWheel_Kp = pid_params['BWheel_Kp']
|
|
|
self.BWheel_Kd = pid_params['BWheel_Kd']
|
|
|
self.BWheel_Ki = pid_params['BWheel_Ki']
|
|
@@ -144,8 +136,8 @@ class BaseController:
|
|
|
|
|
|
return int(pwmA), int(pwmB)
|
|
|
|
|
|
-
|
|
|
- def poll(self):
|
|
|
+
|
|
|
+ def main_poll(self):
|
|
|
|
|
|
self.send_debug_pid()
|
|
|
|
|
@@ -171,17 +163,19 @@ class BaseController:
|
|
|
if aWheel_enc == 0 and bWheel_enc == 0:
|
|
|
self.enc_A = 0
|
|
|
self.enc_B = 0
|
|
|
+ encoder_diff_A = 0
|
|
|
+ encoder_diff_B = 0
|
|
|
if self.isBalance:
|
|
|
self.balanceControl.encoder_integral = 0
|
|
|
self.balanceControl.encoder_lowout = 0
|
|
|
+ else:
|
|
|
+
|
|
|
+ encoder_diff_A = aWheel_enc - self.enc_A
|
|
|
+ encoder_diff_B = bWheel_enc - self.enc_B
|
|
|
|
|
|
-
|
|
|
- encoder_diff_A = aWheel_enc - self.enc_A
|
|
|
- encoder_diff_B = bWheel_enc - self.enc_B
|
|
|
-
|
|
|
-
|
|
|
- self.enc_A = aWheel_enc
|
|
|
- self.enc_B = bWheel_enc
|
|
|
+
|
|
|
+ self.enc_A = aWheel_enc
|
|
|
+ self.enc_B = bWheel_enc
|
|
|
|
|
|
|
|
|
if self.isBalance:
|
|
@@ -317,7 +311,7 @@ class BaseController:
|
|
|
self.v_des_BWheel = int(vB * self.ticks_per_meter / self.PID_rate)
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
def send_debug_pid(self):
|
|
|
if self.debugPID:
|
|
|
try:
|