reference.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding:utf-8 -*-
00003 """ 
00004 
00005 this file base on rplidar protocol interface
00006 
00007 Copyright (c) 2015 Xu Zhihao (Howe).  All rights reserved.
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 
00011 This programm is tested on kuboki base turtlebot. 
00012 
00013 """
00014 from construct import *
00015 
00016 
00017 # cmds
00018 #无应答
00019 stop=0x25#离开扫描采样模式,进入空闲状态
00020 reset=0x40#测距核心软重启
00021 
00022 #多次应答
00023 force_scan=0x21#请求进入扫描采样状态,强制数据输出
00024 scan=0x20#请求进入扫描采样状态
00025 
00026 
00027 #单次应答
00028 get_device_info=0x50#获取设备序列号等信息
00029 get_device_health=0x52#获取设备健康状态
00030 
00031 #标识位
00032 sync_byte=0xA5#报头字节
00033 flag_has_pay_load=0x80#结尾字节
00034 
00035 #response
00036 sync_byte1=0xA5#返回报头字节
00037 sync_byte2=0x5A#返回报头字节
00038 
00039 #返回值类型的字节
00040 measurement = 0x81#当请求为0x02/0x21时的返回值的尾字节
00041 devinfo = 0x4#当请求为0x50时的返回值的尾字节
00042 devhealth = 0x6#当请求为0x52时的返回值的尾字节
00043 
00044 #设备健康状态的返回值
00045 status_ok = 0x0
00046 status_warning = 0x1
00047 status_error = 0x2
00048 
00049 #扫描模型
00050 SINGLE = 0x0
00051 MULTI = 0x1
00052 UNDEFINED_f=0x2
00053 UNDEFINED_s=0x3
00054 
00055 angle_shift=1
00056 
00057 # struct
00058 # 命令格式
00059 command_format = Struct("cmd_format",
00060  ULInt8("sync_byte"), # must be A5
00061  ULInt8("cmd_flag") # CMD
00062 )
00063 
00064 #返回报头文件格式
00065 response_header_format = Struct("header_format",
00066  ULInt8("sync_byte1"), # must be A5
00067  ULInt8("sync_byte2"), # must be 5A
00068  BitStruct("response",
00069   BitField("response_size", 8),
00070   BitField("response_data", 22),
00071   BitField("response_mode",2),
00072   ),
00073  ULInt8("response_type"), # # to determine which kind of response it is
00074 )
00075 
00076 # 返回硬件参数格式 (20 bytes)
00077 response_device_info_format = Struct("info_format",
00078  ULInt8("model"),
00079  ULInt16("firmware_version"),
00080  ULInt8("hardware_version"),
00081  String("serial_number", 16)
00082 )
00083 
00084 # 返回硬件状况格式 (3 bytes)
00085 response_device_health_format = Struct("health_format",
00086  ULInt8("status"),
00087  ULInt16("error_code")
00088 )
00089 
00090 # 返回单次扫描格式 (5 bytes)
00091 response_device_point_format = Struct("point_format",
00092 
00093  BitStruct("quality", 
00094   BitField("quality", 6),
00095   Flag("syncbit_inverse"),#扫描起始标志位的取反,始终有S̅ = ! S
00096   Flag("syncbit")),#扫描起始标志位,S=1 表示新的一圈 360 度扫描的开始
00097 
00098  ULInt16("angle_q6"),#check_bit:1;angle_q6:15;
00099  ULInt16("distance_q2")
00100 )
00101 
00102 
00103 # 2进制字节转16进制字符
00104 toHex = lambda x:"".join([hex(ord(c))[2:].zfill(2) for c in x]).upper()


rplidar_python
Author(s): DinnerHowe
autogenerated on Thu Apr 13 2017 02:56:29