<< return to Pixycam.com

Extract Pan and Tilt Values from Arduino Demo

Hello,

I am attempting to extract the pan and tilt values from the pan/tilt demo in the Arduino. Simply, I want to print them to the Serial Monitor. I assume (from reading the excerpt in italics below) that this data is derived from the center (x and y values) of the detected object. The reason, I wish to extract these, is to control another device in realtime. I am sure this is as simple as adding another println.

Thank you in advance,
Erik

The Pan/Tilt control is implemented using 2 instances of the ServoLoop class - one for the pan and one for the tilt. ServoLoop is a feedback control loop using both Proportional + Derivative (PD) control. The measurements are the x (for pan) and y (for tilt) positions of the blocks reported by the Pixy Camera. The setpoints are the x, y position of the center of the camera’s view. And the outputs are the servo positions

Here is a a link to an Adafruit project that uses this functionality: https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/the-code

Hey Erik,

replied to your same question via email, but posting here for others with similar questions.

From the Arduino pan/tilt demo code:

pixy.setServos(panLoop.m_pos, tiltLoop.m_pos);

is the command that actually sets the servo position. You should be able to print the two variables there (panLoop.m_pos and tiltLoop.m_pos) to the serial monitor and get what you’re after.

These values are different than the x and y center values of whatever object Pixy is tracking - the pan/tilt demo uses PD control, which calculates an output value that is proportional to the magnitude of the error. Check out this page (from the Pixy Pet Robot writeup) which does a good job of explaining the concepts involved: https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/feedback-control-basics

Hope this helps!

Best,
Jesse

This is very helpful. Thanks Jesse.

I am now trying to use these PD values which are returned as integers between 0 and 1000. What confuses me is that they control two servo motors (which makes me think that the values should be between 0 and 180). So, after reading the Adafruit post, I see that the values derived from the TrackBlock function which returns the @panloop.m_pos@ and @tiltloop.m_pos@ to control the servo positions. I believe this text sums it up,
_
The Pan/Tilt control is implemented using 2 instances of the ServoLoop class - one for the pan and one for the tilt. ServoLoop is a feedback control loop using both Proportional + Derivative (PD) control. The measurements are the x (for pan) and y (for tilt) positions of the blocks reported by the Pixy Camera. The setpoints are the x, y position of the center of the camera’s view. And the outputs are the servo positions.
_

Nevertheless, it seems like there is a simple conversion ratio between the PD and X/Y positions that returns the servo motor positions in degrees. From the adafruit post a ‘servoLoop control algorithm’ is used; however, I cannot readily understand the code here. Is there some logic that you can pass along or a formula to extract the servo positions, or a way to transpose the values I have now into degrees?

I ask because I wish to control another servo pan tilt with these values.

Also, is there a difference between the ‘trackBlock’ and ‘getBlocks’ functions?

Thanks so much in advance!
Erik

Hi Erik,

I’m not an expert, so I asked engineering. Here is their response: all servos are slightly different, so the numbers don’t really correspond to degrees, etc. The numbers correspond to pulse width in microseconds (we can vary the pulse width with microsecond accuracy.) The width of the pulse is what servos use to determine the servo angle.

About your trackBlock / getBlocks question - Pixy.getBlocks() is a function in the Arduino library that retrieves object data from the Pixy. More info on our Arduino library and commands here: http://cmucam.org/projects/cmucam5/wiki/Arduino_API

trackBlock is a function in Adafruit’s code (https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/pixy-pet-code ) - according to their writeup, it uses the information from Pixy to adjust the pan and tilt servos to try to keep the tracked object in the center of the field of view.

Hope this helps!

Best,
Jesse

Thanks so much Jesse. I had not expected this information, but it now makes sense. I appreciate you taking the effort to acquire this information. Also, I understand about the functions now.

Kind Regards,
Erik