Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e091b667c | ||
|
|
172886efbd | ||
|
|
7185753455 | ||
|
|
e4797d435c | ||
|
|
2f6eee89c1 | ||
|
|
9e280919f1 | ||
|
|
74627e2456 | ||
|
|
ce862fd07b | ||
|
|
d181e9a14c | ||
|
|
67d7a51331 | ||
|
|
9cf2c5f479 | ||
|
|
401f154a5b | ||
|
|
f0f0d17523 | ||
|
|
618d7f28df | ||
|
|
7a7a0b7012 |
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
import roslib
|
||||
import sys
|
||||
import rospy
|
||||
import cv2
|
||||
import time
|
||||
import random
|
||||
import numpy as np
|
||||
from std_msgs.msg import String
|
||||
from sensor_msgs.msg import Image
|
||||
from cv_bridge import CvBridge, CvBridgeError
|
||||
from geometry_msgs.msg import Twist
|
||||
|
||||
import gripperHelper
|
||||
import bDepth
|
||||
|
||||
|
||||
class gripper_mover():
|
||||
def wait_for_subscribers(self):
|
||||
while self.pub.get_num_connections() == 0:
|
||||
print("Waiting for subscriber on {}".format(self.pub.name))
|
||||
rospy.sleep(1)
|
||||
if rospy.is_shutdown():
|
||||
raise Exception("Got shutdown request before subscribers connected")
|
||||
def wait_for_publisher(self,astra_camera_rgb_topic,astra_camera_depth_topic):
|
||||
while 1:
|
||||
x = rospy.get_published_topics()
|
||||
if any(astra_camera_depth_topic in subl for subl in x) and any(astra_camera_depth_topic in subl for subl in x):
|
||||
break
|
||||
print("Waiting for {} and {}".format(astra_camera_rgb_topic,astra_camera_depth_topic))
|
||||
rospy.sleep(1)
|
||||
|
||||
turtle_is_here = 0
|
||||
def wait_for_here_callback(self,data):
|
||||
rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
|
||||
if data.data == "IMHERE":
|
||||
self.turtle_is_here = 1
|
||||
def wait_for_here(self):
|
||||
sub = rospy.Subscriber("chatterabc", String, self.wait_for_here_callback)
|
||||
while self.turtle_is_here == 0:
|
||||
print("Turtle is not here")
|
||||
self.rate.sleep()
|
||||
sub.unregister()
|
||||
print("Turtle IS here")
|
||||
|
||||
def say_im_finish(self):
|
||||
for x in range(0, 50):
|
||||
hello_str = "GRIPFINISH"
|
||||
print("IM FINISHED")
|
||||
self.pub2.publish(hello_str)
|
||||
self.rate.sleep()
|
||||
|
||||
|
||||
|
||||
def __init__(self, astra_camera_rgb_topic : str, astra_camera_depth_topic : str , start_id : int = 1):
|
||||
|
||||
self.target_id = start_id #We target one tag at a time
|
||||
self.arucoDict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_ARUCO_ORIGINAL)
|
||||
self.arucoParams = cv2.aruco.DetectorParameters_create()
|
||||
|
||||
self.gHelper = gripperHelper.gripperArdunio()
|
||||
# self.gHelper.testMove(10)
|
||||
self.gHelper.grabK()
|
||||
self.bDepth = bDepth.betterDepth()
|
||||
|
||||
### For turtle controll
|
||||
# self.wait_for_subscribers()
|
||||
self.wait_for_publisher(astra_camera_rgb_topic,astra_camera_depth_topic)
|
||||
self.bridge = CvBridge()
|
||||
self.pub2 = rospy.Publisher('grippertalker', String, queue_size=10)
|
||||
rospy.init_node("turtle_control", anonymous=True)
|
||||
self.rate = rospy.Rate(30) # update rate can be increased
|
||||
|
||||
self.wait_for_here()
|
||||
|
||||
self.depth_point = (-1,-1) #This is the point from where we get the depth
|
||||
self.last_depth = -1 #This is the last depth from the depth_point
|
||||
self.last_depth2 = -1
|
||||
self.depth_counter = 0 #Make sure we are really there by counting how many time we got this result
|
||||
self.rState = 0
|
||||
self.lastMove = 0
|
||||
self.image_sub = rospy.Subscriber(
|
||||
astra_camera_rgb_topic, Image, self.callback_rgb
|
||||
)
|
||||
|
||||
self.depth_bridge = CvBridge()
|
||||
self.lastTime = time.time()
|
||||
self.depth_image_sub = rospy.Subscriber(astra_camera_depth_topic,Image,self.callback_depth)
|
||||
|
||||
### Markers haven been detected, now do something
|
||||
def markDetected(self, img, corners):
|
||||
for markerCorner in corners:
|
||||
(top_left, top_right, bottom_right, bottom_left) = markerCorner.reshape((4,2))
|
||||
top_left = (int(top_left[0]), int(top_left[1]))
|
||||
top_right = (int(top_right[0]), int(top_right[1]))
|
||||
bottom_right = (int(bottom_right[0]), int(bottom_right[1]))
|
||||
bottom_left = (int(bottom_left[0]), int(bottom_left[1]))
|
||||
cv2.line(img, top_left, bottom_right, (0,255,0), 2)
|
||||
cv2.line(img, top_right, bottom_left, (0,255,0), 2)
|
||||
self.depth_point = (int((top_left[0] + bottom_right[0]) / 2), int((top_left[1] + bottom_right[1]) / 2))
|
||||
|
||||
cv2.circle(img, self.depth_point, 8, (0,0,255), -1)
|
||||
|
||||
def callback_rgb(self, data):
|
||||
try:
|
||||
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
|
||||
(self.h, self.w) = cv_image.shape[:2]
|
||||
except CvBridgeError as e:
|
||||
print(e)
|
||||
|
||||
#(rows, cols, channels) = cv_image.shape
|
||||
(corners, ids, rejected) = cv2.aruco.detectMarkers(
|
||||
cv_image, self.arucoDict, parameters=self.arucoParams
|
||||
)
|
||||
|
||||
if corners: #marker corners
|
||||
#Now seleted the corners of the tag with the right id => the tag that indicates the distance to the gripper
|
||||
i = np.where(ids == self.target_id) # wahrscheinlich 1 und 0
|
||||
if len(i[0]) > 0:
|
||||
fitting_corners = corners[i[0][0]]
|
||||
self.markDetected(cv_image, fitting_corners)
|
||||
tM = np.where(ids == 0) #Now try to get the marker that indicates the turtlebot
|
||||
else:
|
||||
self.depth_point = (-1,-1)
|
||||
|
||||
|
||||
|
||||
|
||||
cv2.rectangle(cv_image,(0,0),(700,120),(10, 10, 10),-1)
|
||||
#Give some additional informations
|
||||
idString = "IDs:" + str(ids) + " TargetID:" + str(self.target_id)
|
||||
cv2.putText(cv_image, idString, (10,30), cv2.FONT_HERSHEY_TRIPLEX, 1, (200, 200, 200), 2, cv2.LINE_8)
|
||||
depthString = "DepthPoint:" + str(self.depth_point[0]) +"x" +str(self.depth_point[1]) + "Distance:" + str(self.last_depth)
|
||||
cv2.putText(cv_image, depthString, (10,60), cv2.FONT_HERSHEY_TRIPLEX , 0.8, (200, 200, 200), 2, cv2.LINE_8)
|
||||
|
||||
depthString2 = "LastMove:" + str(self.lastMove)
|
||||
cv2.putText(cv_image, depthString2, (10,90), cv2.FONT_HERSHEY_TRIPLEX , 0.8, (200, 200, 200), 2, cv2.LINE_8)
|
||||
|
||||
self.rate.sleep()
|
||||
cv2.imshow("Window", cv_image)
|
||||
cv2.waitKey(1)
|
||||
|
||||
def callback_depth(self, data):
|
||||
#It would be possible to convert this to 32FC1
|
||||
#32FC1 means that each pixel value is stored as one channel floating point with single precision
|
||||
#In 32FC1 each pixel is 4 bytes. Apart from that its a numpy array)
|
||||
cv_depth_image = self.depth_bridge.imgmsg_to_cv2(data, "passthrough")
|
||||
if self.depth_point != (-1,-1):
|
||||
self.currentTime = time.time()
|
||||
# Here x and y are swapped. I dont know why.
|
||||
#notNull = cv_depth_image[self.depth_point[1]][self.depth_point[0]]
|
||||
last_depth_2 = self.bDepth.wDepthImage(cv_depth_image,self.depth_point[1],self.depth_point[0])
|
||||
if last_depth_2 == 0 or last_depth_2 > 2000:
|
||||
return
|
||||
self.last_depth = last_depth_2
|
||||
if (self.currentTime - self.lastTime) > 4:
|
||||
rr = self.last_depth*-0.2478+253.15
|
||||
st=0
|
||||
#self.gHelper.testRotate(int(rr))
|
||||
self.lastTime = time.time()
|
||||
if self.last_depth < 1000:
|
||||
self.lastMove = self.last_depth
|
||||
rr = self.last_depth*-0.2478+253.15
|
||||
st = 0
|
||||
while rr > st :
|
||||
self.gHelper.testRotate(int(st))
|
||||
st = st + 20
|
||||
print("st:" + str(st))
|
||||
print("rr:" + str(rr))
|
||||
print("==here")
|
||||
self.gHelper.testPlace(int(rr))
|
||||
self.depth_point = (-1,-1)
|
||||
self.say_im_finish()
|
||||
rospy.signal_shutdown(1)
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("Please give the following arguments <camera-img-topic> and <camera-depth-topic>")
|
||||
print("Like: marker_attack.py /camera/rgb/image_raw /camera/depth/image_raw")
|
||||
return 1
|
||||
print("OK")
|
||||
ic = gripper_mover(str(sys.argv[1]),str(sys.argv[2]))
|
||||
try:
|
||||
rospy.spin()
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down")
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Before Width: | Height: | Size: 177 KiB |
|
Before Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 182 KiB |
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 251 KiB |
|
Before Width: | Height: | Size: 251 KiB |
|
Before Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 167 KiB |
|
Before Width: | Height: | Size: 235 KiB |
|
Before Width: | Height: | Size: 170 KiB |
|
Before Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.1 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.1 MiB |
|
Before Width: | Height: | Size: 2.1 MiB |
|
Before Width: | Height: | Size: 2.1 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 211 KiB |
|
Before Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 211 KiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 938 KiB |
|
Before Width: | Height: | Size: 1021 KiB |
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 1.9 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.3 MiB |
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 2.3 MiB |
|
Before Width: | Height: | Size: 3.7 MiB |
|
Before Width: | Height: | Size: 3.5 MiB |
|
Before Width: | Height: | Size: 3.3 MiB |
|
Before Width: | Height: | Size: 3.4 MiB |
|
Before Width: | Height: | Size: 4.1 MiB |
|
Before Width: | Height: | Size: 2.1 MiB |
|
Before Width: | Height: | Size: 3.3 MiB |
|
Before Width: | Height: | Size: 2.5 MiB |
|
Before Width: | Height: | Size: 3.0 MiB |
|
Before Width: | Height: | Size: 2.9 MiB |
|
Before Width: | Height: | Size: 2.9 MiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 282 KiB |
|
Before Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 130 KiB |