本文整理汇总了Python中pid.PID.set_target方法的典型用法代码示例。如果您正苦于以下问题:Python PID.set_target方法的具体用法?Python PID.set_target怎么用?Python PID.set_target使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pid.PID
的用法示例。
在下文中一共展示了PID.set_target方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MotionControl
# 需要导入模块: from pid import PID [as 别名]
# 或者: from pid.PID import set_target [as 别名]
class MotionControl(object):
def __init__(self):
rospy.on_shutdown(self.stop)
rospy.wait_for_service('uniboard_service')
self.uniboard_service = rospy.ServiceProxy('uniboard_service', communication)
rospy.Subscriber("/cmd_vel", Twist, self.set_vel)
rospy.Subscriber("/vel", vel_update, self.update)
self.vel_pid = PID(self.drive, 0.5, 0.01, 0.0,[-2, 2], [-1, 1], 'vel_pid')
self.vel_pid.start()
self.rot_pid = PID(self.rotation, 0.5, 0.01, 0.0, [-2.0, 2.0], [-0.5, 0.5], 'rot_pid')
self.rot_pid.start()
# The offset value between wheel power to drive rotation
self.rotation_offset = 0.0
def drive(self, power):
self.uniboard_service('motor_left', 3, str(power), rospy.Time.now())
self.uniboard_service('motor_right', 3, str(power+self.rotation_offset), rospy.Time.now())
def set_vel(self, twist):
self.vel_pid.set_target(twist.linear.x)
self.rot_pid.set_target(twist.angular.z)
def rotation(self, diff):
self.rotation_offset = diff
def stop(self):
self.vel_pid.stop()
self.rot_pid.stop()
def start(self):
self.vel_pid.start()
self.vel_pid.reset()
self.rot_pid.start()
self.rot_pid.reset()
def update(self, vel):
linear = vel.linear_x
angular = vel.angular_z
self.vel_pid.update(linear)
self.rot_pid.update(angular)