代码之家  ›  专栏  ›  技术社区  ›  loveson vashikaran

如何使用Python中的IMU反馈将Turtlebot3旋转90度?

  •  0
  • loveson vashikaran  · 技术社区  · 3 年前

    我想利用IMU传感器的反馈将turtlebot3左转90度,有可能吗

    我已经使用Twist消息本身完成了90度转弯,但我想确认我们的turtlebot3使用IMU数据完成了90°转弯

    #!/usr/bin/env python
    import rospy
    from nav_msgs.msg import Odometry
    from tf.transformations import euler_from_quaternion, quaternion_from_euler
    from geometry_msgs.msg import Twist
    import math
    
    roll = pitch = yaw = 0.0
    target = 90
    kp=0.5
    
    def get_rotation (msg):
        global roll, pitch, yaw
        orientation_q = msg.pose.pose.orientation
        orientation_list = [orientation_q.x, orientation_q.y, orientation_q.z, orientation_q.w]
        (roll, pitch, yaw) = euler_from_quaternion (orientation_list)
        print yaw
    
    rospy.init_node('rotate_robot')
    
    sub = rospy.Subscriber ('/odom', Odometry, get_rotation)
    pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
    r = rospy.Rate(10)
    command =Twist()
    
    while not rospy.is_shutdown():
        #quat = quaternion_from_euler (roll, pitch,yaw)
        #print quat
        target_rad = target*math.pi/180
        command.angular.z = kp * (target_rad-yaw)
        pub.publish(command)
        print("taeget={} current:{}", target,yaw)
        r.sleep()
    

    以上是我使用里程计得到的参考,很好,但我需要用IMU反馈来检查机器人是否准确旋转了90度

    这只是一个使用里程计的参考代码

    0 回复  |  直到 3 年前