Monday, October 10, 2016

Raspberry Pi & Arch Linux - Day 13 - RawDataHandler


In this post, we will present the draft version of RawDataHandler.

Based on our design, all the physical devices is represented by a Component class and it is further wrapper in a ContinuousComponentWrapper class. The communication is always handled by a multiprocessing queue and the format is defined in each concrete component class. So it is very easy to come up with a RawDataHandler class that can handle all the data and messages from different component.


class RawDataHandler:
    def __init__(self, name=None, parser=None, record_size=100):
        assert name is not None and parser is not None
        self._name = name
        self._records     = []
        self._record_size = record_size
        self._parser = parser
        self._columns = [x[0] for x in self._parser]

    def update(self, msg):
        if len(self._records) == self._record_size:
            self._records.pop(0)

        # parse the msg
        record = []
        for attr, idx in self._parser:
            record.append(msg[idx])
        self._records.append(record)
    

    @property
    def data(self):
        df = pd.DataFrame(self._records, columns=self._columns)
        df['param_name'] = self._name
        return df

The most important parameter is the parser. It tells the handler how to extract information of different field from the message.

Now we have all the pieces ready and we can perform the first test of our small ultrasonic radar.

Here is the setup of the environment: we put one piece of paper in front of the radar and it forms a V-shape.





Here is the data generated by the distance sensor:



We do see a V-shape here (well...); however for some reasons, there is a gap at degree = -10. There might be two potential explanation for this phenomenon. The first one is the reflection, due the shape of the paper it is possible that the ultrasonic wave may propagate following the red line in the image. In this case, the path consists of three segments instead of two. Another possible reason is the fact that when the sensor sends and receives the signal, it is also spinning. In other words, between the time it sends the signal and it receives the signal, it will make a slight move and point to a different direction. Though this movement is relatively small because the speedo of motor is largely smaller than the speed of sound, it case it points to the corner of the V shape, the distance measured can be quite sensitive to the angle.




As we can see in the fig-1, on the left side the points lie on the a straight line as expected while on the right part we see some irregularity. I think this irregularity can be partly explained by the curvature of the paper.




Video time ^_^




--END--

No comments:

Post a Comment