Robotics StackExchange | Archived questions

the angles are not accurate as when i accepted them from the input what is the problem

i changed the code at link text to accept speed ,angle and clockwise as an argument and i got the turtles angle deviated from the one i tried with the input function what the hell on the earth do i have to do in ordered to get it working? here is the code

!/usr/bin/env python

import rospy from geometry_msgs.msg import Twist PI = 3.1415926535897

def rotate(speed,angle,clockwise): #Starts a new node rospy.initnode('robotcleaner', anonymous=True) velocitypublisher = rospy.Publisher('/turtle1/cmdvel', Twist, queuesize=10) velmsg = Twist() #Converting from angles to radians angularspeed = speed2PI/360 relativeangle = angle2PI/360

#We wont use linear components
vel_msg.linear.x=0
vel_msg.linear.y=0
vel_msg.linear.z=0
vel_msg.angular.x = 0
vel_msg.angular.y = 0

# Checking if our movement is CW or CCW
if clockwise:
    vel_msg.angular.z = -abs(angular_speed)
else:
    vel_msg.angular.z = abs(angular_speed)
# Setting the current time for distance calculus
t0 = rospy.Time.now().to_sec()
current_angle = 0

while(current_angle < relative_angle):
    velocity_publisher.publish(vel_msg)
    t1 = rospy.Time.now().to_sec()
    current_angle = angular_speed*(t1-t0)


#Forcing our robot to stop
vel_msg.angular.z = 0
velocity_publisher.publish(vel_msg)
rospy.spin()

if name == 'main':
try:
# Testing our function
rotate(180,180,1)
except rospy.ROSInterruptException:
pass

Asked by noh on 2017-04-06 09:32:55 UTC

Comments

Answers