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

        rospy.init_node('obstacle_avoidance')
        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)

        rospy.spin()

    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:
            self.halt()

        # # 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;
        self.cmd_vel_pub.publish(twist)

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

asked 19 Dec '18, 04:55

adeoduye's gravatar image

adeoduye
01
accept rate: 0%

closed 08 Mar, 23:07

marcoarruda's gravatar image

marcoarruda ♦♦
1764

The question has been closed for the following reason "Inactivity" by marcoarruda 08 Mar, 23:07


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.

Regards

permanent link

answered 08 Jan, 11:44

marcoarruda's gravatar image

marcoarruda ♦♦
1764
accept rate: 18%

Follow this question

By Email:

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

By RSS:

Answers

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:

×28
×3
×2
×2

question asked: 19 Dec '18, 04:55

question was seen: 230 times

last updated: 08 Mar, 23:07

powered by OSQA