本文整理匯總了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