3 Servo Y and 2 Servo X from one OpenCV.

Hello this is my first post, My name is Bart an I have a little problem. I designed articulating neck with 2 Y servos. But in i01.Head is only one Y servo for tracking. Is there possible to getY position from one OpenCV tracking? I write many of codes and I have always two OpenCV each one for each servo. Sorry for my english I hope that You undestand me. 3 Servo Y and 2 Servo X is for Eyes and Head Tracking.

How to create more that one tracking service from one OpenCV camera like is in i01.head.tracking and i01.eyes.tracking?

Here is one of my simple code but it doesn't work.

port = "COM3"   
xServoPin = 13   
yServoPin = 12   
xServoPin2 = 38   
yServoPin2 = 40   
 
tracker = Runtime.createAndStart("tracker", "Tracking")
 
servo2X = Runtime.createAndStart("servo2x", "Servo")
servo2X.setPin(xServoPin2)
 
 
servoX = tracker.getX() #first X Servo
servoX.setPin(xServoPin)
servoX.setMinMax(30, 150) 
 
servoY = tracker.getY()
servoY.setPin(yServoPin)
servoY.setM
servo2X = servoX.getPos() #second X servo
 
 
servo2Y = servoY.getPos()
servo2Y.setPin(yServoPin2)
servo2Y.setMinMax(30, 150)  
 
opencv = tracker.getOpenCV()
 
 
opencv.setCameraIndex(0) 
 
 
tracker.connect(port)
 
 
 
tracker.startLKTracking()

 

Mats's picture

Syncronizing servos

Hi bartcam

I made a small demo script on how to syncronize servos. In this demo, the left and the right eye moves in sync, but you can use the same method to syncronize any two ( or more ) servos.

In this demo the left eye is the master and the right eye is the slave.

You will need to change the script to fit your configuration. In your case I think it would be a good start to test the scripts with the left neck servo and the right neck servo.

https://github.com/MyRobotLab/pyrobotlab/blob/master/home/Mats/SyncServo...

/Mats

juerg's picture

listen to servo events

hi Mats

thanks of this example of a servo event listener. How would you do that if more than 1 servo should get observed - I do not see a direct connection of "def onServoEvent" with "addServoEventListener". In your example all servo publishers would trigger the onServoEvent?

 

bartcam's picture

Very thank You, after small

Very thank You, after small modyfications work great.

leftneckPin = 38
 
delta = 0
def onServoEvent(pos):
     leftneckServo.moveTo(pos+delta)
#
python = Runtime.getService("python")
 
leftneckServo = Runtime.createAndStart("i01.head.neck2","Servo")
 
 
leftneckServo.setMinMax(30,140)
leftneckServo.map(0,180,30,140)
leftneckServo.setRest(91)
leftneckServo.attach("i01.left",leftneckPin)
#leftNeckServo.setInverted(True)
 
i01.head.neck.addServoEventListener(python)
i01.head.neck.eventsEnabled(True)

 

 

Mats's picture

You are correct

Hi Juerg

I agree to what you write. So I added the onServoEvent method to the servo service. So now you can do it this way:

# Make the left eye follow the right
rightEyeX.addServoEventListener(leftEyeX)
rightEyeX.eventsEnabled(True)

I also updated the example, since I think this is a better way to do it.

https://github.com/MyRobotLab/pyrobotlab/blob/master/home/Mats/SyncServo...