<< return to Pixycam.com

Controlling Pan/Tilt on Pixy2/Zumo Robot

Hello,
I have successfully made Pixy2/Zumo robot that runs well
with ccc_zumo_chase software. Now want to add a pan scanning
function to the block searching section, but I can control
the pan/tilt servos. Below is a simple attempt to contol the servos.
It deos not work. What is wrong? Thanks.

#include <Pixy2.h>
#include <PIDLoop.h>
#include <ZumoMotors.h>
Pixy2 pixy;//create pixy object
ZumoMotors motors;
PIDLoop panLoop(350, 0, 600, true);
PIDLoop tiltLoop(500, 0, 700, true);

int32_t panOffset;
int32_t tiltOffset = 600;

void setup() {
motors.setLeftSpeed(0);
motors.setRightSpeed(0);
pixy.init();
pixy.changeProg(“color connected components”);

}

void loop() {
pixy.ccc.getBlocks();
panOffset = 200;
panLoop.update(panOffset);
tiltLoop.update(tiltOffset);
pixy.setServos(panLoop.m_command, tiltLoop.m_command);
delay(2000);

pixy.ccc.getBlocks();
panOffset = 500;
panLoop.update(panOffset);
tiltLoop.update(tiltOffset);
pixy.setServos(panLoop.m_command, tiltLoop.m_command);
delay(2000);

pixy.ccc.getBlocks();
panOffset = 800; 
panLoop.update(panOffset);
tiltLoop.update(tiltOffset);
pixy.setServos(panLoop.m_command, tiltLoop.m_command);
delay(2000);

pixy.ccc.getBlocks();
panOffset = 500;
panLoop.update(panOffset);
tiltLoop.update(tiltOffset);
pixy.setServos(panLoop.m_command, tiltLoop.m_command);
delay(2000);

}

Hello,
Can you describe in detail how the program fails?

Edward

Thank you for the prompt replay. I am very impressed by the Pixy but find the software daunting as an hobbyist programmer .

The program I sent you has no effect of the servos. I expected them to move every two seconds, but nothing or the occasional random movement. Nothing as definite has I have got with running the servos directly from an UNO.

Hello,
You should try calling setServos directly:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:general_api

That is, try the command, or similar:

pixy.setServos(500, 500);

Edward

1 Like

Edward, Thank you. That was very helpful.

1 Like