params.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 #     _____
00004 #    /  _  \
00005 #   / _/ \  \
00006 #  / / \_/   \
00007 # /  \_/  _   \  ___  _    ___   ___   ____   ____   ___   _____  _   _
00008 # \  / \_/ \  / /  _\| |  | __| / _ \ | ┌┐ \ | ┌┐ \ / _ \ |_   _|| | | |
00009 #  \ \_/ \_/ /  | |  | |  | └─┐| |_| || └┘ / | └┘_/| |_| |  | |  | └─┘ |
00010 #   \  \_/  /   | |_ | |_ | ┌─┘|  _  || |\ \ | |   |  _  |  | |  | ┌─┐ |
00011 #    \_____/    \___/|___||___||_| |_||_| \_\|_|   |_| |_|  |_|  |_| |_|
00012 #            ROBOTICS™
00013 #
00014 #
00015 #  Copyright © 2012 Clearpath Robotics, Inc. 
00016 #  All Rights Reserved
00017 #  
00018 # Redistribution and use in source and binary forms, with or without
00019 # modification, are permitted provided that the following conditions are met:
00020 #     * Redistributions of source code must retain the above copyright
00021 #       notice, this list of conditions and the following disclaimer.
00022 #     * Redistributions in binary form must reproduce the above copyright
00023 #       notice, this list of conditions and the following disclaimer in the
00024 #       documentation and/or other materials provided with the distribution.
00025 #     * Neither the name of Clearpath Robotics, Inc. nor the
00026 #       names of its contributors may be used to endorse or promote products
00027 #       derived from this software without specific prior written permission.
00028 # 
00029 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00030 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00031 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00032 # DISCLAIMED. IN NO EVENT SHALL CLEARPATH ROBOTICS, INC. BE LIABLE FOR ANY
00033 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 #
00040 # Please send comments, questions, or patches to skynet@clearpathrobotics.com
00041 #
00042 
00043 # ROS
00044 import rospy
00045 import roslib.message
00046 import applanix_msgs.msg
00047 import applanix_msgs.srv 
00048 
00049 response_codes = dict([(val, name) for name, val in applanix_msgs.msg.Ack.__dict__.items() if name.startswith("RESPONSE_")])
00050 
00051 
00052 def main():
00053   rospy.init_node("applanix_params")
00054 
00055   gams_params = rospy.get_param('gams_params', None)
00056   if gams_params != None:
00057     req_msg = applanix_msgs.msg.GAMSParams()
00058     req_msg.antenna_separation = gams_params['antenna_separation']
00059     req_msg.baseline_vector.x = gams_params['baseline_vector']['x']
00060     req_msg.baseline_vector.y = gams_params['baseline_vector']['y']
00061     req_msg.baseline_vector.z = gams_params['baseline_vector']['z']
00062     req_msg.max_heading_error_rms = gams_params['max_heading_error_rms']
00063     call_applanix_service('gams',req_msg)
00064     rospy.loginfo("Configured GAMS params.")
00065 
00066   dmi_params = rospy.get_param('dmi_params', None)
00067   if dmi_params != None:
00068     req_msg = applanix_msgs.msg.AidingSensorParams()
00069     req_msg.dmi_scale_factor = dmi_params['dmi_scale_factor']
00070     req_msg.dmi_lever_arm.x = dmi_params['dmi_lever_arm']['x']
00071     req_msg.dmi_lever_arm.y = dmi_params['dmi_lever_arm']['y']
00072     req_msg.dmi_lever_arm.z = dmi_params['dmi_lever_arm']['z']
00073     call_applanix_service('aiding_sensors',req_msg)
00074     rospy.loginfo("Configured DMI params.")
00075 
00076   com_ports = rospy.get_param('com_ports', None) 
00077   if com_ports != None:
00078     req_msg = applanix_msgs.msg.COMPortSetup()
00079     for port_num, port_params in enumerate(com_ports):
00080       # 8N1 is pretty universal now; less need to parameterize it. 
00081       port_msg = applanix_msgs.msg.COMPortParams()
00082       port_msg.parity = port_msg.PARITY_NONE
00083       port_msg.data_stop = port_msg.DATA_8_STOP_1
00084       port_msg.flow = port_msg.FLOW_NONE
00085       port_msg.baud = getattr(port_msg, "BAUD_%s" % port_params['baud'])
00086       port_msg.input_select = getattr(port_msg, "INPUT_%s" % port_params['input'])
00087       port_msg.output_select = getattr(port_msg, "OUTPUT_%s" % port_params['output'])
00088       req_msg.port_mask |= 2 << port_num
00089       req_msg.ports.append(port_msg)
00090 
00091     call_applanix_service("com_port_setup", req_msg)
00092     rospy.loginfo("Configured COM ports.")
00093 
00094   base_gnss = rospy.get_param('base_gnss', None) 
00095   if base_gnss != None:
00096     for base_num, base_params in enumerate(base_gnss):
00097       base_msg = applanix_msgs.msg.BaseGNSSSetup()
00098       base_msg.base_gnss_input_type = getattr(base_msg, "TYPE_%s" % base_params['type'])        
00099       base_msg.datum = getattr(base_msg, "DATUM_%s" % base_params['datum'])     
00100       call_applanix_service("base_gnss_%i_setup" % (base_num + 1), base_msg)
00101       rospy.loginfo("Configured base GNSS #%i." % (base_num + 1))
00102 
00103   geometry = rospy.get_param('geometry', None) 
00104   if geometry != None:
00105     req_msg = applanix_msgs.msg.GeneralParams()
00106     for vector_name in ['imu_lever_arm', 'primary_gnss_lever_arm', 'imu_mounting_angle', 'ref_mounting_angle', 'aux_1_gnss_lever_arm', 'aux_2_gnss_lever_arm']:
00107       if vector_name in geometry:
00108         vector = geometry[vector_name]
00109         getattr(req_msg, vector_name).x = vector['x']
00110         getattr(req_msg, vector_name).y = vector['y']
00111         getattr(req_msg, vector_name).z = vector['z']
00112     req_msg.time_types = 0x1
00113     req_msg.distance_type = 1
00114     req_msg.autostart = 1 
00115     req_msg.multipath = 0  # LOW setting, do not change. 
00116     call_applanix_service('general', req_msg)
00117     rospy.loginfo("Configured geometry.")
00118 
00119 
00120   # Default rate of 10Hz
00121   rate = rospy.get_param('rate', 10)
00122   rospy.Subscriber("subscribed_groups", applanix_msgs.msg.Groups, groups_callback)
00123 
00124   # Delay setting the sensor override msg until we have received notice that Fine Align is active.
00125   sensor_overrides = rospy.get_param('sensor_overrides', None) 
00126   if sensor_overrides != None:
00127     override_msg = applanix_msgs.msg.AidingSensorIntegrationControl()
00128     for override_str in sensor_overrides:
00129       override_msg.override |= getattr(override_msg, "OVERRIDE_%s" % override_str)
00130     rospy.loginfo("Waiting on Fine Align before configuring sensor overrides.")
00131     proceed = [False]
00132     def _cb(msg):
00133       if msg.status_a & applanix_msgs.msg.GeneralStatus.STATUS_A_FINE_ALIGN_ACTIVE != 0:
00134         proceed[0] = True
00135     sub = rospy.Subscriber("status/general", applanix_msgs.msg.GeneralStatus, _cb)
00136     while not proceed[0]:
00137       rospy.sleep(1.)
00138     sub.unregister()
00139     call_applanix_service("aiding_sensor_integration", override_msg)
00140     rospy.loginfo("Configured sensor overrides.")
00141 
00142   rospy.spin()
00143  
00144 
00145 def call_applanix_service(name, req):
00146   service_defn = getattr(applanix_msgs.srv, "Set" + req.__class__.__name__)
00147   rospy.wait_for_service(name)
00148   ack = rospy.ServiceProxy(name, service_defn)(req).ack
00149   if ack.response_code != applanix_msgs.msg.Ack.RESPONSE_ACCEPTED:
00150     rospy.logwarn("Parameter change call to %s resulted in error code %d (%s)." %
00151                   (name, ack.response_code, response_codes[ack.response_code]))
00152   return ack
00153 
00154 
00155 def groups_callback(message):
00156   req_msg = applanix_msgs.msg.PortControl()
00157   req_msg.rate = rospy.get_param('rate', 10)
00158   groups = set(message.groups)
00159   groups.add(10)
00160   for group_num in groups:
00161     req_msg.groups.append(applanix_msgs.msg.OutputGroup(group=group_num))
00162   call_applanix_service("primary_data_port", req_msg)
00163   #print message.groups


applanix_bridge
Author(s): Mike Purvis
autogenerated on Thu Aug 27 2015 12:15:53