loveson vashikaran
loveson vashikaran

Reputation: 1

How to turn Turtlebot3 90 degrees using IMU feedback in Python?

I want to turn turtlebot3 90 degree left turn using the feedback from the IMU sensor , is it possible

I've done 90 degree turn using Twist message itself , but I want to confirm that our turtlebot3 turned 90 degree using IMU data

#!/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()

above is the reference that i got using odometry is fine ,but I need to check it with IMU feedback to check whether robot is turned accurate 90 degree or not

It's just a reference code using odometry

Upvotes: 0

Views: 420

Answers (0)

Related Questions