<< return to Pixycam.com

Need help on Pixy2 with Zumo Code Please

Hello,
Just bough a Zumo for Arduino kits with a Pixy2 and Pan-Tilt kit. after following the guide on the Pixycam website, I can make everything works just as intend.

However, when running ccc_zumo_chase demo. My Zumo will always run over the object. After inspec the code, I found there is no code on keeping the distance with object when find and track the block().

I’d like to keep the bot always at same distance when find and tracked. here are the code I think it could work… but I am so convinced I did WRONG… where should I put the code to?

int32_t size = 400;
void FollowBlock(int trackedBlock)
{
int32_t followError = RCS_CENTER_POS - panLoop.m_pos;
size += pixy.ccc.blocks[trackedBlock].m_width * pixy.ccc.blocks[trackedBlock].m_height;
size -= size >> 3;
int forwardSpeed = constrain(400 - (size/256), -100, 400);
int32_t differential = (followError + (followError * forwardSpeed))>>8;
int leftSpeed = constrain(forwardSpeed + differential, -400, 400);
int rightSpeed = constrain(forwardSpeed - differential, -400, 400);
motors.setLeftSpeed(leftSpeed);
motors.setRightSpeed(rightSpeed);
}

I’m just starting to learn C++ and taking beginner online courses. Basically I have no idea what I am doing… this is a great project for me to start learning.

Thank you so much for your time looking into this.

Sam

Hello,
I don’t quite understand your code. There are lots of functions that aren’t included. Note the follow code:

Contains a “translate loop” (called translateLoop) that tries to keep distance to an object by looking down on the object… If the object is sufficiently large your pixy robot won’t be able to look down on it. Why does it need to look down* on the object? By having the object below Pixy’s line of vision, the object will move father down in the image the closer the robot gets to the object. It’s because of this Pixy can estimate the distance to the object.

Hope this helps!

Edward

That’s a great explanation Edward! Thank you for your time!
and could you please explain: translateLoop(400, 800, 300, false)
400, 800, 300, and false means?

Just wondering if is possible to keep the distance from the object, and calculate the distance from pixy2’s frame size. So the zumo bot will always keep the same frame size if the object get too close (frame size exceed the set size)

example: frame size = 400 height, 400 width. if object get too close the frame size will become 500 hight and 500 width. there for zumo will back up to the 400 height, 400 width. if less than 400h, 400w zumo will go to it.

do you think that will work too?

That’s sort of the idea :slight_smile: The frame size doesn’t change though, just the location of the object in the image.

The 400, 800 and 300 are the PID gains and the false means that we don’t want the PID loop to send servo commands (we will do that when we call motors.setLeftSpeed(left), motors.setRightSpeed(right))

The PID code is here:

PID loops are simple control loops, but can be pretty daunting/confusing if you haven’t seen them before.

Hope this helps :slight_smile:

Edward

that’s great Edward, I am going to look into some PID study cases. hopefully one day I can really understand how to tune the PID with pixy2 and zumo together. thank you for all your help! if I have more questions I hope you don’t mind me bugging you here :slight_smile:

btw: what if I change those PID Loop number bigger or smaller, will it break my servo? just want to know how are those number relate to the servos? or Pixy2’s image?
PID_MAX_INTEGRAL 2000 // how is the “2000” come from? max value of the servo? or the image?

Hello,
The PID values (or gains) don’t have any units. They don’t relate to pixels in the image or degrees the servos turn. You can’t break the servos if you use the wrong values, at least not quickly :slight_smile:

Edward

that’s great! finger crossed as I am trying to tuning and learning it. thank you for all your help!