<< return to Pixycam.com

Question avoid projects

Hi
I am working on a project to avoid things using Pixy Cam.
I wrote the code and implemented it, and I’m not sure it’s working.

Is it right to do it like code?

if((pixy.ccc.blocks[0].m_x>120)&&(pixy.ccc.blocks[0].m_x<190)) {left();}
if(((pixy.ccc.blocks[0].m_x<120) && (pixy.ccc.blocks[0].m_x>10)) or ((pixy.ccc.blocks[0].m_x>190))) {go();}
if((pixy.ccc.blocks[0].m_x>10)&&(pixy.ccc.blocks[0].m_x<190)) {right();}
if((pixy.ccc.blocks[0].m_x>120)&&(pixy.ccc.blocks[0].m_x<315)) {left();}
if(((pixy.ccc.blocks[0].m_x>10)&&(pixy.ccc.blocks[0].m_x<120))&& (pixy.ccc.blocks[0].m_x>190)) {go();}

else{stop();}}}

Hello,
I’m not sure what you’re asking — “right” has lots of meanings :slight_smile:

but one thing I notice – if you’re going to access the block array, you need to make sure that Pixy2 has detected something by putting it in an if statement, such as:

// grab blocks!
pixy.ccc.getBlocks();
  
if (pixy.ccc.numBlocks) {
  if((pixy.ccc.blocks[0].m_x&gt;120)&amp;&amp;(pixy.ccc.blocks[0].m_x&lt;190)) {left();}
   // ...
}

Here, the “if (pixy.ccc.numBlocks)” guarantees that there will be at least 1 block detected, and hence pixy.ccc.blocks[0] will contain valid data.

Edward