<< return to Pixycam.com

I found the cause of the strange x, y positional display of blocks

The problem was in the position of “block-> print ()”. (in ‘ccc_zumo_chase.ino’ )

Below is a loop() of the ccc_zumo_chase.ino code provided as an example.


pixy.ccc.getBlocks();

if (index==-1) // search…
{
Serial.println(“Searching_for_block…”);
index = acquireBlock();
if (index>=0)
Serial.println(“Found_block!”);
}
// If we’ve found a block, find it, track it
if (index>=0)
block = trackBlock(index);

// If we’re able to track it, move motors
if (block)
{
panOffset = (int32_t)pixy.frameWidth/2 - (int32_t)block->m_x;
tiltOffset = (int32_t)block->m_y - (int32_t)pixy.frameHeight/2;
panLoop.update(panOffset);
tiltLoop.update(tiltOffset);
pixy.setServos(panLoop.m_command, tiltLoop.m_command);
panOffset += panLoop.m_command - PIXY_RCS_CENTER_POS;
tiltOffset += tiltLoop.m_command - PIXY_RCS_CENTER_POS - PIXY_RCS_CENTER_POS/2 + PIXY_RCS_CENTER_POS/8;
rotateLoop.update(panOffset);
translateLoop.update(-tiltOffset);
if (translateLoop.m_command>MAX_TRANSLATE_VELOCITY)
translateLoop.m_command = MAX_TRANSLATE_VELOCITY;
left = -rotateLoop.m_command + translateLoop.m_command;
right = rotateLoop.m_command + translateLoop.m_command;
motors.setLeftSpeed(left);
motors.setRightSpeed(right);
block->print();
}


“block-> print ();” in bold is executed after all motor control operations are completed.

Then, the data value sent to the serial will draw the wrong position, not the position of the current block.

If you move the location of that statement(“block->print();”) right after “block = trackBlock (index);”, you will normally send the block’s current position data via serial.

Anyway, for the first time, I created a prototype of my robot’s wireless block viewer. =)
https://youtu.be/ClUXgTFT_Y4

thanks for reading!

-yuna

Great, glad you figured it out!

1 Like

Thanks to your continued answers. =)