本文整理汇总了Python中protocol.Protocol.decode方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.decode方法的具体用法?Python Protocol.decode怎么用?Python Protocol.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.decode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Speed
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode [as 别名]
class Speed(ChassisDev):
TYPE = 0x02
# 12 bytes data package format in struct
pack_pmt = "3f"
def __init__(self):
self.protocol = Protocol(self.TYPE, self.pack_pmt)
ChassisDev.__init__(self, "Speed",
pub_topic = "/speed_wheel",
pub_msg_class = Float32MultiArray,
pub_rate = 20)
self.speeds = Float32MultiArray()
self.speeds.data = [0,0,0]
ChassisDev.pub_data_update(self, self.speeds)
ChassisDev.start_pub(self)
def data_handler(self, bin_data_pack):
wheel0, wheel1, wheel2 = \
self.protocol.decode(bin_data_pack)
self.speeds.data = [wheel0, wheel1, wheel2]
ChassisDev.pub_data_update(self, self.speeds)
示例2: Odom
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode [as 别名]
class Odom(ChassisDev):
TYPE = 0x01
# 12 bytes data package format in struct
pack_pmt = "3i"
def __init__(self):
self.protocol = Protocol(self.TYPE, self.pack_pmt)
ChassisDev.__init__(self, "Chassis",
pub_topic = "/encoder_cnts",
pub_msg_class = Float32MultiArray,
pub_rate = 20)
self.counters = Float32MultiArray()
ChassisDev.start_pub(self)
def data_handler(self, bin_data_pack):
counter0, counter1, counter2 = \
self.protocol.decode(bin_data_pack)
self.counters.data = [counter0, counter1, counter2]
ChassisDev.pub_data_update(self, self.counters)
示例3: Battery
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode [as 别名]
class Battery(ChassisDev):
TYPE = 0x03
# 12 bytes data package format in struct
pack_pmt = "2f2H"
def __init__(self):
self.protocol = Protocol(self.TYPE, self.pack_pmt)
ChassisDev.__init__(self, "smart_battery",
pub_topic = "smart_battery",
pub_msg_class = SmartBatteryStatus)
self.battery_status = SmartBatteryStatus()
ChassisDev.start_pub(self)
def data_handler(self, bin_data_pack):
try:
voltage, rate, _,_ = \
self.protocol.decode(bin_data_pack)
except e:
print e
return
self.battery_status.voltage = voltage
self.battery_status.rate = rate
self.battery_status.charge_state = 0
if voltage > 2000:
self.battery_status.percentage = 100 - (2520 - voltage)/4
else:
self.battery_status.percentage = 100 - (1260 - voltage)/1.6
ChassisDev.pub_data_update(self, self.battery_status)
示例4: MPU
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode [as 别名]
class MPU(ChassisDev):
TYPE = 0x04
# 12 bytes data package format in struct
pack_pmt = "3f"
TYPE_ACC = 0x00
TYPE_GYRO = 0x01
def __init__(self):
self.protocol = Protocol(self.TYPE, self.pack_pmt)
ChassisDev.__init__(self, "chassis", pub_topic="imu/data_raw", pub_rate=10, pub_msg_class=Imu)
self.imu = Imu()
ChassisDev.start_pub(self)
def data_handler(self, bin_data_pack):
if struct.unpack("20B", bin_data_pack)[2] == self.TYPE_GYRO:
try:
x, y, z = self.protocol.decode(bin_data_pack)
self.imu.angular_velocity.x = x
self.imu.angular_velocity.y = y
self.imu.angular_velocity.z = z
self.imu.header.frame_id = "base_footprint"
self.imu.header.stamp = rospy.Time.now()
ChassisDev.pub_data_update(self, self.imu)
except Exception as e:
print e
return
else:
try:
x, y, z = self.protocol.decode(bin_data_pack)
self.imu.linear_acceleration.x = x
self.imu.linear_acceleration.y = y
self.imu.linear_acceleration.z = z
except e:
print e
return