1 Star 0 Fork 1

WangWeitong/dachuang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
follow_r0_with_acceleration.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
WangWeitong 提交于 2021-08-26 14:31 . follow with acceleration
#!/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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wwt_panache/dachuang.git
git@gitee.com:wwt_panache/dachuang.git
wwt_panache
dachuang
dachuang
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385