diff --git a/scripts/localize.py b/scripts/localize.py index 42a28ad..b04492c 100755 --- a/scripts/localize.py +++ b/scripts/localize.py @@ -68,16 +68,16 @@ def is_listed(anchors, id): def get_serial_data(): # ser.write('+') start = ser.read() - return ser.readline().strip('$\r\n').split(',') - # if start == '$': - # data_string = ser.readline().strip('\r\n').split(',') - # return data_string - # else: - # return None + # return ser.readline().strip('$\r\n').split(',') + if start == '$': + data_string = ser.readline().strip('\r\n').split(',') + return data_string + else: + return None if __name__ == '__main__': - rospy.init_node('lips') + rospy.init_node('ros_dwm1000') listener = tf.TransformListener() start_time = rospy.get_time() #create rosparameters @@ -104,15 +104,14 @@ def get_serial_data(): beacon_count = 0 while not rospy.is_shutdown(): - #just give some delay for serial - rospy.sleep(0.1) data_string = get_serial_data() - print data_string - if 'None' != data_string: - # print "hello" + # print data_string + if None != data_string: #check if current anchor has already been listed #check if the current range is within specified distance - if (not is_listed(anchors, data_string[0])) and (MIN_RANGE < float(data_string[1]) < MAX_RANGE): + # if (not is_listed(anchors, data_string[0])) and (MIN_RANGE < float(data_string[1]) < MAX_RANGE): + if MIN_RANGE < float(data_string[1]) < MAX_RANGE: + anchors.append(data_string[0]) ranges.append(data_string[1]) transforms.append(get_transform(data_string[0])) @@ -121,7 +120,6 @@ def get_serial_data(): #perform trilateration once enough anchors have been found if beacon_count == REQ_ANCHOR: #do trilateration - print transforms pos = get_tag_location(anchors,ranges,transforms) #broadcast the transform diff --git a/scripts/serialtest.py b/scripts/serialtest.py new file mode 100644 index 0000000..71bb051 --- /dev/null +++ b/scripts/serialtest.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +''' + Copyright (c) 2016, Juan Jimeno + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +''' + + +import serial + +def get_serial_data(): + # ser.write('+') + start = ser.read() + # return ser.readline().strip('$\r\n').split(',') + if start == '$': + data_string = ser.readline().strip('\r\n').split(',') + return data_string + else: + return None + +if __name__ == '__main__': + SERIAL_PORT = '/dev/ttyUSB0' + ser = serial.Serial(SERIAL_PORT, 115200) + ser.timeout = None + + ranges = [] + anchors = [] + transforms = [] + beacon_count = 0 + + while True: + data_string = get_serial_data() + print data_string