cmd_vel_to_joint.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:popcanbot 作者: lucasw 项目源码 文件源码
def __init__(self):
        self.rate = rospy.get_param("~rate", 20.0)
        self.period = 1.0 / self.rate

        # angular mode maps angular z directly to steering angle
        # (adjusted appropriately)
        # non-angular mode is somewhat suspect, but it turns
        # a linear y into a command to turn just so that the
        # achieved linear x and y match the desired, though
        # the vehicle has to turn to do so.
        # Non-angular mode is not yet supported.
        self.angular_mode = rospy.get_param("~angular_mode", True)

        # Not used yet
        # self.tf_buffer = tf2_ros.Buffer()
        # self.tf = tf2_ros.TransformListener(self.tf_buffer)
        # broadcast odometry
        self.br = tf2_ros.TransformBroadcaster()
        self.ts = TransformStamped()
        self.ts.header.frame_id = "map"
        self.ts.child_frame_id = "base_link"
        self.ts.transform.rotation.w = 1.0
        self.angle = 0

        # The cmd_vel is assumed to be in the base_link frame centered
        # on the middle of the two driven wheels
        # This is half the distance between the two drive wheels
        self.base_radius = rospy.get_param("~base_radius", 0.06)
        self.wheel_radius = rospy.get_param("~wheel_radius", 0.04)

        self.left_wheel_joint = rospy.get_param("~left_wheel_joint", "wheel_front_left_joint")
        self.right_wheel_joint = rospy.get_param("~right_wheel_joint", "wheel_front_right_joint")

        self.point_pub = rospy.Publisher("cmd_vel_spin_center", PointStamped, queue_size=1)
        self.joint_pub = {}
        self.joint_pub['left'] = rospy.Publisher("front_left/joint_state",
                                                 JointState, queue_size=1)
        self.joint_pub['right'] = rospy.Publisher("front_right/joint_state",
                                                  JointState, queue_size=1)
        # TODO(lucasw) is there a way to get TwistStamped out of standard
        # move_base publishers?
        # TODO(lucasw) make this more generic, read in a list of any number of wheels
        # the requirement is that that all have to be aligned, and also need
        # a set spin center.
        self.ind = {}
        self.joint_state = {}
        self.joint_state['left'] = JointState()
        self.joint_state['left'].name.append(self.left_wheel_joint)
        self.joint_state['left'].position.append(0.0)
        self.joint_state['left'].velocity.append(0.0)
        self.joint_state['right'] = JointState()
        self.joint_state['right'].name.append(self.right_wheel_joint)
        self.joint_state['right'].position.append(0.0)
        self.joint_state['right'].velocity.append(0.0)

        self.cmd_vel = Twist()
        rospy.Subscriber("cmd_vel", Twist, self.cmd_vel_callback, queue_size=2)
        self.timer = rospy.Timer(rospy.Duration(self.period), self.update)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号