qobjects timmers cannot be stopped from another thread

asked 2018-11-27 20:06:35 -0500

dumb gravatar image

updated 2018-11-28 01:34:39 -0500

gvdhoorn gravatar image

HI guys , im coding a multi-robot , in ros kinetic with python and gazebo,

MY mission is make one robot find a yellow cube in scenario. then get that location and send to second robot

im trying to code my group of robot, im using ros,gazebo and qt crator, and im not expert, im a little bit stupid.

idk whats happening , i tryied few things, but im really don't know what to do.

it starts working, but when he faces the first wall, it crashes with follow message "QOBJECTS TIMMERS CANNOT BE STOPPED FROM ANOTHER THREAD"

here is my code

#!/usr/bin/env python

import rospy, time , cv2, cv_bridge, numpy
from nav_msgs.msg import Odometry
from tf.transformations import euler_from_quaternion
from geometry_msgs.msg import Point, Twist
from sensor_msgs.msg import LaserScan,  Image, CameraInfo
from math import atan2

class Follower:
  def __init__(self):
    self.bridge = cv_bridge.CvBridge()
    #cv2.namedWindow("window", 1)
    self.image_sub = rospy.Subscriber('/tb3_0/camera/rgb/image_raw',Image, self.image_callback)
    #self.cmd_vel_pub = rospy.Publisher('/cmd_vel',Twist, queue_size=1)
    #self.twist = Twist()

  def image_callback(self, msg):
    image = self.bridge.imgmsg_to_cv2(msg,desired_encoding='bgr8')
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    lower_yellow = numpy.array([ 10,  10,  10])
    upper_yellow = numpy.array([255, 255, 250])
    mask = cv2.inRange(hsv, lower_yellow, upper_yellow)

    h, w, d = image.shape
    search_top = 3*h/4
    search_bot = 3*h/4 + 20
    mask[0:search_top, 0:w] = 0
    mask[search_bot:h, 0:w] = 0
    M = cv2.moments(mask)
    if M['m00'] > 0:
      cx = int(M['m10']/M['m00'])
      cy = int(M['m01']/M['m00'])
      #cv2.circle(image, (cx, cy), 20, (0,0,255), -1)
      print "achei amarelo"
      #color = 1
      goal.x = x
      goal.y = y
   # cv2.imshow("mask",mask)
    cv2.imshow("output", image)

#Odometria para identificar posicao
x = 0.0
y = 0.0
theta = 0.0

def newOdom(msg):
    global x
    global y
    global theta

    x = msg.pose.pose.position.x
    y = msg.pose.pose.position.y

    rot_q = msg.pose.pose.orientation
    (roll, pitch, theta) = euler_from_quaternion([rot_q.x, rot_q.y, rot_q.z, rot_q.w])


odom_sub_tb3_0 = rospy.Subscriber("/tb3_0/odom", Odometry, newOdom)
#pub = rospy.Publisher("/tb3_0/cmd_vel", Twist, queue_size = 1)

r = rospy.Rate(4)

goal = Point()
goal.x = 0
goal.y = 0

def scan_callback(msg):
    global range_front
    global range_right
    global range_left
    global ranges
    global min_front,i_front, min_right,i_right, min_left ,i_left

    ranges = msg.ranges
    # get the range of a few points
    # in front of the robot (between 5 to -5 degrees)
    range_front[:5] = msg.ranges[5:0:-1]
    range_front[5:] = msg.ranges[-1:-5:-1]
    # to the right (between 300 to 345 degrees)
    range_right = msg.ranges[300:345]
    # to the left (between 15 to 60 degrees)
    range_left = msg.ranges[60:15:-1]
    # get the minimum values of each range
    # minimum value means the shortest obstacle from the robot
    min_range,i_range = min( (ranges[i_range],i_range) for i_range in xrange(len(ranges)) )
    min_front,i_front = min( (range_front[i_front],i_front) for i_front in xrange(len(range_front)) )
    min_right,i_right = min( (range_right[i_right],i_right) for i_right in xrange ...
edit retag flag offensive close merge delete


it starts working, but when he faces the first wall, it crashes with follow message [..]

please always include the complete error message when posting questions here. Do not paraphrase or quote.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-28 01:35:24 -0500 )edit