<< return to Pixycam.com

Pixy not following properly?

I just set up my robot and from what I see pixy is running away from the tracked object(doing the opposite) I placed the tilt servo on the rift and pan servo on the left, pixy can track and everything works fine(using arduino code) but the code is just written backwards im guessing

can someone help me fix this so that pixy doesn’t look away from tracked object?
here is the code im using.

//
// begin license header
//
// This file is part of Pixy CMUcam5 or "Pixy" for short
//
// All Pixy source code is provided under the terms of the
// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
// Those wishing to use Pixy source code, software and/or
// technologies under different licensing terms should contact us at
// [email protected]. Such licensing terms are available for
// all portions of the Pixy codebase presented here.
//
// end license header
//
// This sketch is a simple tracking demo that uses the pan/tilt unit.  For
// more information, go here:
//
// http://cmucam.org/projects/cmucam5/wiki/Run_the_Pantilt_Demo
//

#include   
#include 

Pixy pixy;

#define X_CENTER        ((PIXY_MAX_X-PIXY_MIN_X)/2)       
#define Y_CENTER        ((PIXY_MAX_Y-PIXY_MIN_Y)/2)

class ServoLoop
{
public:
  ServoLoop(int32_t pgain, int32_t dgain);

  void update(int32_t error);
   
  int32_t m_pos;
  int32_t m_prevError;
  int32_t m_pgain;
  int32_t m_dgain;
};


ServoLoop panLoop(300, 500);
ServoLoop tiltLoop(500, 700);

ServoLoop::ServoLoop(int32_t pgain, int32_t dgain)
{
  m_pos = PIXY_RCS_CENTER_POS;
  m_pgain = pgain;
  m_dgain = dgain;
  m_prevError = 0x80000000L;
}

void ServoLoop::update(int32_t error)
{
  long int vel;
  char buf[32];
  if (m_prevError!=0x80000000)
  {	
    vel = (error*m_pgain + (error - m_prevError)*m_dgain)>>10;
    //sprintf(buf, "%ld\n", vel);
    //Serial.print(buf);
    m_pos += vel;
    if (m_pos>PIXY_RCS_MAX_POS) 
      m_pos = PIXY_RCS_MAX_POS; 
    else if (m_pos<PIXY_RCS_MIN_POS) 
      m_pos = PIXY_RCS_MIN_POS;
  }
  m_prevError = error;
}



void setup()
{
  Serial.begin(9600);
  Serial.print("Starting...\n");
  
  pixy.init();
}

void loop()
{ 
  static int i = 0;
  int j;
  uint16_t blocks;
  char buf[32]; 
  int32_t panError, tiltError;
  
  blocks = pixy.getBlocks();
  
  if (blocks)
  {
    panError = X_CENTER-pixy.blocks[0].x;
    tiltError = pixy.blocks[0].y-Y_CENTER;
    
    panLoop.update(panError);
    tiltLoop.update(tiltError);
    
    pixy.setServos(panLoop.m_pos, tiltLoop.m_pos);
    
    i++;
    
    // do this (print) every 50 frames because printing every
    // frame would bog down the Arduino
    if (i%50==0) 
    {
      sprintf(buf, "Detected %d:\n", blocks);
      Serial.print(buf);
      for (j=0; j<blocks; j++)
      {
        sprintf(buf, "  block %d: ", j);
        Serial.print(buf); 
        pixy.blocks[j].print();
      }
    }
  }  
}

Hello James,
You might try modifying these two lines:

    panError = X_CENTER-pixy.blocks[0].x;
    tiltError = pixy.blocks[0].y-Y_CENTER;

change them so that they are the exact negative:

    panError = pixy.blocks[0].x-X_CENTER;
    tiltError = Y_CENTER-pixy.blocks[0].y;

Hope this helps!

Edward

thank you but now I have a new problem… I unplugged everything from the laptop and went to pick up my siblings and when I came back, I tried it again to show them but it said no pixy device detected, the usb works because when I plug it in, the pixy turns white, I googled to find the answer but when I try to hold the power then plug the usb, it doesn’t blink, it stays bright white, I tried plugging it into another laptop and it still didn’t work

when I plugged my axon to laptop using the same usb cord it worked(makes the usb plugged in sound) but when I try with my pixy it doesnt. I tried unplugging my servos, and all… why did my pixy randomly stop getting detected? what can I do to fix it?

Hello James,
That’s odd. Can you run through this troubleshooting guide?

http://cmucam.org/projects/cmucam5/wiki/I_get_the_message_"No_Pixy_devices_have_been_detected"_in_PixyMon

Edward

ok my old pixy was a defective one and the new one came in the mail, and I edited the code like you told me but its still not following properly

Hello James,
Can you describe your problem. It doesn’t sound like the same problem as before. If you are having trouble with Pixy detecting objects (false positives, false negatives), this page might help:

http://cmucam.org/projects/cmucam5/wiki/Some_Tips_on_Generating_Color_Signatures_2

Edward

its the same problem as the original post said, the pixy can detect and everything works fine, it just doesn’t follow the object correctly, when I place an object in pixy’s view pixy should be following the object but instead it looks away.

I fixed the problem, and for anyone having the same problem, the problem is the way the servos are connected, mine were in the right place, pan on the left and tilt on the right, BUT they were facing the WRONG direction, the yellow is supposed to be on top and black on bottom with yellow(of course) in the middle.

Good news :slight_smile:

Hello,

I am working on my final robotics project for school. I decided to get involved with this cam but ever since I got it, assembled it and run the pan/tilt demo, both servos have not worked properly. After assembling the kit and connecting Pixy to my laptop the servos go to their zero position as they are meant to however when moving to the opposite side (facing downward and to the left) both servos get stuck and wont move (not to mention the continuous buzzing) unless I force them. I already broke one of the servos trying to maneuver it in the opposite direction

The pan is plugged in on the left, the tilt on the right, and the yellow signal wire is at the top for both connectors. I tried switching the position of the connectors (pan on right, tilt on left) just to see the result and the same servo continues to get stuck regardless of which side it is plugged into.

I also tried changing the servo frequency in PixyMon for kicks and the problem still persist.

I also disassembled and reassembled the kit to make sure it was not a binding issue however both servos still get stuck.

Could this be a problem with the pan/tilt demo program the camera is sending to the servos? or could there be another problem at hand?

I appreciate any help I can get!

Thank you,

(BTW I am running the Pixymon version 2.0.9 in a windows 10 x64)

If your pixy cam is moving but isn’t moving correctly the problem is how the servo wires are connected, never force servo movements once it is powered, you will damage your servo motor, try this.

STEP A.

  1. switch the wire places, the left goes right, the right goes left
  2. switch the wire direction, if both wires were facing left, face them right, if they were facing right, face them left.
  3. switch and try again.

STEP B
also try messing with the code(only mess with the code if step a didn’t work)
ServoLoop panLoop(300, 500);
ServoLoop tiltLoop(500, 700);
especially this portion