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")
servoX = tracker.getX() #first X Servo
servoX.setMinMax(30, 150) 
servoY = tracker.getY()
servo2X = servoX.getPos() #second X servo
servo2Y = servoY.getPos()
servo2Y.setMinMax(30, 150)  
opencv = tracker.getOpenCV()


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.



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):
python = Runtime.getService("python")
leftneckServo = Runtime.createAndStart("i01.head.neck2","Servo")



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

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