codes.py
Go to the documentation of this file.
00001 #! /usr/bin/env python -m
00002 # -*- coding: utf-8 -*-
00003 #     _____
00004 #    /  _  \
00005 #   / _/ \  \
00006 #  / / \_/   \
00007 # /  \_/  _   \  ___  _    ___   ___   ____   ____   ___   _____  _   _
00008 # \  / \_/ \  / /  _\| |  |  _| / _ \ |  _ \ |  _ \ / _ \ |_   _|| | | |
00009 #  \ \_/ \_/ /  | |  | |  | └─┐| |_| || |/ / | |/ /| |_| |  | |  | └─┘ |
00010 #   \  \_/  /   | |_ | |_ | ┌_┘|  _  ||  _ \ |  _/ |  _  |  | |  | ┌─┐ |
00011 #    \_____/    \___/|___||___||_| |_||_| \_\|_|   |_| |_|  |_|  |_| |_|
00012 #            ROBOTICS™
00013 #
00014 #  File: codes.py
00015 #  Desc: Horizon Message Codes
00016 #  
00017 #  Copyright © 2010 Clearpath Robotics, Inc. 
00018 #  All Rights Reserved
00019 # 
00020 #  Redistribution and use in source and binary forms, with or without
00021 #  modification, are permitted provided that the following conditions are met:
00022 #      * Redistributions of source code must retain the above copyright
00023 #        notice, this list of conditions and the following disclaimer.
00024 #      * Redistributions in binary form must reproduce the above copyright
00025 #        notice, this list of conditions and the following disclaimer in the
00026 #        documentation and/or other materials provided with the distribution.
00027 #      * Neither the name of Clearpath Robotics, Inc. nor the
00028 #        names of its contributors may be used to endorse or promote products
00029 #        derived from this software without specific prior written permission.
00030 # 
00031 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00032 #  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00033 #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00034 #  ARE DISCLAIMED. IN NO EVENT SHALL CLEARPATH ROBOTICS, INC. BE LIABLE FOR ANY
00035 #  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00036 #  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00037 #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00038 #  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00039 #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00040 #  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041 #
00042 #  Please send comments, questions, or patches to code@clearpathrobotics.com
00043 #
00044 
00045 
00046 from . import payloads         # Horizon Protocol Message Payload Definitions
00047 
00048 from collections import namedtuple
00049 
00050 
00051 __version__  = "1.0"
00052 __revision__ = "$Revision: 916 $"
00053 
00054 VERSION_BYTE = 0x00
00055 
00056 SET = 0x01
00057 REQUEST = 0x02
00058 
00059 class Code:
00060     def __init__(self, base_code, capability, data_payload_cls, request_payload_cls=None):
00061         self.base_code = base_code
00062         self.capability = capability
00063         self.data_payload = data_payload_cls
00064         if request_payload_cls:
00065             # Has own request class
00066             self.request_payload = request_payload_cls
00067         else:
00068             # Use fallback subscribe request
00069             self.request_payload = payloads.Subscribe
00070 
00071     def set(self):
00072         if self.capability & SET: return self.base_code
00073 
00074     def request(self):
00075         if self.capability & REQUEST: return self.base_code + 0x4000
00076 
00077     def data(self):
00078         if self.capability & REQUEST: return self.base_code + 0x8000
00079 
00080 codes = {}
00081 names = {}
00082 
00083 def extend(new_codes):
00084     global codes, names
00085     codes.update(new_codes)
00086     for name, code in new_codes.items():
00087         if code.set(): names[code.set()] = name
00088         if code.request(): names[code.request()] = name
00089         if code.data(): names[code.data()] = name
00090 
00091 
00092 extend({
00093     'echo':
00094         Code( 0x0000, REQUEST, payloads.Echo ),
00095     'platform_info':
00096         Code( 0x0001, SET | REQUEST, payloads.PlatformInfo ),
00097     'platform_name':
00098         Code( 0x0002, SET | REQUEST, payloads.PlatformName ),
00099     'firmware_info':
00100         Code( 0x0003, REQUEST, payloads.FirmwareInfo ),
00101     'system_status':
00102         Code( 0x0004, REQUEST, payloads.SystemStatus ),
00103 #    'platform_time':
00104 #        Code( 0x0005, SET, payloads.PlatformTime ),
00105     'power_status':
00106          Code( 0x0005, REQUEST, payloads.PowerStatus ),
00107     'processor_status':
00108         Code( 0x0006, REQUEST, payloads.ProcessorStatus ),
00109     'safety_status':
00110         Code( 0x0010, REQUEST, payloads.SafetyStatus ),
00111     'config':
00112         Code( 0x0100, SET | REQUEST, payloads.Config, payloads.ConfigRequest ),
00113     'differential_speed':
00114         Code( 0x0200, SET | REQUEST, payloads.DifferentialSpeed ),
00115     'differential_control':
00116         Code( 0x0201, SET | REQUEST, payloads.DifferentialControl ),
00117     'differential_output':
00118         Code( 0x0202, SET | REQUEST, payloads.DifferentialOutput ),
00119     'ackermann_output':
00120         Code( 0x0203, SET | REQUEST, payloads.AckermannOutput ),
00121     'differential_current':
00122         Code( 0x0220, SET | REQUEST, payloads.DifferentialCurrent ),
00123     'differential_current_control':
00124         Code( 0x0221, SET | REQUEST, payloads.DifferentialCurrentControl ),
00125     'velocity':
00126         Code( 0x0204, SET | REQUEST, payloads.Velocity ),
00127     'turn':
00128         Code( 0x0205, SET | REQUEST, payloads.Turn ),
00129     'max_speed':
00130         Code( 0x0210, SET | REQUEST, payloads.MaxSpeed ),
00131     'max_accel':
00132         Code( 0x0211, SET | REQUEST, payloads.MaxAccel ),
00133     'gear_status':
00134         Code( 0x0212, SET | REQUEST, payloads.GearStatus ),
00135 #    'gpadc_output':
00136 #        Code( 0x0300, SET | REQUEST, payloads.GPADCOutput ),
00137 #    'gpio':
00138 #        Code( 0x0301, SET | REQUEST, payloads.GPIO ),
00139 #    'gpio_output':
00140 #        Code( 0x0302, SET, payloads.GPIOOutput ),
00141 #    'gpadc_input':
00142 #        Code( 0x0303, REQUEST, payloads.GPADCInput ),
00143 #    'pan_tilt_zoom':
00144 #        Code( 0x0400, SET | REQUEST, payloads.PanTiltZoom ),
00145     'distance':
00146         Code( 0x0500, REQUEST, payloads.Distance ),
00147     'distance_timing':
00148         Code( 0x0501, REQUEST, payloads.DistanceTiming ),
00149     'platform_orientation':
00150         Code( 0x0600, REQUEST , payloads.Orientation ),
00151     'platform_rotation':
00152         Code( 0x0601, REQUEST, payloads.Rotation ),
00153     'platform_acceleration':
00154         Code( 0x0602, REQUEST, payloads.Acceleration ),
00155 #    'platform_6axis':
00156 #       Code( None, 0x4603, 0x8603, payloads.Platform6Axis ),
00157 #    'platform_6axis_orientation':
00158 #       Code( None, 0x4604, 0x8604, payloads.Platform6AxisOrientation ),
00159     'platform_magnetometer':
00160         Code( 0x0606, REQUEST, payloads.Magnetometer ),
00161     'encoders':
00162         Code( 0x0800, REQUEST, payloads.Encoders ),
00163     'raw_encoders':
00164         Code( 0x0801, REQUEST, payloads.RawEncoders ),
00165     'encoders_config':
00166         Code( 0x0802, SET | REQUEST, payloads.EncodersConfig ),
00167 #    'absolute_joint_position':
00168 #        Code( 0x1010, 0x5010, 0x9010, payloads.AbsoluteJointPosition ),
00169 #    'relative_joint_position':
00170 #        Code( 0x1011, 0x5011, 0x9011, payloads.RelativeJointPosition ),
00171 #    'joint_control':
00172 #        Code( 0x1012, 0x5012, 0x9012, payloads.JointControl ),
00173 #    'joint_homing_status':
00174 #        Code( 0x1013, 0x5013, 0x9013, payloads.JointHomingStatus ),
00175 #    'joint_torques':
00176 #        Code( None, 0x5014, 0x9014, payloads.JointTorques ),
00177 #    'end_effector_position':
00178 #        Code( 0x1020, 0x5020, 0x9020, payloads.EndEffectorPosition ),
00179 #    'end_effector_pose':
00180 #        Code( 0x1021, 0x5021, 0x9021, payloads.EndEffectorPose ),
00181 #    'end_effector_orientation':
00182 #        Code( None, 0x5022, 0x9022, payloads.EndEffectorOrientation ),
00183     'reset':
00184         Code( 0x2000, SET, payloads.Reset ),
00185     'restore_system_config':
00186         Code( 0x2001, SET, payloads.RestoreSystemConfig ),
00187     'store_system_config':
00188         Code( 0x2002, SET, payloads.StoreSystemConfig ),
00189     'current_sensor_config':
00190         Code( 0x2100, SET | REQUEST, payloads.CurrentSensorConfig ),
00191     'voltage_sensor_config':
00192         Code( 0x2101, SET | REQUEST, payloads.VoltageSensorConfig ),
00193     'temperature_sensor_config':
00194         Code( 0x2102, SET | REQUEST, payloads.TemperatureSensorConfig ),
00195     'orientation_sensor_config':
00196         Code( 0x2103, SET | REQUEST, payloads.OrientationSensorConfig ),
00197     'gyro_config':
00198         Code( 0x2104, SET | REQUEST, payloads.GyroConfig ),
00199     'accelerometer_config':
00200         Code( 0x2105, SET | REQUEST, payloads.AccelerometerConfig ),
00201     'magnetometer_config':
00202         Code( 0x2106, SET | REQUEST, payloads.MagnetometerConfig ),
00203     'battery_estimation_config':
00204         Code( 0x2107, SET | REQUEST, payloads.BatteryEstimationConfig ),
00205     'platform_kinematics':
00206         Code( 0x2108, SET | REQUEST, payloads.PlatformKinematics ),
00207     'raw_current_sensor':
00208         Code( 0x2110, REQUEST, payloads.RawCurrentSensor ),
00209     'raw_voltage_sensor':
00210         Code( 0x2111, REQUEST, payloads.RawVoltageSensor ),
00211     'raw_temperature_sensor':
00212         Code( 0x2112, REQUEST, payloads.RawTemperatureSensor ),
00213     'raw_orientation_sensor':
00214         Code( 0x2113, REQUEST, payloads.RawOrientationSensor ),
00215     'raw_gyro':
00216         Code( 0x2114, REQUEST, payloads.RawGyro ),
00217     'raw_accelerometer':
00218         Code( 0x2115, REQUEST, payloads.RawAccelerometer ),
00219     'raw_magnetometer':
00220         Code( 0x2116, REQUEST, payloads.RawMagnetometer ),
00221     'control_flags':
00222         Code( 0x2130, SET | REQUEST, payloads.ControlFlags )
00223 })


clearpath_base
Author(s): Mike Purvis
autogenerated on Sat Dec 28 2013 16:50:47