【参赛作品】四旋翼地面站
错过了最佳的作品提交日期了。前段时间帮同学做电子设计大赛,做的就是四旋翼的竞赛题目。感觉收货颇丰的。
在DIY作品中,还是做自己的老本行吧,所以就写了一套四旋翼的地面站来参赛了。
这个地面站经历了好几个版本的。
也为大家提供了通信协议的。方便大家能够使用 。
只要是通过串口,就可以实现数据的发送和显示。
附带了 通信协议的
消息格式:*高度,pitch,roll,yaw,经度,纬度,rc1,rc2,rc3,rc4;
除经纬度之外,其他必须为整型,有bug还在测试中。roll角度为0-360°
消息:*1522,15,12,12,2.33666555,3.22555554,1500,1500,1500,1500;
为了方便调试,这里也做了一些修改的。
看了到调试界面了吗?
这个是演示视频的。看看效果的
http://v.youku.com/v_show/id_XNjQwODQyNjQ0.html
为了让更多的人了解一下这个东西,附上串口代码的:
void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int n =SP.BytesToRead;
byte[] buf = new byte;
(sender as SerialPort).Read(buf, 0, n);
//Array.Resize(ref buf, n);
// MessageBox.Show( String.Format("{0}{1}", BitConverter.ToString(buf), Environment.NewLine));
//MessageBox.Show(Encoding.Default.GetString(buf));
int m=0;
while (m != n)
{
if (buf == '*' )
{
msg_num = 0;
is_exit1 = 1;
}
else if (buf == '#')
{
msg_num = 0;
is_exit1 = 2;
}
if(buf == ';')
{
//msg_num = 0;
if (is_exit1 == 1)
{
is_exit2 = 1;
pcmsg = buf;
}
else
{
msg_num = 0;
is_exit1 = 0;
is_exit2 = 0;
pcmsg = null;
pcmsg = new byte;
return;
}
break;
}
pcmsg=buf;
m++;
msg_num++;
if (msg_num >= 399)
{
msg_num = 0;
is_exit1 = 0;
is_exit2 = 0;
pcmsg = null;
pcmsg = new byte;
return;
}
}
if (is_exit2 == 1 && is_exit1 == 2)
{
string recvstr = Encoding.Default.GetString(pcmsg);
RECV.Text = recvstr;
string mstr = recvstr.Substring(1, msg_num - 1);
msg.Text = mstr;
string str2 = mstr.Replace(",", "");
int strlen = mstr.Length - str2.Length + 1;
string[] s = mstr.Split(',');
if (strlen != 9)
{
is_exit2 = 0;
is_exit1 = 0;
pcmsg = null;
pcmsg = new byte;
return;
}
PP.Text =(( Convert.ToDouble(s))/100).ToString();
PI.Text = ((Convert.ToDouble(s)) / 100).ToString();
PD.Text = ((Convert.ToDouble(s)) / 100).ToString();
YP.Text = ((Convert.ToDouble(s)) / 100).ToString();
YI.Text = ((Convert.ToDouble(s)) / 100).ToString();
YD.Text = ((Convert.ToDouble(s)) / 100).ToString();
AP.Text = ((Convert.ToDouble(s)) / 100).ToString();
AI.Text = ((Convert.ToDouble(s)) / 100).ToString();
AD.Text = ((Convert.ToDouble(s)) / 100).ToString();
msg_num = 0;
is_exit1 = 0;
is_exit2 = 0;
}
if (is_exit2 == 1 && is_exit1==1)
{
string recvstr=Encoding.Default.GetString(pcmsg);
RECV.Text = recvstr;
string mstr =recvstr.Substring(1, msg_num-1);
msg.Text = mstr;
string str2= mstr.Replace(",","");
int strlen =mstr.Length- str2.Length+1;
string[] s = mstr.Split(',');
// MessageBox.Show(strlen.ToString());
if (strlen >= 10)
{
val.Text = s + Environment.NewLine + s + Environment.NewLine + s + Environment.NewLine + s + Environment.NewLine + s
+ Environment.NewLine + s + Environment.NewLine + s + Environment.NewLine + s + Environment.NewLine + s
+ Environment.NewLine + s;
}
if (strlen >= 21 || strlen < 19)
{
is_exit2 = 0;
is_exit1 = 0;
pcmsg = null;
pcmsg = new byte;
return;
}
//娑堟伅鏍煎紡锛?楂樺害锛宲itch锛宺oll锛寉aw锛岀粡搴︼紝绾害锛宺c1锛宺c2锛宺c3锛宺c4锛?
if(strlen >0)
if (reg.IsMatch(s) && s != ""&& s.Length <6 )
{
altimeterIndicator1.SetAlimeterParameters(Convert.ToInt16(s)%65535);
}
if (strlen > 2)
if (reg.IsMatch(s) && reg.IsMatch(s) && s != ""
&& s != "" &&s.Length< 4 && s.Length<4)
{
mpitch =-Convert.ToInt16(s);
mroll =-Convert.ToInt16(s);
attitudeIndicator1.SetAttitudeIndicatorParameters(-mpitch, mroll);
}
if (strlen > 3)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
int tyaw=0;
tyaw =Convert.ToInt16(s);;
tyaw = 180 - tyaw;
myaw = tyaw;
headingIndicator1.SetHeadingIndicatorParameters(tyaw);
}
if (strlen >2 )
if (reg.IsMatch(s) && reg.IsMatch(s) && reg.IsMatch(s)
&& s != "" && s != "" && s != "" )
{
bFI1.Altitude = Convert.ToInt16(s);
bFI1.Pitch = -Convert.ToInt16(s);
bFI1.Bank = mroll;//Convert.ToInt16(s);
bFI2.Altitude = Convert.ToInt16(s);
bFI2.Pitch =- Convert.ToInt16(s);
bFI2.Bank = mroll;//Convert.ToInt16(s);
}
if (strlen > 4)
{
wd.Text = s;
dwd.Text = s;
}
if (strlen > 5)
{
jd.Text = s;
djd.Text = s;
}
if (strlen > 6)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc1.Value = limit(Convert.ToInt16(s));
rc1l.Text = s;
}
if (strlen >7 )
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc2.Value = limit(Convert.ToInt16(s));
rc2l.Text = s;
}
if (strlen > 8)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc3.Value = limit(Convert.ToInt16(s));
rc3l.Text = s;
}
if (strlen >9 )
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc4.Value = limit(Convert.ToInt16(s));
rc4l.Text = s;
}
if (strlen > 10)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc5.Value = limit(Convert.ToInt16(s));
rc5l.Text = s;
}
if (strlen > 11)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc6.Value = limit(Convert.ToInt16(s));
rc6l.Text = s;
}
if (strlen > 12)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc7.Value = limit(Convert.ToInt16(s));
rc7l.Text = s;
}
if (strlen > 13)
if (reg.IsMatch(s) && s != "" && s.Length < 5)
{
rc8.Value = limit(Convert.ToInt16(s));
rc8l.Text = s;
}
if (strlen > 14)
pitchtext.Text = s;
if (strlen > 15)
rolltext.Text = s;
if (strlen > 16)
yawtext.Text = s;
if (strlen > 17)
alttext.Text = s;
if (strlen > 18)
mjd.Text = s;
if (strlen > 19)
mwd.Text = s;
is_exit2 = 0;
is_exit1 = 0;
pcmsg = null;
pcmsg = new byte;
}
}
{:1_12:}{:1_12:}厉害理工男{:1_23:}{:1_23:} 厉害!!! 厉害 支持什么飞控 cyb2688 发表于 2014-8-18 14:17 static/image/common/back.gif
厉害理工男
多谢支持 炸香机 发表于 2014-8-18 23:36 static/image/common/back.gif
厉害 支持什么飞控
支持四轴 china 发表于 2014-8-26 19:51 static/image/common/back.gif
支持四轴
支持所有四轴飞控? 能交流交流吗,最近我也再做这个。
页:
[1]