ros callback for turtlebot

asked 2020-10-23 01:50:06 -0500

Krishna99 gravatar image

i just want the turtlebot to stop after one revolution or drawing a circle....i am doing this using twist msg and i also give the linear and angular velocity in the publisher and also have also subscribed to the topic published, i don't know what to do after this. I am new to ROS and still learning python. i really need this help (basically i want the bot to come back to its initial position after one revolution)

edit retag flag offensive close merge delete



Is this homework? This same question has been asked at least three times on Stackoverflow over the last month or so. The answer is always the same: you'll need to learn about closed-loop control. It's also best to share your code and ask specific questions about it rather than only describing the task you are given and asking for a solution.

chfritz gravatar image chfritz  ( 2020-10-23 11:31:44 -0500 )edit

!/usr/bin/env python

import rospy from geometry_msgs.msg import Twist from turtlesim.msg import Pose

def pose_callback(ms): print("msg.theta")

def revolve():

rospy.init_node('turtle_revolve', anonymous=True)
velocity_publisher = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
vel_loop_rate = rospy.Rate(10)

while not rospy.is_shutdown():

    rospy.Subscriber("/turtle1/pose", Pose, pose_callback)

    vel_msg = Twist()

    vel_msg.linear.x = 10
    vel_msg.linear.y= 0
    vel_msg.linear.z= 0 
    vel_msg.angular.x= 0
    vel_msg.angular.y= 0
    vel_msg.angular.z= 2


if __name__ == '__revolve__': try: revolve() except rospy.ROSInterruptException: pass

Krishna99 gravatar image Krishna99  ( 2020-10-23 13:05:39 -0500 )edit

this is the code i have been working on. i just want write a callback function for this script where the turtlebot stops to its initial position after drawing a circle. i also don't know that my code is working or not because whenever i execute the file it spawns a new command line and no output. It would be really helpful for me, i am a beginner in ROS and in python i feel a bit hard to troubleshoot the problem which i face

Thank You

Krishna99 gravatar image Krishna99  ( 2020-10-23 13:10:12 -0500 )edit