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