<< return to Pixycam.com

X, y value problem in block

Hi.
Greetings again.
The question follows the last Bluetooth spp transmission topic.
I used ‘Processing’ to plot the position of the block in the frame.
The video below is the result.
first video is just ‘ccc_hello_world’ mode, second is ‘ccc_zumo_chase’ mode(but just pan-tilt state).
viewer of ‘ccc_hello_world’
viewer of ‘ccc_zumo_chase’

When Arduino runs the ‘ccc_hello_world.ino’ code, the x and y, width and height values(​​received through bluetooth serial communication) ​​are normal.
However, in the ‘ccc_zumo_chase’ mode, the x and y values seem to be different compared to the positions drawn in the pixyMon.

Looking at the value of serial communication, the x value is generally 0, and the y value seems to reflect the angle value of the pan servomotor.

Below is what I fixed a bit in Pixy2CCC.h.
(The Arduino code only includes sending the command value to the serial in the example provided.)


void print()
{
int i, j;
char buf[128], sig[6], d;
bool flag;
if (m_signature>CCC_MAX_SIGNATURE) // color code! (CC)
{
// convert signature number to an octal string
for (i=12, j=0, flag=false; i>=0; i-=3)
{
d = (m_signature>>i)&0x07;
if (d>0 && !flag)
flag = true;
if (flag)
sig[j++] = d + ‘0’;
}
sig[j] = ‘\0’;
sprintf(buf, “sig:%s\n(%d:decimal)\nx:%d\ny:%d\nwidth:%d\nheight:%d\nangle:%d\nindex:%d\nage:%d”, sig, m_signature, m_x, m_y, m_width, m_height, m_angle, m_index, m_age);
}
else{ // regular block. Note, angle is always zero, so no need to print
sprintf(buf, “sig:%d\nx:%d\ny:%d\nwidth:%d\nheight:%d\nindex:%d\nage:%d”, m_signature, m_x, m_y, m_width, m_height, m_index, m_age);
}
Serial.println(buf);
}

uint16_t m_signature;
uint16_t m_x;
uint16_t m_y;
uint16_t m_width;
uint16_t m_height;
int16_t m_angle;
uint8_t m_index;
uint8_t m_age;
};


Below is my processing code.

import processing.serial.*;
import java.util.List;
import java.util.ArrayList;

Serial myPort; // Create object from Serial class
String message;
int panOffset,tiltOffset;
int panLoop_command,tiltLoop_command;
int rotateLoop_command,translateLoop_command;
int leftSpeed,rightSpeed;
int sig,x,y,wid,hei,index,age;
List dataList=new ArrayList();

void setup()
{
dataList.add(“panOffset”);
dataList.add(“tiltOffset”);
dataList.add(“panLoop.m_command”);
dataList.add(“tiltLoop.m_command”);
dataList.add(“rotateLoop.m_command”);
dataList.add(“translateLoop.m_command”);
dataList.add(“leftSpeed”);
dataList.add(“rightSpeed”);
dataList.add(“sig”);
dataList.add(“x”);
dataList.add(“y”);
dataList.add(“width”);
dataList.add(“height”);
dataList.add(“index”);
dataList.add(“age”);

//size(316,208); //in ‘ccc_hello_world’ mode, that size operate correctly.
size(632,832); //316 * 2, 208 * 4 -->Increased frame size due to strange x, y values

String portName = Serial.list()[1];
println(portName);
myPort = new Serial(this, portName, 115200);
}

void draw()
{
processMessages();
updateUI();
}

void processMessages(){
while(myPort.available()>0){
message=myPort.readStringUntil(’\n’);
if(message!=null){
message=message.substring(0,(message.length()-1));
if(message.contains(":")){
String value;
int label=0;
String [] data=message.split(":");
value=data[1].trim();
label=dataList.indexOf(data[0]);
switch(label){
case 0:
panOffset=Integer.parseInt(value);
break;
case 1:
tiltOffset=Integer.parseInt(value);
break;
case 2:
panLoop_command=Integer.parseInt(value);
break;
case 3:
tiltLoop_command=Integer.parseInt(value);
break;
case 4:
rotateLoop_command=Integer.parseInt(value);
break;
case 5:
translateLoop_command=Integer.parseInt(value);
break;
case 6:
leftSpeed=Integer.parseInt(value);
break;
case 7:
rightSpeed=Integer.parseInt(value);
break;
case 8:
sig=Integer.parseInt(value);
break;
case 9:
println(“x:”+value);
x=Integer.parseInt(value);
break;
case 10:
println(“y:”+value);
y=Integer.parseInt(value);
break;
case 11:
println(“width:”+value);
wid=Integer.parseInt(value);
break;
case 12:
println(“height:”+value);
hei=Integer.parseInt(value);
break;
case 13:
index=Integer.parseInt(value);
break;
case 14:
age=Integer.parseInt(value);
break;
default:
break;
}
}
else{
print(message);
} //end of if(contains(":"))
} //end of if(message!=null)
} //end of while
}

void updateUI(){
background(255);
fill(192);
rectMode(CENTER);

//I thought the reason why the x value was still 0 was that the center of the frame was from the origin.
rect(x+(float)632/2,y+(float)416/2,wid,hei);
// rect(x,y,wid,hei); //in ‘ccc_hello_world’ mode, that code operate correctly.
}


I wonder why the y value reflects the angle of the pan servomotor.
Compared to the pixyMon, the width and height values ​​of the blocks are also different.
I’ve read CCC-related topics in the pixy2 Wiki’s documentation, but I can’t find anything wrong.

Can you find out what I did wrong?

Thanks for reading.

-yuna

Sorry, I’m very confused about what you’d like from us. Could you restate your question?

So, when I draw the screen with the x, y, height, and width values ​​of the ‘block’ structure, when the program in Arduino is ‘ccc_hello_world.ino’, it is drawn the same as in pixyMon. However, when Arduino’s code is ‘ccc_zumo_chase.ino’, it is strangely drawn (as you can see in the link’s video). It does not draw the correct position of the detected block. In the example code provided, little has changed(serial message). I don’t know why this is happening.

++
When uploading ‘ccc_pantilt.ino’ and drawing, the block is drawn normally. (video : ‘ccc_pantilt’ mode view
In contrast to the ‘zumo_chase’ mode.

The difference in code seems to be the following:
in ‘ccc_zumo_chase.ino’


Block *trackBlock(uint8_t index)
{
uint8_t i;

for (i=0; i<pixy.ccc.numBlocks; i++)
{
if (index==pixy.ccc.blocks[i].m_index)
return &pixy.ccc.blocks[i];
}

return NULL;
}

void loop()
{
static int16_t index = -1;
int32_t panOffset, tiltOffset, headingOffset, left, right;
Block *block=NULL;

pixy.ccc.getBlocks();

/* …skip… */

if (index>=0)
block = trackBlock(index);

/* …skip… */

if (block)
{

/* …skip… */

block->print();
} else{

/* …skip… */

}


in ‘ccc_pantilt.ino’


void loop()
{
static int i = 0;
int j;
char buf[64];
int32_t panOffset, tiltOffset;

pixy.ccc.getBlocks();

if (pixy.ccc.numBlocks){
i++;

//This for loop is what I added
for (i=0; i<pixy.ccc.numBlocks; i++)
{
pixy.ccc.blocks[i].print();
}

if (i%60==0)
  Serial.println(i);   

/* …skip …*/

}
else // no object detected, go into reset state
{

/* …skip …*/

}
}


My guess is that when the x and y values ​​of the block structure received returned by “trackBlock(index)” function in chase mode are printed, the values ​​change.

Sorry, could you send a video of the problem? All I can see is the video of it working normally.

I will say that you might try tweaking the Signature Tuning slider to get a better lock on your signature. instructions here: https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:some_tips_on_generating_color_signatures_2

Cheers,
Jesse

Oops, nevermind! Just saw your other post. Thanks for following up!

1 Like