Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2203

how to make the relationship between velocity and time be linear by python

$
0
0
I created code which making turtlebot 2 following me depend on detecting my face and chose a value of velocity 0.2 m/s my issue is the movement of the robot when disappearing my face suddenly which making turtlebot stops suddenly, I need to make decreasing its velocity gradually like this figure [link text](https://www.google.com.eg/search?q=linear+velocity+with+time&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi754nI8_HgAhXCxbwKHRJ3D_gQ_AUIDigB&biw=1855&bih=952#imgrc=fbTRSzhfqRk8uM:) my experience not good in ROS I need to change the line `self.twist.linear.x = 0.05` by the linear relationship between velocity and time as shown in the figure in the link, I mean that turtlebot will stop after a certain time, for example, 20 second my full code: #!/usr/bin/env python import rospy from sensor_msgs.msg import Image from geometry_msgs.msg import Twist import cv2, cv_bridge face_cascade = cv2.CascadeClassifier('/home/redhwan/1/run-webcam/Face-Detect-Demo-by-Ali-master/haarcascade_frontalface_default.xml' ) class Face_detection: def __init__(self): self.bridge = cv_bridge.CvBridge() self.image_sub = rospy.Subscriber('/usb_cam/image_raw',Image, self.image_callback) self.cmd_vel_pub = rospy.Publisher('/cmd_vel_mux/input/teleop',Twist, queue_size=1) self.twist = Twist() def image_callback(self, msg): image = self.bridge.imgmsg_to_cv2(msg,desired_encoding='bgr8') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale( gray,scaleFactor=1.1,minNeighbors=5,minSize=(30, 30),flags=cv2.cv2.CASCADE_SCALE_IMAGE) faces = face_cascade.detectMultiScale(gray, 1.3, 5) if(type(faces) != tuple): for (x, y, w, h) in faces: cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) self.twist.linear.x = 0.2 self.cmd_vel_pub.publish(self.twist) cv2.imshow('face ', image) cv2.waitKey(3) if(type(faces) == tuple): self.twist.linear.x = 0.05 self.cmd_vel_pub.publish(self.twist) rospy.init_node('face_detection') follower = Face_detection() rospy.spin() please help me or any suggestion Thank you in advance

Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>