代码拉取完成,页面将自动刷新
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
class SubThenPub:
def __init__(self, init_distence, vel_lambda):
self.init_distence = init_distence
self.vel_lambda = vel_lambda
self.distence_diff = init_distence
self.my_vel = 0
self.last_vel = 0
self.__pub_ = rospy.Publisher('/robot_1/cmd_vel', Twist, queue_size=10)
self.__sub_ = rospy.Subscriber('/robot_0/odom', Odometry, self.callback)
def callback(self, data):
self.distence_diff = (data.twist.twist.linear.x - self.last_vel) / 50 + self.distence_diff
acceleration = self.vel_lambda * (data.twist.twist.linear.x - self.last_vel) / self.distence_diff
self.my_vel += acceleration / 50
vel_msg = Twist()
vel_msg.linear.x = self.my_vel
self.__pub_.publish(vel_msg)
self.last_vel = self.my_vel
rospy.loginfo("pub velocity:[%0.2f m/s]",vel_msg.linear.x)
def main():
init_distence = float(input('please input init distence between two cars (m):'))
vel_lambda = float(input('please input vel lambda of the model:'))
rospy.init_node('follow_r0', anonymous=True)
SAPObject = SubThenPub(init_distence, vel_lambda)
rospy.spin()
if __name__ == "__main__":
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。