Why is my turtlebot not moving continuously

asked 2019-11-26 10:44:12 -0500

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

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)
            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):

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

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?

edit retag flag offensive close merge delete


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

Choco93 gravatar image Choco93  ( 2019-11-27 08:27:34 -0500 )edit