Huskylens with servo control.

userHead MurbiesWalto 2022-12-20 15:08:46 883 Views2 Replies

I'm fairly new to all of this, I was wondering if anyone had some Insight or some good sources to read up on. I have a Huskylens camera module and have been able to follow the wiki and get the block size coordinates and center coordinates in the serial monitor in the object tracking mode. My problem is I don't know where to start with taking that data and translating it to servos that will keep the camera centered on the object. I have a very basic Pan and Tilt set up with MG995 servos. Anyone point me in the direction of a tutorial or have some insight on converting that data to control 2 servos? Thank you!

2023-04-14 16:55:01

Thanks a lot for information, was searching similar!

userHeadPic nickfury1
2023-04-13 20:32:12

I would use the Map function. The Huskys screen size/image size is 320x240 so it can be translated to control a servo like this.

map(value, fromLow, fromHigh, toLow, toHigh)

 

Value=X value(Horizontal center)

fromLow=0

fromHight=320

toLow=0

toHigh=180

This will get you started but you will find out that your servos are going to move wildly as they are trying to keep up with the object/color you are trying to track.

 

The best way I found to do it is like this.

Lets just track the horizontal for this example and you can do the same for the vertical.

1)Get you horizontal center value

2)Next you want to setup an imaginary window as you will see you will need a buffer area to keep things from going crazy. So your width is 320, this means the center is 160 subtract 10 from that and you have 150, add 10 to the 160 and you have 170 this is your buffer area.

3)Using a simple if statement of logic you can now perform the actions. if(x< =150) { A=A-1 Servo1.write(A);} , then do this for the other side if(x> =170) {A=A+1  Servo1.write(A);} then to keep everything within the 0 to 180 do this. if(A<0){A<0;), and this the other way if(A>180){A=180;} 

4)You can do the same for your vertical movement. if you want the servo to move faster just change the value of A=A+1 to A=A+2 or some other value.

If you find your servos moving in the opposite direction that they should to track the object then just change the math from A=A-1 to A=A+1. Hope this helps you.

userHeadPic Jeffro