<< return to Pixycam.com

Tilt/Pan servo position with Arduino

I’m running the Pixy2 on an Arduino Uno using your ccc_pantilt.ino example. Seems to be working fine right out of the box which is great. I need to print the position of the pane & tilt servos.

Looks like this function is where the magic happens:
pixy.setServos(panLoop.m_command, tiltLoop.m_command);

I’ve been rooting around in the Pixy2.h and PIDLoop.h files to try and find if there is a variable that holds these values with no luck.

Any help would be greatly appreciated

The PID loop code is in this file:

The variable is stored in m_command, which is (in the case of the servos), the servo position.

Hope this helps!


Thanks! I’ll try to summarize what I did.

I ended up creating a global integer variable “xyz” in the ccc_pantilt.ino example.

I then declared it as an “extern int” variable in the PIDLoop.h file. (I had to edit the .h file in notepad)
I then set xyz = m_command; at the right spot inside the PIDLoop.h file.

I then did a Serial.print(xyz); twice inside the ccc_pantilt.ino example. Once after panLoop.update(panOffset); and once after liltLoop.update(tiltOffset);

At the locations of these new print commands, I could redefine other variables such as PanPosition=xyz;, and TiltPosition=xyz; to store for other purposes to complicated to get into now.

If I didn’t need to store the values, I could have just done a Serial.println(m_command); inside the PIDLoop.h file at the right spot.