2 """ For more info on the documentation go to https://www.decawave.com/sites/default/files/dwm1001-api-guide.pdf 5 from dwm1001_systemDefinitions
import SYS_DEFS
7 __author__ = SYS_DEFS.AUTHOR
8 __version__ = SYS_DEFS.VERSION
9 __maintainer__ = SYS_DEFS.MAINTAINER
10 __email__ = SYS_DEFS.EMAIL
11 __status__ = SYS_DEFS.STATUS
14 import rospy, time, serial, os
15 from dwm1001_apiCommands
import DWM1001_API_COMMANDS
16 from dynamic_reconfigure.server
import Server
17 from localizer_dwm1001.cfg
import DWM1001_Tune_SerialConfig
18 from localizer_dwm1001.msg
import Anchor
19 from localizer_dwm1001.msg
import Tag
20 from localizer_dwm1001.srv
import Anchor_0
25 rospy.init_node(
'Localizer_DWM1001', anonymous=
False)
28 os.popen(
"sudo chmod 777 /dev/ttyACM0",
"w")
35 dynamicConfig_OPEN_PORT = {
"open_port":
False}
36 dynamicConfig_CLOSE_PORT = {
"close_port":
False}
37 dynamicConfig_SERIAL_PORT = {
"serial_port":
""}
40 serialPortDWM1001 = serial.Serial(
42 port = str(rospy.get_param(
'~serial_port_name')),
43 baudrate = int(rospy.get_param(
'~serial_baud_rate')),
44 parity=SYS_DEFS.parity,
45 stopbits=SYS_DEFS.stopbits,
46 bytesize=SYS_DEFS.bytesize
56 Initialize port and dwm1001 api 69 serialPortDWM1001.close()
73 serialPortDWM1001.open()
76 if(serialPortDWM1001.isOpen()):
77 rospy.loginfo(
"Port opened: "+ str(serialPortDWM1001.name) )
83 serialPortDWM1001.write(DWM1001_API_COMMANDS.LEC)
84 serialPortDWM1001.write(DWM1001_API_COMMANDS.SINGLE_ENTER)
85 rospy.loginfo(
"Reading DWM1001 coordinates")
87 rospy.loginfo(
"Can't open port: "+ str(serialPortDWM1001.name))
91 while not rospy.is_shutdown():
93 serialReadLine = serialPortDWM1001.read_until()
99 rospy.loginfo(
"Found index error in the network array!DO SOMETHING!")
103 except KeyboardInterrupt:
104 rospy.loginfo(
"Quitting DWM1001 Shell Mode and closing port, allow 1 second for UWB recovery")
105 serialPortDWM1001.write(DWM1001_API_COMMANDS.RESET)
106 serialPortDWM1001.write(DWM1001_API_COMMANDS.SINGLE_ENTER)
109 rospy.loginfo(
"Quitting, and sending reset command to dev board")
111 serialPortDWM1001.write(DWM1001_API_COMMANDS.RESET)
112 serialPortDWM1001.write(DWM1001_API_COMMANDS.SINGLE_ENTER)
114 if "reset" in serialReadLine:
115 rospy.loginfo(
"succesfully closed ")
116 serialPortDWM1001.close()
120 Split network data such us coordinates of anchor and tag, by comma ',' 122 :param dataFromUSB: Array from serial port containing all informations, tag xyz and anchor xyz 124 :returns: arrayFromUSBFormatted 128 arrayFromUSBFormatted = [x.strip()
for x
in dataFromUSB.strip().split(
',')]
130 return arrayFromUSBFormatted
134 Publish anchors and tag in topics using Tag and Anchor Object 136 :param networkDataArray: Array from serial port containing all informations, tag xyz and anchor xyz 143 for network
in networkDataArray:
148 temp_anchor_number = networkDataArray[networkDataArray.index(network)]
150 anchor = Anchor( str(networkDataArray[networkDataArray.index(network) + 1]),
151 float(networkDataArray[networkDataArray.index(network) + 2]),
152 float(networkDataArray[networkDataArray.index(network) + 3]),
153 float(networkDataArray[networkDataArray.index(network) + 4]),
154 float(networkDataArray[networkDataArray.index(network) + 5]))
158 pub_anchor = rospy.Publisher(
'/dwm1001/anchor'+str(temp_anchor_number[-1]), Anchor, queue_size=1)
159 pub_anchor.publish(anchor)
160 rospy.loginfo(
"Anchor: " 169 elif 'POS' in network:
172 tag = Tag(float(networkDataArray[networkDataArray.index(network) + 1]),
173 float(networkDataArray[networkDataArray.index(network) + 2]),
174 float(networkDataArray[networkDataArray.index(network) + 3]),)
177 pub_anchor = rospy.Publisher(
'/dwm1001/tag', Tag, queue_size=1)
178 pub_anchor.publish(tag)
180 rospy.loginfo(
"Tag: " 195 Update dynamic configuration of ROS 203 global dynamicConfig_SERIAL_PORT
208 dynamicConfig_CLOSE_PORT.update({
"close_port":
True})
210 dynamicConfig_OPEN_PORT.update({
"open_port" :
False})
212 dynamicConfigServer.update_configuration(dynamicConfig_OPEN_PORT)
213 dynamicConfigServer.update_configuration(dynamicConfig_CLOSE_PORT)
215 dynamicConfig_CLOSE_PORT.update({
"close_port":
False})
217 dynamicConfig_OPEN_PORT.update({
"open_port":
True})
219 dynamicConfig_SERIAL_PORT = {
"serial_port": str(serialPortDWM1001.name)}
221 dynamicConfigServer.update_configuration(dynamicConfig_OPEN_PORT)
222 dynamicConfigServer.update_configuration(dynamicConfig_OPEN_PORT)
223 dynamicConfigServer.update_configuration(dynamicConfig_CLOSE_PORT)
224 dynamicConfigServer.update_configuration(dynamicConfig_SERIAL_PORT)
228 Initialize dwm1001 api, by sending sending bytes 236 serialPortDWM1001.write(DWM1001_API_COMMANDS.RESET)
238 serialPortDWM1001.write(DWM1001_API_COMMANDS.SINGLE_ENTER)
241 serialPortDWM1001.write(DWM1001_API_COMMANDS.SINGLE_ENTER)
245 serialPortDWM1001.write(DWM1001_API_COMMANDS.SINGLE_ENTER)
250 Map each button from dynamic configuration gui with specific action 252 :param config: array contains value of the gui 257 global serialReadLine
261 if config[
"quit_dwm1001_api"]:
262 rospy.loginfo(
"Not implement it yet")
263 config[
"quit_dwm1001_api"] =
False 265 if config[
"close_port"]:
266 rospy.loginfo(
"Close port not implement it yet")
267 config[
"close_port"] =
False 270 rospy.loginfo(
"Not implement it yet")
271 config[
"exit"] =
False 280 if __name__ ==
'__main__':
284 except rospy.ROSInterruptException:
def initializeDWM1001API(self)
def splitByComma(self, dataFromUSB)
def updateDynamicConfiguration_SERIALPORT(self)
def callbackDynamicConfig(self, config, level)
def pubblishCoordinatesIntoTopics(self, networkDataArray)