Commit f701cff4 authored by Mathieu Reymond's avatar Mathieu Reymond
Browse files

vertical camera position, minimal exception handling

parent 81a9c6d3
......@@ -7,6 +7,7 @@ import cv2
#Baxter and ROS imports
import baxter_interface
import rospy
import time
class BaxterAgent(object):
"""
......@@ -43,17 +44,24 @@ class BaxterAgent(object):
arm.move(arm.top)
rospy.sleep(2)
img = arm.take_snapshot()
self.baxter.sort(arm_name)
f = self.extract_features(img)
f['direction'] = arm_name.upper()
print(f)
self.tree.add_training_sample(f)
try:
f = self.extract_features(img)
f['direction'] = arm_name.upper()
print(f)
self.tree.add_training_sample(f)
self.baxter.sort(arm_name)
except:
print('no features found')
arm.move(arm.neutral)
def _train_end(self, msg):
if msg:
self.is_train = False
self.tree.train()
self.save_decision_tree()
try:
self.tree.train()
self.save_decision_tree()
except:
print('could not train features')
def train(self):
self.drawTrainingUI()
......@@ -72,14 +80,18 @@ class BaxterAgent(object):
if msg:
self.baxter.left.move(self.baxter.left.top)
img = self.baxter.left.take_snapshot()
features = self.extract_features(img)
cv2.imwrite('tosort.jpg', img)
print(features)
direction = self.tree.classify(features).lower()
print(direction)
if direction != 'left':
self.baxter.left.move(self.baxter.left.neutral)
self.baxter.sort(direction)
try:
features = self.extract_features(img)
cv2.imwrite('tosort.jpg', img)
print(features)
direction = self.tree.classify(features).lower()
print(direction)
if direction != 'left':
self.baxter.left.move(self.baxter.left.neutral)
self.baxter.sort(direction)
except Exception as e:
print(e)
self.baxter.both.move(self.baxter.both.neutral)
def _run_end(self, m):
if m:
......
......@@ -12,12 +12,10 @@ import cv_bridge as cvb
import cv2
class Arm(moveit_commander.MoveGroupCommander):
def __init__(self, name, neutral=None, top=None, pick=None, grasp=None):
def __init__(self, name, **kwargs):
super(Arm, self).__init__(name)
self.neutral = neutral
self.pick = pick
self.top = top
self.grasp = grasp
for i,v in kwargs.items():
setattr(self, i, v)
name = self.get_name()[:-4] #remove _arm from name)
self.bridge = cvb.CvBridge()
......@@ -99,12 +97,14 @@ class Arms(object):
class Baxter(object):
def __init__(self):
self.left = Arm('left_arm', neutral=[0.64623441, 0.84175585, 0.0570087, -0.3827256, 0.92221457, 0.02060252, 0.05115608],
top=[0.74667248, 0.02808032, 0.50554368, -0.00295978, 0.97005472, -0.02409497, 0.24167026],
up=[0.74667248, 0.02808032, 0.50554368, -0.00295978, 0.97005472, -0.02409497, 0.24167026],
top=[0.53463346, 0.0016183, 0.16230051, 0.00700717, 0.99995422, -0.00275706, -0.00590466],
pick=[7.54538492e-01, 3.44879303e-04, -6.50381151e-02, 5.63301315e-03, 9.99927904e-01, -9.66346662e-03, -4.36723168e-03],
grasp=[0.75390833, -0.00113117, -0.14, 0.00568284, 0.99992606, -0.00980662, -0.0044056])
self.right = Arm('right_arm',
neutral=[0.649446, -0.83735957, 0.06168316, 0.38299498, 0.92211736, -0.02071508, 0.050846],
top=[0.74667248, 0.02808032, 0.50554368, -0.00295978, 0.97005472, -0.02409497, 0.24167026],
up=[0.74667248, 0.02808032, 0.50554368, -0.00295978, 0.97005472, -0.02409497, 0.24167026],
top=[0.53463346, 0.0016183, 0.16230051, 0.00700717, 0.99995422, -0.00275706, -0.00590466],
pick=[7.54538492e-01, 3.44879303e-04, -6.50381151e-02, 5.63301315e-03, 9.99927904e-01, -9.66346662e-03, -4.36723168e-03],
grasp=[0.75390833, -0.00113117, -0.14, 0.00568284, 0.99992606, -0.00980662, -0.0044056])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment