<< return to Pixycam.com

Servo Dead Zone

Is there anyway to create a sort of dead zone in the Pixymon software so that when an object is near the center the servos don’t move around so much? I am using 2 large servos to control a pan tilt mechanism and as it tracks the object it seems to jitter and shake a lot instead of holding steady onto the object. I know it’s not a power issue, but I thought maybe a sort of dead zone in the middle of the screen would help prevent it from moving so much. Thank you for this amazing piece of kit!!

Hello,
If you are using the ccc_pantilt Arduino program, it’s fairly easy to add a dead zone in the code. If you are using pan-tilt demo from PixyMon, it’s not as easy.

In the ccc_pantilt.ino, there’s this code:

panOffset = (int32_t)pixy.frameWidth/2 - (int32_t)pixy.ccc.blocks[0].m_x;
tiltOffset = (int32_t)pixy.ccc.blocks[0].m_y - (int32_t)pixy.frameHeight/2;  

which generates the error for pan and tilt. You want to essentially ignore errors below a certain threshold – something like this:

panOffset = deadzone((int32_t)pixy.frameWidth/2 - (int32_t)pixy.ccc.blocks[0].m_x);
tiltOffset = deadzone((int32_t)pixy.ccc.blocks[0].m_y - (int32_t)pixy.frameHeight/2);

where deadzone() is:

#define MIN_ERROR  10

int32_t deadzone(int32_t error) {
  if (error>MIN_ERROR)
      return error-MIN_ERROR;
  else if (error<-MIN_ERROR)
      return error+MIN_ERROR;
  else
      return 0;
}  

Hope this helps!

Edward

Hello :slight_smile:
i have 12bit 333Hz servos so i need to get 12bit data from pixy2
please can you check my code if its good or not:

PositionXmotor=MinServo+float(double((pixy.ccc.blocks[0].m_x)/pixy.frameWidth*(MaxServo - MinServo));
PositionYmotor=MinServo+float(double(pixy.ccc.blocks[0].m_y)/pixy.frameHeight*(MaxServo - MinServo));

do i need to add (int32_t) for the code like this:
PositionXmotor=MinServo+float(double((int32_t)pixy.ccc.blocks[0].m_x)/(int32_t)pixy.frameWidth*(MaxServo - MinServo));
PositionYmotor=MinServo+float(double((int32_t)pixy.ccc.blocks[0].m_y)/(int32_t)pixy.frameHeight*(MaxServo - MinServo));

i got the idea from this code:
panOffset = (int32_t)pixy.frameWidth/2 - (int32_t)pixy.ccc.blocks[0].m_x;
tiltOffset = (int32_t)pixy.ccc.blocks[0].m_y - (int32_t)pixy.frameHeight/2;

i need to make my code fast as possible, i will use Arduino H7 lite, so i have good 8mbRAM.

Thanks
G.K
:maple_leaf:

i asked the GPT4 and he told me to use this code:
PositionXmotor = map(pixy.ccc.blocks[0].m_x, 0, pixy.frameWidth, MinServo, MaxServo);
PositionYmotor = map(pixy.ccc.blocks[0].m_y, 0, pixy.frameHeight, MinServo, MaxServo);

GPT4: If you want to use the Arduino H7 Lite to control your servos, you don’t need to cast the result of the calculation to float or double.
so what do you Think :thinking:
Thanks

Hello,
I’m not familiar with 12 bit 333Hz servos. Pixy is sending standard 60Hz PWM commands to its servo port. The Arduino code will not change this, unless your Arduino is driving the servos.

Edward

1 Like

Hello Edward :slight_smile:
Thanks for your reply
yes you are right i am driving another extra two servos on Arduino H7 lite, so i can play with the frequency and resolution for the 12bit 333hz servos outputs .
please can you check my code if its good or not:
PositionXmotor=MinServo+float(double((pixy.ccc.blocks[0].m_x)/pixy.frameWidth*(MaxServo - MinServo));
PositionYmotor=MinServo+float(double(pixy.ccc.blocks[0].m_y)/pixy.frameHeight*(MaxServo - MinServo));

i asked the GPT4 and he told me to use this code with mapping:
PositionXmotor = map(pixy.ccc.blocks[0].m_x, 0, pixy.frameWidth, MinServo, MaxServo);
PositionYmotor = map(pixy.ccc.blocks[0].m_y, 0, pixy.frameHeight, MinServo, MaxServo);
GPT4: If you want to use the Arduino H7 Lite to control your servos, you don’t need to cast the result of the calculation to float or double.
so what do you Think :thinking:

to get better 12bit resolution do i need to add (int32_t) for the code like this:
PositionXmotor=MinServo+float(double((int32_t)pixy.ccc.blocks[0].m_x)/(int32_t)pixy.frameWidth*(MaxServo - MinServo));
PositionYmotor=MinServo+float(double((int32_t)pixy.ccc.blocks[0].m_y)/(int32_t)pixy.frameHeight*(MaxServo - MinServo));

i got the idea from this code:
panOffset = (int32_t)pixy.frameWidth/2 - (int32_t)pixy.ccc.blocks[0].m_x;
tiltOffset = (int32_t)pixy.ccc.blocks[0].m_y - (int32_t)pixy.frameHeight/2;

please let me know!
Thanks