subscriber infinite loop in python
Hi
I am starting with ROS and i have done this code who can read a image provided by topic to do something more when this run properly.
The problem is that never run "print("salida del bucle"). it enters at def (obtener)..... and never exit from this function
why can be the reason?
#!/usr/bin/env python
#%s string, %f float, %d integer
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import numpy as np
import cv2
import datetime
#.....................lectura topic odometria.....................
def obtener(datos):
#rospy.loginfo(rospy.get_caller_id() + " datos actualizados")
#rospy.loginfo(rospy.get_caller_id() + " anchura de pixeles %i", datos.width)
#rospy.loginfo(rospy.get_caller_id() + " datos leidos de camara %i", datos.data[100])
#convertimos la imagen a codigo python
global cv_image
cv_image = bridge.imgmsg_to_cv2(datos)
cv_image_p = cv2.normalize(cv_image, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U)
cv2.imshow('image_desde_ROS', cv_image_p)
cv2.waitKey(30)
#rospy.sleep(0.1)
#rospy.Rate(1)
#creamos un subscriptor para obtener la odometria
def leer_odometria():
rospy.Subscriber("/d435i_camera/depth/image_rect_raw", Image, obtener)
rospy.spin()
#----------------------------publicacion topic velocidad----------------------
if __name__ == '__main__':
# Inicializamos el nodo de ROS
rospy.init_node("test_drive")
# Creamos un publicista para que publique comandos de velocidad
cmd_pub = rospy.Publisher("cmd_vel", Twist, queue_size=1)
bridge = CvBridge()
col = [0, 0, 0, 0, 0]
col_nueva = [0, 0, 0, 0, 0]
try:
while not rospy.is_shutdown():
leer_odometria()
print("salida del bucle")
except rospy.ROSInterruptException:
pass