Example #1
0
    def _log_data_log2(self, timestamp, data, logconf):
        """Callback froma the log API when data arrives"""
        msg = Temperature()
        # ToDo: it would be better to convert from timestamp to rospy time
        msg.header.stamp = rospy.Time.now()
        msg.header.frame_id = self.tf_prefix + "/base_link"
        # measured in degC
        msg.temperature = data["baro.temp"]
        self._pubTemp.publish(msg)

        # ToDo: it would be better to convert from timestamp to rospy time
        msg = MagneticField()
        msg.header.stamp = rospy.Time.now()
        msg.header.frame_id = self.tf_prefix + "/base_link"

        # measured in Tesla
        msg.magnetic_field.x = data["mag.x"]
        msg.magnetic_field.y = data["mag.y"]
        msg.magnetic_field.z = data["mag.z"]

        self._pubMag.publish(msg)

        msg = Float32()
        # hPa (=mbar)
        msg.data = data["baro.pressure"]
        self._pubPressure.publish(msg)

        # V
        msg.data = data["pm.vbat"]
        self._pubBattery.publish(msg)

        # Test
        msg.data = data["test.tval"]
        self._pubTest.publish(msg)
    def _log_data_log2(self, timestamp, data, logconf):
        """Callback froma the log API when data arrives"""
        msg = Temperature()
        # ToDo: it would be better to convert from timestamp to rospy time
        msg.header.stamp = rospy.Time.now()
        msg.header.frame_id = self.tf_prefix + "/base_link"
        # measured in degC
        msg.temperature = data["baro.temp"]
        self._pubTemp.publish(msg)

        # ToDo: it would be better to convert from timestamp to rospy time
        msg = MagneticField()
        msg.header.stamp = rospy.Time.now()
        msg.header.frame_id = self.tf_prefix + "/base_link"

        # measured in Tesla
        msg.magnetic_field.x = data["mag.x"]
        msg.magnetic_field.y = data["mag.y"]
        msg.magnetic_field.z = data["mag.z"]

        self._pubMag.publish(msg)

        msg = Float32()
        # hPa (=mbar)
        msg.data = data["baro.pressure"]
        self._pubPressure.publish(msg)

        # V
        msg.data = data["pm.vbat"]
        self._pubBattery.publish(msg)
    def publish_variables(self, event):
        t = rospy.get_time()
        for var in self._variables:
            pc_msg = PointCloud()
            pc_msg.header.stamp = rospy.Time.now()
            pc_msg.header.frame_id = 'world'
            for name in self._vehicle_pos:
                value = self._interpolate(var, self._vehicle_pos[name][0],
                                          self._vehicle_pos[name][1],
                                          self._vehicle_pos[name][2], t)
                # Updating the point cloud for this variable
                pc_msg.points.append(
                    Point32(self._vehicle_pos[name][0],
                            self._vehicle_pos[name][1],
                            self._vehicle_pos[name][2]))
                pc_msg.channels.append(ChannelFloat32())
                pc_msg.channels[-1].name = 'intensity'
                pc_msg.channels[-1].values.append(value)

                # Create the message objects
                if 'temperature' in var.lower():
                    msg = Temperature()
                    msg.header.stamp = rospy.Time.now()
                    msg.header.frame_id = '%s/base_link' % name
                    # TODO Read from the unit of temperature from NC file
                    # Converting to Celsius
                    msg.temperature = value - 273.15
                else:
                    msg = FloatStamped()
                    msg.header.stamp = rospy.Time.now()
                    msg.header.frame_id = '%s/base_link' % name
                    msg.data = value
                self._topics[name][var].publish(msg)
            self._pc_variables[var].publish(pc_msg)
        return True