I am trying to temporarily interrupt the turtlebot3_teleop node from a custom node I am creating.

The scenario is when the lidar on my Turtlebot3 is a certain distance from an obstacle, I want to stop the bot, re-orient it in some direction which is obstacle free, my node will finish and then allow teleop to continue controlling the robot.

However, the process of stopping the bot is not responding as desired. My code is being executed but at the same time teleop is trying to do it's work. So the robot is stoping and starting in quick succession.

I need help, please. How do I get teleop to stop issuing twist temporarily so my node and take over, execute and then relinguish control back to teleop?

My code is as follows:

#! /usr/bin/env python

import rospy
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist, Vector3

class checker:

    def __init__(self):
        print('INIT Responding')

        self.cmd_vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
        self.cmd_vel_sub = rospy.Subscriber('/cmd_vel', Twist, self.twisty)
        self.laser_s_sub = rospy.Subscriber('/scan', LaserScan, self.callback)


    def twisty(self, sub):
        self.cmd_vel_sub = sub

    #defines a callback
    def callback(self, msg):
        # # REAR
        print('REAR    [0]: ' + str(msg.ranges[0]))

        # # RIGHT
        print('RIGHT  [90]: ' + str(msg.ranges[90]))

        # FRONT
        print('FRONT [180]: ' + str(msg.ranges[180]))
        if msg.ranges[180] == 0:

        # # LEFT
        print('LEFT  [270]: ' + str(msg.ranges[270]))

    def halt(self):
        rospy.loginfo("\n*************STOPPING FRONT MOTION**************")
        twist = Twist()
        twist.linear.x = 0.0;
        twist.angular.z = 0.0;

if __name__ == '__main__':
        c = checker()
    except rospy.ROSInterruptException:

asked 19 Dec '18, 04:55

adeoduye's gravatar image

accept rate: 0%

Hello @adeoduye,

I think a better solution for your problem is to have teleop running all the time, but you don't subscribe to it directly from the robot.

You can have a third node, let's call it manager, which is going to receive the commands from teleop and from your controller and decide, depending on the laser reading, which one to use and redirect to the robot.

Let me know if you need more details about that solution.


permanent link

answered 08 Jan, 11:44

marcoarruda's gravatar image

marcoarruda ♦♦
accept rate: 19%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 19 Dec '18, 04:55

question was seen: 62 times

last updated: 08 Jan, 11:44

powered by OSQA