Skip to content
This repository was archived by the owner on Feb 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/drivers/PiBot/JdeRobotKids.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
JdeRobotKids:
Robot: gazebo #pibot, mbot or gazebo
Robot: pibot #pibot, mbot or gazebo

Real:
Port: /dev/ttyUSB0
Expand Down Expand Up @@ -30,4 +30,4 @@ JdeRobotKids:
Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
Proxy: "irRight:default -h localhost -p 8992"
Format: RGB8


65 changes: 63 additions & 2 deletions src/drivers/PiBot/gazebo/piBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
import comm
import config
import cv2
import imutils

GREEN_MIN = numpy.array([20, 50, 100],numpy.uint8)#numpy.array([48, 138, 138],numpy.uint8)
GREEN_MAX = numpy.array([90, 235, 210],numpy.uint8)#numpy.array([67, 177, 192],numpy.uint8)

BLUE_MIN = numpy.array([0, 255, 85],numpy.uint8)#numpy.array([104, 200, 42],numpy.uint8)
BLUE_MAX = numpy.array([179, 255, 255],numpy.uint8)#numpy.array([179, 255, 255],numpy.uint8)

RED_MIN = numpy.array([163, 209, 30],numpy.uint8)#numpy.array([48, 138, 138],numpy.uint8)
RED_MAX = numpy.array([179, 255, 255],numpy.uint8)#numpy.array([67, 177, 192],numpy.uint8)

ORANGE_MIN = numpy.array([0, 123, 165],numpy.uint8)#numpy.array([48, 138, 138],numpy.uint8)
ORANGE_MAX = numpy.array([179, 255, 255],numpy.uint8)#numpy.array([67, 177, 192],numpy.uint8)


class PiBot:

Expand Down Expand Up @@ -95,8 +109,11 @@ def dameImagen(self):
Función que muestra la imagen percibida por la camara
'''
img = self.camera.getImage().data
cv2.imshow("img", img)
cv2.waitKey(0)
img = imutils.resize(img, width=400)

return img
#cv2.imshow("img", img)
#cv2.waitKey(0)

def leerIRSigueLineas(self):
'''
Expand Down Expand Up @@ -127,6 +144,50 @@ def leerUltrasonido(self):
value = self.us.getSonarData().range
return value

def dameObjeto(self, lower=ORANGE_MIN, upper=ORANGE_MAX, showImageFiltered=False):

image = self.dameImagen()
# convert to the HSV color space
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

# construct a mask for the color specified
# then perform a series of dilations and erosions
# to remove any small blobs left in the mask
mask = cv2.inRange(hsv, lower, upper)
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)

# find contours in the mask and
# initialize the current center
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
center = None
area = None

# only proceed if at least one contour was found
if len(cnts) > 0:
# find the largest contour in the mask, then use
# it to compute the minimum enclosing circle and
# centroid
c = max(cnts, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
area = M["m00"]

# only proceed if the radius meets a minimum size
if radius > 10:
# draw the circle border
cv2.circle(image, (int(x), int(y)), int(radius), (0, 255, 0), 2)

# and the centroid
cv2.circle(image, center, 5, (0, 255, 255), -1)

if showImageFiltered:
# Control waitKey from outside, only for local executions, not jupyter.
cv2.imshow("image_filtered", image)

return center, area

def quienSoy(self):
print ("Yo soy un robot simulado PiBot")

Expand Down
33 changes: 18 additions & 15 deletions src/drivers/PiBot/real/piBot.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
from JdeRobotKids import JdeRobotKids
import Ice
from jderobot_interfaces import JdeRobotKids
import numpy
import threading
import sys
import comm
import config
import jderobot_config
import progeo

from imutils.video import VideoStream
import imutils

class PiBot:

'''
Expand All @@ -26,9 +27,9 @@ def __init__(self, camara):
self._tipo = "PiBot"
self._dit = pigpio.pi()
self._frame = None
if camara == "PiCam"
if camara == "PiCam":
self._videostream = VideoStream(usePiCamera=True).start()
else
else:
self._videostream = VideoStream(usePiCamera=False).start()
'''
props = Ice.createProperties()
Expand Down Expand Up @@ -251,14 +252,15 @@ def leerUltrasonido(self): #devuelve la distancia a un objeto en metros
elapsed = stop - start

return (elapsed * 343) / 2

def dameImagen (self):
self._frame = self._videostream.read()
self._frame = imutils.resize(self._frame, width=400)
return self._frame

def mostrarImagen (self):
cv2.imshow("Imagen", self._frame)

def dameImagen (self):
self._frame = self._videostream.read()
self._frame = imutils.resize(self._frame, width=400)

return self._frame

def mostrarImagen (self):
cv2.imshow("Imagen", self._frame)

def damePosicionDeObjetoDeColor():
'''
Expand Down Expand Up @@ -291,6 +293,7 @@ def damePosicionDeObjetoDeColor():
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
area = M["m00"]

# only proceed if the radius meets a minimum size
if radius > 10:
Expand All @@ -300,7 +303,7 @@ def damePosicionDeObjetoDeColor():
# and the centroid
cv2.circle(image, center, 5, (0, 255, 255), -1)

return center
return center, area

def dameSonarVisual ():
'''
Expand Down
1 change: 1 addition & 0 deletions src/drivers/PiBot/real/progeo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import numpy

DEBUG = 1
Expand Down