Unassembled Mini Pan-Tilt Kit (Without Micro Servos) ID: 1968 DESCRIPTION Page 1 of 2 -
Page 2 of 2 This unssembled pan-tilt kit is the perfect way to give your project customized full range motion! The pan-tilt can rotate roughly 180° from side-to-side and can tilt downwards roughly 150° (it may be less depending on the servos you use, of course). This version comes in kit form without any servos, unlike our fully assembled version (http://adafruit.
Pixy Pet Robot - Color vision follower Created by Bill Earl Last updated on 2015-06-19 12:30:09 PM EDT
Guide Contents Guide Contents Overview and Materials Materials: Tools: Assemble the Camera Preparing the Pan/Tlt Base Remove the Side Tabs Trim the remaining tabs flush Cut a notch for the cable connectors Attach the Camera Connect the Servo Cables Secure the Cables Final Assembly Attach the Camera to the Leonardo Connect the ribbon cable Attach the Camera and Processor to the Zumo Playing with your Pixy Pet! Teach the Camera Find a toy! Connect the Camera Run PixyMon Upload the Code Play Ball! The Code
Derivative Control 38 Troubleshooting 40 © Adafruit Industries https://learn.adafruit.
Overview and Materials This project pairs the super-awsome Pixy CMUCam-5 vision system with the high performance Zumo robot platform, a pan/tilt mechanism and an Arduino Leonardo for a brain. The Pixy camera has powerful image processing capabilities that can track objects by color. It can track dozens of objects simultaneously and report their locations to the Arduino in real-time. The built-in pan/tilt servo control is fast enough to track a bouncing ball.
Materials: Pixy CMUcam-5 (http://adafru.it/dSP) Mini Pan/Tilt Kit - Assembled with Micro Servos (http://adafru.it/1967)* Zumo Robot (http://adafru.it/dSQ) Arduino Leonardo (http://adafru.it/849) Double-sided foam tape Cable Ties 4x AA batteries * If you have some micro-servos already, we also have an unassembled pan/tilt kit (http://adafru.it/1968) in the store. Some modifications may be required to fit your servo horns to the pan/tilt kit.
Note: Due to the pin assignments of the Zumo robot shield, this project will not work with an Uno or other Atmega 328-based processor. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Assemble the Camera The Pixy Camera itself is fully assembled. We just need to attach it to the pan/tilt base and connect the servos. The pan/tilt kit is available with and without sevos. The mechanism is sized to fit standard micro sevo cases. However, servo horns are not standardized. If using other servos, you may need to trim or re-shape the horns to fit. Preparing the Pan/Tlt Base The pan/tilt base has mounting tabs for a different style of camera module.
Remove the Side Tabs Cut the side tabs so that they are flush with the face of the camera mounting bracket. The bracket is made of a fairly soft nylon, so these are easly removed with a pair of wire cutters. © Adafruit Industries https://learn.adafruit.
Trim the remaining tabs flush There are two smaller alignment tabs and a cable guide that must be trimmed flush also. © Adafruit Industries https://learn.adafruit.
Cut a notch for the cable connectors We need to make room for the cable connectors on © Adafruit Industries https://learn.adafruit.
the back of the camera module. Two cuts, as shown in the photos will remove the top left side of the bracket. © Adafruit Industries https://learn.adafruit.
Attach the Camera Cut a 1"x1" piece of double-sided foam tape and position on the back of the camera module as shown. Remove the backing paper and align the camera bracket as shown. The connector headers on the back of the camera module will fit into the notch we cut in the previous step. Press down firmly to adhere the camera to the mounting bracket. Your final assembly should look like the last photo to the left.. © Adafruit Industries https://learn.adafruit.
Connect the Servo Cables The servo cables attach to the 2x6 pin header on the back of the camera. The cable for the pan servo (the bottom one) should be on the left. The cable for the tilt servo should be on the right. Make sure that the brown wire is on the bottom and the yellow wire is on top. Tape the two connectors together. This will make it © Adafruit Industries https://learn.adafruit.
easier to keep them from getting mixed up if you have to disconnect them later. Secure the Cables Route the servo cables as shown and anchor to the pan/tilt base with cable ties. Be sure to leave enough slack so that the cables will not interfere with the pan/tlt motion. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Final Assembly The Zumo itself comes pre-assembled, minus the Leonardo processor. We just need to attach the processor and camera assembly and connect the cables. Attach the Camera to the Leonardo Cut a piece of foam tape to fit in the recess in the bottom of the pan/tilt base. (If you are using narrower tape, you can use multiple pieces.) Position the camera as shown on the bottom of the Leonardo and press firmly to attach.
Connect the ribbon cable The gray ribbon cable that came with your Pixy has © Adafruit Industries https://learn.adafruit.
one 6-pin connector and one 8-pin connector. Attach the 6-pin end to the ICSP header on the Leonardo as shown. Make sure to align the edge with the red-stripe so that it is closest to the "LEONARDO" logo on the board. Attach the 8-pin end to the back of the Pixy. This connection is keyed, so there is only one way you can plug it in. © Adafruit Industries https://learn.adafruit.
Attach the Camera and Processor to the Zumo Align the Leonardo with the header pins on the Zumo. The camera should be facing the front. Press firmly to seat the board on the headers. And you are done! © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Playing with your Pixy Pet! Teach the Camera The first thing you need to do is teach Pixy the objects you want it to track. The best way to do this is using the PixyMon software. With PixyMon, you can see exactly what Pixy sees and how well it has learned. Find a toy! Brightly colored balls are good. Place it in view of the Pixy camera. Connect the Camera Connect the camera to your computer using a miniB USB cable.
Download PixyMon from the link above. (There are several versions, be sure to pick the right one for your operating system.) Launch the PixyMon application. Select the "Cooked" view (click on the icon with the chef's hat!) This view will show you exactly what the Pixy camera sees in realtime. Click "Action->Set Signature1..." Select an area on the ball to teach a color to the camera. Once learned, the camera will indicate recognized objects with a rectangle and signature number.
The Code Copy the code below into the Arduino IDE and upload.
class ServoLoop { public: ServoLoop(int32_t proportionalGain, int32_t derivativeGain); void update(int32_t error); int32_t int32_t int32_t int32_t }; m_pos; m_prevError; m_proportionalGain; m_derivativeGain; // ServoLoop Constructor ServoLoop::ServoLoop(int32_t proportionalGain, int32_t derivativeGain) { m_pos = RCS_CENTER_POS; m_proportionalGain = proportionalGain; m_derivativeGain = derivativeGain; m_prevError = 0x80000000L; } // ServoLoop Update // Calculates new output based on the measured // error a
//--------------------------------------Pixy pixy; // Declare the camera object ServoLoop panLoop(200, 200); // Servo loop for pan ServoLoop tiltLoop(150, 200); // Servo loop for tilt ZumoMotors motors; // declare the motors on the zumo //--------------------------------------// Setup - runs once at startup //--------------------------------------void setup() { Serial.begin(9600); Serial.print("Starting...\n"); pixy.
//--------------------------------------// Track blocks via the Pixy pan/tilt mech // (based in part on Pixy CMUcam5 pantilt example) //--------------------------------------int TrackBlock(int blockCount) { int trackedBlock = 0; long maxSize = 0; Serial.print("blocks ="); Serial.println(blockCount); for (int i = 0; i < blockCount; i++) { if ((oldSignature == 0) || (pixy.blocks[i].signature == oldSignature)) { long newSize = pixy.blocks[i].height * pixy.blocks[i].
void FollowBlock(int trackedBlock) { int32_t followError = RCS_CENTER_POS - panLoop.m_pos; // How far off-center are we looking now? // Size is the area of the object. // We keep a running average of the last 8. size += pixy.blocks[trackedBlock].width * pixy.blocks[trackedBlock].
motors.setRightSpeed(250); } else { motors.setLeftSpeed(+180); motors.setRightSpeed(-180); } delay(random(250, 500)); } pixy.setServos(panLoop.m_pos, tiltLoop.m_pos); } } © Adafruit Industries https://learn.adafruit.
Pixy Pet Code Design OK. That was fun, but how does it work? The Pixy Robot code consists of two main control systems: Object Tracking with the Pixy Camera and the pan/tilt mechanism and Object Following with the Zumo robot base. Together these two systems produce a very natural looking response where the 'head' turns in response to motion and the 'body' follows. Both control systems are based on Feedback Control Loops.
//--------------------------------------// Track blocks via the Pixy pan/tilt mech // (based in part on Pixy CMUcam5 pantilt example) //--------------------------------------int TrackBlock(int blockCount) { int trackedBlock = 0; long maxSize = 0; Serial.print("blocks ="); Serial.println(blockCount); for (int i = 0; i < blockCount; i++) { if ((oldSignature == 0) || (pixy.blocks[i].signature == oldSignature)) { long newSize = pixy.blocks[i].height * pixy.blocks[i].
On each pass through the main loop, we calculate the errors for the pan and tilt controls as the difference between the measurements and the setpoints. Then we invoke the ServoLoop control algorithms to calculate the outputs. //--------------------------------------// Servo Loop Class // A Proportional/Derivative feedback // loop for pan/tilt servo tracking of // blocks.
}; // ServoLoop Constructor ServoLoop::ServoLoop(int32_t proportionalGain, int32_t derivativeGain) { m_pos = RCS_CENTER_POS; m_proportionalGain = proportionalGain; m_derivativeGain = derivativeGain; m_prevError = 0x80000000L; } // ServoLoop Update // Calculates new output based on the measured // error and the current state.
will back up. //--------------------------------------// Follow blocks via the Zumo robot drive // // This code makes the robot base turn // and move to follow the pan/tilt tracking // of the head. //--------------------------------------int32_t size = 400; void FollowBlock(int trackedBlock) { int32_t followError = RCS_CENTER_POS - panLoop.m_pos; // How far off-center are we looking now? // Size is the area of the object. // We keep a running average of the last 8. size += pixy.blocks[trackedBlock].
© Adafruit Industries https://learn.adafruit.
Feedback Control Basics Measurements, Setpoints, Errors and Ouputs To start with, let's define some terms commonly used to describe control systems: Measurement - This is typically the value of the parameter you are trying to control. It could be temperature, pressure, speed, position or any other parameter. Before you can control anything, you have to be able to measure it. Setpoint - This is the desired value for the parameter you are trying to control.
heat. If the measured temperature is above the setpoint, it turns it off. To prevent rapid cycling which could damage the system, there is typically some gap between the 'on' threshold and the 'off' threshold. This is called 'hysteresis'. An On/Off controller with hysteresis s sometimes called a "Differential Gap Controller". That sounds pretty sophisticated, but it is still a very primitive type of controller.
setpoint. The Pixy object tracking algorithm uses derivative control in conjunction with the proportional control to help prevent over-correction when tracking objects. © Adafruit Industries https://learn.adafruit.
Troubleshooting Pixy Pet wont track an object Pixy Pet tracks best if the object is a bright saturated color. It also helps if there are not a lot of similarly colored things in the environment to distract your Pixy. Pixy Pet loses the tracked object - even when it is right in front of it. Pixy Pet performs best in a brightly lit area. Check with PixyMon to make sure that Pixy recognizes the object well and re-teach that color signature if necessary. Sometimes, moving to an area with different lighting (e.