示例#1
0
    def bar30callback(self, data):
        # Check if message id is valid (I'm using SCALED_PRESSURE
        # and not SCALED_PRESSURE2)
        if data.msgid == 137:
            # Transform the payload in a python string
            p = pack("QQ", *data.payload64)
            # Transform the string in valid values
            # https://docs.python.org/2/library/struct.html
            time_boot_ms, press_abs, press_diff, temperature = unpack(
                "Iffhxx", p)

            fp = FluidPressure()
            fp.header = data.header
            fp.fluid_pressure = press_abs
            fp.variance = 2.794

            self.abs_pressure = press_abs * 100  # convert hPa to Pa
            self.prespub.publish(fp)
示例#2
0
def publishBarometerData():
    airPressurePub = rospy.Publisher('air_pressure',
                                     FluidPressure,
                                     queue_size=10)
    temperaturePub = rospy.Publisher('barometer_temperature',
                                     Temperature,
                                     queue_size=10)
    rospy.init_node('barometer_publisher', anonymous=True)

    # Set update rate, in Hz
    rate = rospy.Rate(10)

    while not rospy.is_shutdown():
        # Pressure
        baro.refreshPressure()
        time.sleep(0.1)
        baro.readPressure()

        # Temperature
        baro.refreshTemperature()
        time.sleep(0.1)
        baro.readTemperature()

        # Process the data
        baro.calculatePressureAndTemperature()

        # Generate Header
        header = Header()
        header.stamp = rospy.Time.now()

        # Generate Message (Temperature)
        temperatureMsg = Temperature()
        temperatureMsg.header = header
        temperatureMsg.temperature = baro.TEMP
        temperaturePub.publish(temperatureMsg)

        # Generate message and publish (Pressure)
        airPressureMsg = FluidPressure()
        airPressureMsg.header = header
        airPressureMsg.fluid_pressure = baro.PRES * 100
        airPressurePub.publish(airPressureMsg)

        # Sleep
        rate.sleep()
示例#3
0
    def spin_once(self):
        def baroPressureToHeight(value):
            c1 = 44330.0
            c2 = 9.869232667160128300024673081668e-6
            c3 = 0.1901975534856
            intermediate = 1 - math.pow(c2 * value, c3)
            height = c1 * intermediate
            return height

        # get data
        data = self.mt.read_measurement()
        # common header
        h = Header()
        h.stamp = rospy.Time.now()
        h.frame_id = self.frame_id

        # get data (None if not present)
        temp_data = data.get('Temperature')  # float
        orient_data = data.get('Orientation Data')
        velocity_data = data.get('Velocity')
        position_data = data.get('Latlon')
        altitude_data = data.get('Altitude')
        acc_data = data.get('Acceleration')
        gyr_data = data.get('Angular Velocity')
        mag_data = data.get('Magnetic')
        pressure_data = data.get('Pressure')
        time_data = data.get('Timestamp')
        gnss_data = data.get('GNSS')

        # debug the data from the sensor
        # print(data)
        # print("\n")

        # create messages and default values
        "Temp message"
        temp_msg = Temperature()
        pub_temp = False
        "Imu message supported with Modes 1 & 2"
        imuraw_msg = Imu()
        pub_imuraw = False
        imuins_msg = Imu()
        pub_imuins = False
        "SensorSample message supported with Mode 2"
        ss_msg = sensorSample()
        pub_ss = False
        "Mag message supported with Modes 1 & 2"
        mag_msg = Vector3Stamped()
        pub_mag = False
        "Baro in meters"
        baro_msg = FluidPressure()
        height_msg = baroSample()
        pub_baro = False
        "GNSS message supported only with MTi-G-7xx devices"
        "Valid only for modes 1 and 2"
        gnssPvt_msg = gnssSample()
        gps1_msg = NavSatFix()
        gps2_msg = GPSFix()
        pub_gnssPvt = False
        gnssSatinfo_msg = GPSStatus()
        pub_gnssSatinfo = False
        # All filter related outputs
        "Supported in mode 3"
        ori_msg = orientationEstimate()
        pub_ori = False
        "Supported in mode 3 for MTi-G-7xx devices"
        vel_msg = velocityEstimate()
        pub_vel = False
        "Supported in mode 3 for MTi-G-7xx devices"
        pos_msg = positionEstimate()
        pub_pos = False

        # first getting the sampleTimeFine
        # note if we are not using ros time, the we should replace the header
        # with the time supplied by the GNSS unit
        if time_data and not self.use_rostime:
            time = time_data['SampleTimeFine']
            h.stamp.secs = 100e-6 * time
            h.stamp.nsecs = 1e5 * time - 1e9 * math.floor(h.stamp.secs)

        # temp data
        if temp_data:
            temp_msg.temperature = temp_data['Temp']
            pub_temp = True

        # acceleration data
        if acc_data:
            if 'accX' in acc_data:  # found acceleration
                pub_imuraw = True
                imuraw_msg.linear_acceleration.x = acc_data['accX']
                imuraw_msg.linear_acceleration.y = acc_data['accY']
                imuraw_msg.linear_acceleration.z = acc_data['accZ']
            if 'freeAccX' in acc_data:  # found free acceleration
                pub_imuins = True
                imuins_msg.linear_acceleration.x = acc_data['freeAccX']
                imuins_msg.linear_acceleration.y = acc_data['freeAccY']
                imuins_msg.linear_acceleration.z = acc_data['freeAccZ']
            if 'Delta v.x' in acc_data:  # found delta-v's
                pub_ss = True
                ss_msg.internal.imu.dv.x = acc_data['Delta v.x']
                ss_msg.internal.imu.dv.y = acc_data['Delta v.y']
                ss_msg.internal.imu.dv.z = acc_data['Delta v.z']
            #else:
            #	raise MTException("Unsupported message in XDI_AccelerationGroup.")

        # gyro data
        if gyr_data:
            if 'gyrX' in gyr_data:  # found rate of turn
                pub_imuraw = True
                imuraw_msg.angular_velocity.x = gyr_data['gyrX']
                imuraw_msg.angular_velocity.y = gyr_data['gyrY']
                imuraw_msg.angular_velocity.z = gyr_data['gyrZ']
                # note we do not force publishing the INS if we do not use the free acceleration
                imuins_msg.angular_velocity.x = gyr_data['gyrX']
                imuins_msg.angular_velocity.y = gyr_data['gyrY']
                imuins_msg.angular_velocity.z = gyr_data['gyrZ']
            if 'Delta q0' in gyr_data:  # found delta-q's
                pub_ss = True
                ss_msg.internal.imu.dq.w = gyr_data['Delta q0']
                ss_msg.internal.imu.dq.x = gyr_data['Delta q1']
                ss_msg.internal.imu.dq.y = gyr_data['Delta q2']
                ss_msg.internal.imu.dq.z = gyr_data['Delta q3']
            #else:
            #	raise MTException("Unsupported message in XDI_AngularVelocityGroup.")

        # magfield
        if mag_data:
            ss_msg.internal.mag.x = mag_msg.vector.x = mag_data['magX']
            ss_msg.internal.mag.y = mag_msg.vector.y = mag_data['magY']
            ss_msg.internal.mag.z = mag_msg.vector.z = mag_data['magZ']
            pub_mag = True

        if pressure_data:
            pub_baro = True
            baro_msg.fluid_pressure = pressure_data['Pressure']
            height = baroPressureToHeight(pressure_data['Pressure'])
            height_msg.height = ss_msg.internal.baro.height = height

        # gps fix message
        if gnss_data and 'lat' in gnss_data:
            pub_gnssPvt = True
            # A "3" means that the MTi-G is using the GPS data.
            # A "1" means that the MTi-G was using GPS data and is now coasting/dead-reckoning the
            # 	position based on the inertial sensors (the MTi-G is not using GPS data in this mode).
            # 	This is done for 45 seconds, before the MTi-G Mode drops to "0".
            # A "0" means that the MTi-G doesn't use GPS data and also that it
            # 	doesn't output position based on the inertial sensors.
            if gnss_data['fix'] < 2:
                gnssSatinfo_msg.status = NavSatStatus.STATUS_NO_FIX  # no fix
                gps1_msg.status.status = NavSatStatus.STATUS_NO_FIX  # no fix
                gps1_msg.status.service = 0
            else:
                gnssSatinfo_msg.status = NavSatStatus.STATUS_FIX  # unaugmented
                gps1_msg.status.status = NavSatStatus.STATUS_FIX  # unaugmented
                gps1_msg.status.service = NavSatStatus.SERVICE_GPS
            # lat lon alt
            gps1_msg.latitude = gnss_data['lat']
            gps1_msg.longitude = gnss_data['lon']
            gps1_msg.altitude = gnss_data['hEll']
            # covariances
            gps1_msg.position_covariance[0] = math.pow(gnss_data['horzAcc'], 2)
            gps1_msg.position_covariance[4] = math.pow(gnss_data['horzAcc'], 2)
            gps1_msg.position_covariance[8] = math.pow(gnss_data['vertAcc'], 2)
            gps1_msg.position_covariance_type = NavSatFix.COVARIANCE_TYPE_DIAGONAL_KNOWN
            # custom message
            gnssPvt_msg.itow = gnss_data['iTOW']
            gnssPvt_msg.fix = gnss_data['fix']
            gnssPvt_msg.latitude = gnss_data['lat']
            gnssPvt_msg.longitude = gnss_data['lon']
            gnssPvt_msg.hEll = gnss_data['hEll']
            gnssPvt_msg.hMsl = gnss_data['hMsl']
            gnssPvt_msg.vel.x = gnss_data['velE']
            gnssPvt_msg.vel.y = gnss_data['velN']
            gnssPvt_msg.vel.z = gnss_data['velD']
            gnssPvt_msg.hAcc = gnss_data['horzAcc']
            gnssPvt_msg.vAcc = gnss_data['vertAcc']
            gnssPvt_msg.sAcc = gnss_data['speedAcc']
            gnssPvt_msg.pDop = gnss_data['PDOP']
            gnssPvt_msg.hDop = gnss_data['HDOP']
            gnssPvt_msg.vDop = gnss_data['VDOP']
            gnssPvt_msg.numSat = gnss_data['nSat']
            gnssPvt_msg.heading = gnss_data['heading']
            gnssPvt_msg.headingAcc = gnss_data['headingAcc']

        if orient_data:
            if 'Q0' in orient_data:
                pub_imuraw = True
                imuraw_msg.orientation.w = orient_data['Q0']
                imuraw_msg.orientation.x = orient_data['Q1']
                imuraw_msg.orientation.y = orient_data['Q2']
                imuraw_msg.orientation.z = orient_data['Q3']
                pub_imuins = True
                imuins_msg.orientation.w = orient_data['Q0']
                imuins_msg.orientation.x = orient_data['Q1']
                imuins_msg.orientation.y = orient_data['Q2']
                imuins_msg.orientation.z = orient_data['Q3']
            elif 'Roll' in orient_data:
                pub_ori = True
                ori_msg.roll = orient_data['Roll']
                ori_msg.pitch = orient_data['Pitch']
                ori_msg.yaw = orient_data['Yaw']
            else:
                raise MTException(
                    'Unsupported message in XDI_OrientationGroup')

        if velocity_data:
            pub_vel = True
            vel_msg.velE = velocity_data['velX']
            vel_msg.velN = velocity_data['velY']
            vel_msg.velU = velocity_data['velZ']

        if position_data:
            pub_pos = True
            pos_msg.latitude = position_data['lat']
            pos_msg.longitude = position_data['lon']

        if altitude_data:
            pub_pos = True
            tempData = altitude_data['ellipsoid']
            pos_msg.hEll = tempData[0]

        # publish available information
        if pub_imuraw:
            imuraw_msg.header = h
            self.imuraw_pub.publish(imuraw_msg)
        if pub_imuins:
            imuins_msg.header = h
            self.imuins_pub.publish(imuins_msg)
        if pub_mag:
            mag_msg.header = h
            self.mag_pub.publish(mag_msg)
        if pub_temp:
            temp_msg.header = h
            self.temp_pub.publish(temp_msg)
        if pub_ss:
            ss_msg.header = h
            self.ss_pub.publish(ss_msg)
        if pub_baro:
            baro_msg.header = h
            height_msg.header = h
            self.baro_pub.publish(baro_msg)
            self.height_pub.publish(height_msg)
        if pub_gnssPvt:
            gnssPvt_msg.header = h
            gps1_msg.header = h
            self.gnssPvt_pub.publish(gnssPvt_msg)
            self.gps1_pub.publish(gps1_msg)
        #if pub_gnssSatinfo:
        #	gnssSatinfo_msg.header = h
        #	self.gnssSatinfo_pub.publish(gnssSatinfo_msg)
        if pub_ori:
            ori_msg.header = h
            self.ori_pub.publish(ori_msg)
        if pub_vel:
            vel_msg.header = h
            self.vel_pub.publish(vel_msg)
        if pub_pos:
            pos_msg.header = h
            self.pos_pub.publish(pos_msg)