Go to the documentation of this file.00001
00002
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
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
00036 sync_byte1=0xA5
00037 sync_byte2=0x5A
00038
00039
00040 measurement = 0x81
00041 devinfo = 0x4
00042 devhealth = 0x6
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
00058
00059 command_format = Struct("cmd_format",
00060 ULInt8("sync_byte"),
00061 ULInt8("cmd_flag")
00062 )
00063
00064
00065 response_header_format = Struct("header_format",
00066 ULInt8("sync_byte1"),
00067 ULInt8("sync_byte2"),
00068 BitStruct("response",
00069 BitField("response_size", 8),
00070 BitField("response_data", 22),
00071 BitField("response_mode",2),
00072 ),
00073 ULInt8("response_type"),
00074 )
00075
00076
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
00085 response_device_health_format = Struct("health_format",
00086 ULInt8("status"),
00087 ULInt16("error_code")
00088 )
00089
00090
00091 response_device_point_format = Struct("point_format",
00092
00093 BitStruct("quality",
00094 BitField("quality", 6),
00095 Flag("syncbit_inverse"),
00096 Flag("syncbit")),
00097
00098 ULInt16("angle_q6"),
00099 ULInt16("distance_q2")
00100 )
00101
00102
00103
00104 toHex = lambda x:"".join([hex(ord(c))[2:].zfill(2) for c in x]).upper()