Skip to content

Side cam #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 bot/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ omni_drive_motors: {
south: { board_num: 2, motor_num: 2 , invert: True},
east: { board_num: 0, motor_num: 2 , invert: True},
west: { board_num: 0, motor_num: 1 },
north: { board_num: 2, motor_num: 1 }

north: { board_num: 2, motor_num: 1 },
camera: generic_cam
}

IR : {
Expand Down
7 changes: 7 additions & 0 deletions bot/hardware/complex_hardware/SeventhDOF.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def __init__(self):

self.rail_DMCC = pyDMCC.DMCC(1)
self.rail_motor = self.rail_DMCC.motors[motor_num]

@lib.api_call
def get_position(self):
return self.rail_motor.position



@lib.api_call
def Orientor(self,Position):

Expand Down
31 changes: 18 additions & 13 deletions bot/hardware/complex_hardware/camera_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@
from bot.hardware.complex_hardware.QRCode2 import Block
from bot.hardware.complex_hardware.partial_qr import *

def find_name(symlink):
# find where symlink is pointing (/dev/vide0, video1, etc)
cmd = "readlink -f /dev/" + symlink
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
out = process.communicate()[0]

#extract ints from name video0, etc
nums = [int(x) for x in out if x.isdigit()]
# There should nto be more than one digit
interface_num = nums[0]
return interface_num


class Camera(object):

Expand All @@ -42,7 +32,7 @@ def __init__(self, cam_config):
udev_name = cam_config["udev_name"]
print udev_name

cam_num = find_name(udev_name)
cam_num = self.find_cam_num(udev_name)

# extract calib data from cam_config
self.a = cam_config["a"]
Expand All @@ -59,7 +49,22 @@ def __init__(self, cam_config):
self.scanner = zbar.ImageScanner()
self.scanner.parse_config('enable')


def find_name(self, symlink):
# find where symlink is pointing (/dev/vide0, video1, etc)
cmd = "readlink -f /dev/" + symlink
process = subprocess.Popen(cmd.split(),
stdout=subprocess.PIPE)
out = process.communicate()[0]

#extract ints from name video0, etc
nums = [int(x) for x in out if x.isdigit()]
# There should nto be more than one digit
if len(nums) != 0:
print "error with camera interfaces"
return
interface_num = nums[0]
return interface_num

def apply_filters(self, frame):
"""Attempts to improve viewing by applying filters """
# grayscale
Expand Down
21 changes: 16 additions & 5 deletions bot/hardware/complex_hardware/robot_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __init__(self, arm_config):

self.hopper = [None, None, None, None]

@lib.api_call
def get_props(self):
print "rail pos", self.rail.get_position()


@property
def joints(self):
return self.__joints
Expand All @@ -74,6 +79,8 @@ def joints(self, vals):
if len(vals) == 5:
self.__joints = vals
else:
vals[:] = [0 for i in a if i < 0]
vals[:] = [180 for i in a if i > 180]
self.__joints[:len(vals)] = vals
print "Joints to be sent: ", vals
self.servo_cape.transmit_block([0] + self.__joints)
Expand Down Expand Up @@ -128,8 +135,8 @@ def joint_center_on_qr(self):

# Correction constants for P(ID) controller.
# unlikely that we'll bother using I or D
p_x = 10
p_y = 10
p_x = 50
p_y = 6

while True:
ret = self.cam.QRSweep()
Expand All @@ -141,7 +148,7 @@ def joint_center_on_qr(self):
dy = ret.tvec[1]

if abs(dx) > 0.1:
self.joints[0] += p_x * dx
self.move_rail(p_x * dx)
if abs(dy) > 0.1:
self.joints[3] += p_y * dy
#print "Joints = ", self.joints
Expand Down Expand Up @@ -551,7 +558,11 @@ def check_hopper(self):
@lib.api_call
def orient(self, pos):
self.rail.Orientor(pos)


@lib.api_call
def move_rail(self, displacement):
return self.rail.DisplacementMover(displacement)

@lib.api_call
def GrabQR(self):
self.cam.QRSweep()
Expand Down Expand Up @@ -588,4 +599,4 @@ def color_test_loop(self, hopper_pos):
else:
print "Error: No color Found."



28 changes: 28 additions & 0 deletions bot/navigation/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import os.path
import yaml

from bot.hardware.complex_hardware import Camera

bound = lambda x, l, u: l if x < l else u if x > u else x

MAX_VALUE = 800
Expand All @@ -34,6 +36,32 @@ def __init__(self, rail_cars=0):
mapping = ["EXIT", "west", "east", "EXIT"]
self.rail_cars_side = mapping[rail_cars]

# camera for checking block
c_config = self.config["generic_cam"]
self.cam = Camera(c_config)

@lib.api_call
def check_current_car(self, expected_color):
""" Verifies that car is currenly facing a bin"""
frame = self.cam.get_current_frame()
qr_list = self.cam.get_qr_list(frame)

# Should not happen unless far away
if len(qr_list) > 2:
return False

# assure that at least 2 are same
colors = {"red":0, "blue": 0, "green":0, "yellow":0}
for q in qr_list:
colors[q.value] += 1

if any( i >= 2 for i in colors.itervalues()):
return True

# If none of these conditions met, assum not lined up
return False


def stop_unused_motors(self, direction):
direction = direction.lower()
if direction == "north" or direction == "south":
Expand Down