Robotics StackExchange | Archived questions

Why is my turtlebot not moving continuously

if __name__ == '__main__':
    rospy.init_node('gray')
    settings = termios.tcgetattr(sys.stdin)
    pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
    x = 0
    th = 0
    node = Gray()
    node.main()

We make the publisher(cmd_vel) in main, and run the main function of class gray.

 def __init__(self):
        self.r = rospy.Rate(10)
        self.selecting_sub_image = "compressed"  # you can choose image type "compressed", "raw"
        if self.selecting_sub_image == "compressed":
            self._sub = rospy.Subscriber('/raspicam_node/image/compressed', CompressedImage, self.callback, queue_size=1)
        else:
            self._sub = rospy.Subscriber('/usb_cam/image_raw', Image, self.callback, queue_size=1)
        self.bridge = CvBridge()

init function makes a subscriber, which runs 'callback' when it gets data.

def main(self):
    rospy.spin()

Then it runs the spin() function.

v, ang = vel_select(lvalue, rvalue, left_angle_num, right_angle_num, left_down, red_dots)
self.sendv(v, ang)

Inside the callback function, it gets a linear speed and angular speed value, and runs a sendv function to send it to the subscribers.

 def sendv(self, lin_v, ang_v):
    twist = Twist()
    speed = rospy.get_param("~speed", 0.5)
    turn = rospy.get_param("~turn", 1.0)
    twist.linear.x = lin_v * speed
    twist.angular.z = ang_v * turn
    twist.linear.y, twist.linear.z, twist.angular.x, twist.angular.y = 0, 0, 0, 0
    pub.publish(twist)

and... sendv function sends it to the turtlebot. It has to move continuously, because if we do not publish data, it still has to move with the speed it got from the last publish. Also, callback function runs every 0.1 seconds, so it keeps sending data.

But it does not move continously. It stops for a few seconds, and go for a very short time, and stops again, and go for a very short time, and so on. The code which selects the speed works correctly, but the code who sents it to the turtlebot does not work well. Can anyone help?

Asked by silver_plate on 2019-11-26 11:44:12 UTC

Comments

Not sure if that is the reason but why are you getting params with every sendv call?

Asked by Choco93 on 2019-11-27 09:27:34 UTC

Answers