串行数据和多维数组 [英] Serial data and multidimensional arrays

查看:104
本文介绍了串行数据和多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在尝试解析来自arduino的一些串行数据. arduino正在倾泻一个角度和一个距离.我面临的一个问题是,arduino正在倾卸角度,然后倾卸一条新线,然后倾倒该距离,然后倾卸另一条新线.以这样的方式,腻子的输出如下所示:

0<-angle
12< ---距离
1
45
2
324
.
.
.
180
3
179
14
.
.
.
0
12并继续直到我关闭arduino

我想将这些数据放入一个数组,其中维1是位置,维2是距离.我已经读过,由于优化的多维度数组的使用不佳,使用单个昏暗数组的速度要快得多,但我不确定为什么.角度只能向后旋转180度,最大距离为400厘米.这来自在180度扫动伺服器上的Ping传感器.我可以使arduino将数据转储到一行并将字符串解析为两个值,但是我认为这可能比使它在来自串行端口的其他每行中存储值要慢.据我所知,串行数据将进入一个字节数组,作为SerialPort.read(buffer,0,1)的缓冲区,其中buffer是byte [].总结一下:

1.数据必须尽快处理
2.最终结果是一个多维数组或两个单个数组,或者对于每个天使值而言,都有一个对应的距离的任何地方.
3.天使数据将在0到180度之间摆动,但角度是可变的.

之后,我想将向量转换为x和y分量,并在位图上绘制点,其中每个像素代表一个厘米.就像雷达一样,每次通过时都会用新的视点更新图像.

我所要求的只是一种获取串行数据的方法,以便每隔一行将其放置到一个变量中,而将其余各行放置在另一个变量中.

Hey guys,
I''m trying to parse some serial data coming from the arduino. The arduino is dumping a angle and a distance. An issue im facing is that the arduino is dumping the angle, then a new line, then the distance, then another new line. Its in such a way that the output from putty looks like this:

0 <--angle
12 <---distance
1
45
2
324
.
.
.
180
3
179
14
.
.
.
0
12 and continues until i shut off the arduino

I want to put these data into an an array where dimension 1 is the position and dimension 2 is the distance. Ive read that using a single dim array is much faster due to the poorly optimized multidim array but I''m not sure why. The angle can only go to 180 and back, the distance has a max value of 400cm. This is coming from a ping sensor that is on a 180 degree sweeping servo. I can make the arduino dump the data into one line and parse out the string into two values but I think this might be slower than making it store values in every other line coming from the serial port. From what I know, the serial data will be coming into a byte array as the buffer for the SerialPort.read(buffer,0,1) where buffer is the byte[]. So to sum things up:

1. data must be processed as fast as possible
2. end result is a multi dim or two single arrays or whatever where for each angel value there is a corresponding distance.
3. the angel data will oscillate from 0 to 180 degrees and back but the distance is variable.

After that I want to convert the vectors into x and y components and plot the points on a bitmap where each pixel represents one centimeter. much like radar-where the image gets updated with new visual points every pass.

All im asking for is a way to grab serial data so that every other line is placed into one variable and the rest in another.

推荐答案

那怎么办? /> (这样您就可以优化单维数组)

What about this?
(this way you have an optimized single dimension array)

public struct ArduinoData
{
    public int Angle;
    public int Distance;
}

public const Max = 1000;  // Whatever

public ArduinoData[] arduinoData = new ArduinoData[Max];


这篇关于串行数据和多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆