Ask Your Question
0

Delay problem with /cmd_vel Turtlebot3

asked 2018-04-20 10:01:07 -0600

DanielRobotics gravatar image

updated 2018-04-20 10:52:09 -0600

I am running ROS Kinetic, on a Turtlebot3 Burger with a Raspberry Pi3.

The goal here is to remotely control the Turtlebot from another Raspberry Pi. The remote controller Pi sends movement information over a socket connection.

I have delay problems when publishing into /cmd_vel (60 seconds delay) and again delay of 60 seconds from when the Twist message is echoed in the topic /cmd_vel to when the Turtlebot starts moving. I cannot locate why this 2 x 60 seconds delay occurs. I think that I might be pushing the raspberry pi too much.

If I do the following steps: The Turtlebot3 is the ROS MASTER. 1. From remote SSH into the Raspberry Pi --> roslaunch turtlebot3_bringup turtlebot3_robot.launch 2. From remote SSH into the Raspberry Pi -- >roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

Everything works fine no delays.

When I do: The Turtlebot3 is the ROS MASTER. 1. From remote SSH into the Raspberry Pi --> roslaunch turtlebot3_bringup turtlebot3_robot.launch 2. From remote SSH into the Raspberry Pi -- >python post_office.py //python script posted below. 3. From remote SSH into the Raspberry Pi -- >rostopic echo /cmd_vel

The messages get into /cmd_vel with a 60 seconds delay. The Turtlebot3 starts moving after 120 seconds delay.

When I do: The REMOTE PC is the ROS MASTER. 1. roscore on remote pc 2. From remote SSH into the Raspberry Pi --> roslaunch turtlebot3_bringup turtlebot3_robot.launch 3. From remote SSH into the Raspberry Pi -- >python post_office.py //python script posted below. 4. Remote pc -- >rostopic echo /cmd_vel

The messages get into /cmd_vel with a 0 seconds delay. The Turtlebot3 starts moving after 35 seconds delay.

env | grep ROS gives the following when Turtlebot3 is ROS MASTER: ROS_ETC_DIR=/opt/ros/kinetic/etc/ros ROS_ROOT=/opt/ros/kinetic/share/ros ROS_MASTER_URI=http://192.168.1.39:11311 ROS_PACKAGE_PATH=/home/pi/catkin_ws/src:/opt/ros/kinetic/share ROSLISP_PACKAGE_DIRECTORIES=/home/pi/catkin_ws/devel/share/common-lisp ROS_HOSTNAME=192.168.1.39 ROS_DISTRO=kinetic

Here is the post_office.py running on the Turtlebot3.

import socket
import json
import rospy
from geometry_msgs.msg import Twist
import thread
import time

HOST = ''
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print ('Connected by', addr)

twist = Twist()
lin = 0.0
ang = 0.0
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=5) #queqe size can be adjusted maybe

def publish_cmd_vel():
    while not rospy.is_shutdown(): #checking the rospy.is_shutdown() flag and then doing work. You have to check is_shutdown() to check if your program should exit (e.g. if there is a Ctrl-C or otherwise).
        twist.linear.x = lin; twist.linear.y = 0; twist.linear.z = 0 #liniar has to be .x value to change
        twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = ang #angular has to be .z value to change
        try:
            pub.publish(twist)
        except:
            print('unable to publish')

def recv_from_controller():
    while True:
        global lin, ang
        move_bytes = conn.recv(1024) #receive information as bytes
        #print("Type received", type(move_bytes))
        #move_info_string = move_bytes.decode()
        #print("After decoding ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2018-04-20 10:06:09 -0600

gvdhoorn gravatar image

Perhaps add a rospy.sleep(..) in your main while loop? At the moment it's probably publishing Twist msgs at about 10KHz (or some other high frequency).

edit flag offensive delete link more

Comments

I tried adding rospy.sleep(1) into the main while True. so sleeping for 1 seconds, but it has no effect on the delays.

DanielRobotics gravatar imageDanielRobotics ( 2018-04-20 10:53:45 -0600 )edit
1

Which loop specifically did you add the sleep to? The one with pub.publish(twist) in it?

gvdhoorn gravatar imagegvdhoorn ( 2018-04-20 13:18:51 -0600 )edit

I placed it in the last one after publish_cmd_vel) I will try to place it in the one with pub.publish(twist) in it.

DanielRobotics gravatar imageDanielRobotics ( 2018-04-20 13:28:41 -0600 )edit

adding a rospy.sleep(0.1) to the one with pub.publish(twist) in it fixed the delay issue. Thanks!

DanielRobotics gravatar imageDanielRobotics ( 2018-04-21 10:00:45 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-04-20 10:01:07 -0600

Seen: 413 times

Last updated: Apr 20 '18