【原创】【捕食者】基于Processing的遥控器数据可视化

LittleQiang LittleQiang | 532 | 2015-03-10

本帖最后由 LittleQiang 于 2015-3-10 21:18 编辑



[postbg]2.jpg[/postbg]厂家发货你的速度能够快一点吗!!!

前几天发了一篇用Processing玩游戏的帖子,不过游戏还是没有写好,能力有限。
然后又想起自己用软件调试遥控器参数的软件,感觉挺好玩的,趁着元器件在路上,花了两个小时程序谢了出来!!


菜鸟一枚,没有学过Jave编程,只是看着processing的参考例程码出来的!!
不喜勿喷!!!

[code]//Date:2015/3/10
//Editor:LittleQiang in NCHU
//Version :1.0
//运行环境:Processing2.2.1

import processing.serial.*;

Serial myPort; //The serial port

String myString ; //Input string form serial port
int SerialFlag=0;

float min =364; //遥控器最小值
float max =1684; //遥控器最大值

float [] Buffer =new float[6];
float [] ch = new float [4];
float [] s =new float [2];

void setup()
{
size(1200,480);
frameRate(1000);
background(0);
smooth();

println(Serial.list());
myPort=new Serial(this,Serial.list()[0],115200); //打开串口,设置波特率为115200
myPort.bufferUntil('\n'); //从串口读数据直到遇到\n

}

void draw()
{
background(0);
if(SerialFlag==1) //不断轮寻看是否发生串口中断
Text();
}

void Text()
{
fill(#3833DB);//bule
textSize(32);
text("Robomasters",width/2-100,32);

textSize(16);
text("\nCH0 :"+ch[0]+"\n\nCH1 :"+ch[1]+"\n\nCH2 :"+ch[2]+"\n\nCH3 :"+ch[3]+"\n\nS1 :"+s[0]+"\n\nS2 :"+s[1],0,100); //显示各个通道的数据

for(int i=0,x=17;i<6;i++)
{
stroke(255);
fill(#F70724);
rect(110,112+i*3*x,200,16);
}

for(int i=0,x=17;i<6;i++)
{
stroke(255);
fill(#461CBC);
if(i<4)
rect(110,112+i*3*x,map(ch,min,max,0,200),16); //显示四个通道
if(i>=4)
rect(110,112+i*3*x,200.0/3*s[i-4],16); //两个开关

}
stroke(255);
fill(0);
rect(400,85,720,340);

stroke(255);
fill(#3B1AAA);
rect(470,155,200,200);

stroke(255);
fill(#3B1AAA);
rect(850,155,200,200);

stroke(#3B1AAA);
fill(#836D73);
ellipse(map(ch[2],min,max,480,660),map(ch[3],max,min,165,345),20,20); //拨杆
ellipse(map(ch[0],min,max,860,1040),map(ch[1],max,min,165,345),20,20); //拨杆

}



void serialEvent(Serial p)//via serial port get the inputStringData//串口中断
{

myString=p.readString();

if(myString !=null)
{
myString=trim(myString);//jump to the '\0',trim off any whitespace
String [] inputStringData=split(myString,',');//Convert the speed separated by a comma into individual values

for(int i=0;i<6;i++)
{
Buffer=float(inputStringData);
print("\t",Buffer);
}

//updata ch
for(int i=0;i<4;i++)
{
ch=Buffer; //更新通道数据
}

//
for(int i=0;i<2;i++)
{
s=Buffer[i+4]; //更新开关数据
}


println();
SerialFlag=1; //mark the serial flag
}
}[/code]


本来想发视频的但是视频只能用QuickTime播放



1.png





2.png





请问这篇文章对你有用吗?

【原创】【捕食者】基于Processing的遥控器数据可视化
所有评论
暂无更多
暂无更多
关于作者
LittleQiang
LittleQiang
0 关注Ta
0 文章
0 经验值
0 获赞

目录

评论