00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 if __name__ == "__main__":
00046 print ("ERROR: clearpath.horizon is a module and can NOT be run"\
00047 " as a script!\nFor a command-line interface demo of Horizon, run:"\
00048 "\n python -m clearpath.horizon.demo\n")
00049
00050 import sys
00051 sys.exit(1)
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 from .. import utils
00105 from . import protocol
00106
00107
00108 import datetime
00109 import logging
00110 import time
00111 import inspect
00112
00113 __version__ = "1.0"
00114 __revision__ = "$Revision: 916 $"
00115
00116 logger = logging.getLogger('clearpath.horizon')
00117 """Horizon Module Log"""
00118 logger.setLevel(logging.DEBUG)
00119 logger.addHandler(utils.NullLoggingHandler())
00120 logger.propagate = True
00121 logger.debug("Loading clearpath.horizon ...")
00122
00123
00124
00125
00126
00127
00128
00129
00130 class Horizon(object):
00131 version = (1, 1)
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 def __init__(self, transport = protocol.transports.Serial.autodetect,
00160 transport_args = {}, retries = 5, send_timeout = 50,
00161 rec_timeout = 100, store_timeout = 2000):
00162
00163 self._protocol = None
00164 self._protocol = protocol.Client(transport, transport_args, retries,
00165 send_timeout, rec_timeout, store_timeout)
00166
00167 def __str__(self):
00168 return str(self._protocol)
00169
00170 def __del__(self):
00171 self.close()
00172
00173 def open(self):
00174 if not self._protocol.is_open():
00175 self._protocol.open()
00176
00177
00178 firm = self.request_firmware_info()
00179 self.version = firm.version
00180
00181 def close(self):
00182 if self._protocol != None and self._protocol.is_open():
00183 self._protocol.close()
00184
00185
00186 def acks(self, enabled):
00187 if enabled:
00188 self._protocol.acks = True
00189 else:
00190 self._protocol.acks = False
00191
00192
00193
00194 def emergency_stop(self):
00195 self._protocol.emergency_stop()
00196
00197 def reset(self):
00198 self.set_reset()
00199
00200
00201
00202
00203 def set_platform_info(self, passcode = 0, model = '', revision = 0, serial = 0):
00204 self._protocol.command('platform_info', locals())
00205
00206 def set_platform_name(self, name = 'Clearpath1'):
00207 self._protocol.command('platform_name', locals())
00208
00209 def set_platform_time(self, time = 0):
00210 self._protocol.command('platform_time', locals())
00211
00212 def set_platform_kinematics(self, passcode = 0, track = 0.0, wheelbase = 0.0):
00213 self._protocol.command('platform_kinematics', locals())
00214
00215 def set_control_flags(self, passcode = 0, flags = 0x00000000):
00216 self._protocol.command('control_flags', locals())
00217
00218 def set_safety_status(self, flags = 0x0000):
00219 self._protocol.command('safety_status', locals())
00220
00221 def set_config(self, index=0, value=0.0):
00222 self._protocol.command('config', locals())
00223
00224 def set_differential_speed(self, left_speed = 0.0, right_speed = 0.0,
00225 left_accel = 0.0, right_accel = 0.0):
00226 self._protocol.command('differential_speed', locals())
00227
00228 def set_differential_current(self, left = 0.0, right = 0.0):
00229 self._protocol.command('differential_current', locals())
00230
00231 def set_differential_control(self, left_p = 0.0, left_i = 0.0, left_d = 0.0,
00232 left_ffwd = 0.0, left_stic = 0.0, left_sat = 0.0,
00233 right_p = 0.0, right_i = 0.0, right_d = 0.0, right_ffwd = 0.0,
00234 right_stic = 0.0, right_sat = 0.0):
00235 self._protocol.command('differential_control', locals())
00236
00237 def set_differential_current_control(self, left_p = 0.0, left_i = 0.0, left_d = 0.0,
00238 left_ffwd = 0.0, left_stic = 0.0, left_sat = 0.0,
00239 right_p = 0.0, right_i = 0.0, right_d = 0.0, right_ffwd = 0.0,
00240 right_stic = 0.0, right_sat = 0.0):
00241 self._protocol.command('differential_current_control', locals())
00242
00243 def set_differential_output(self, left = 0.0, right = 0.0):
00244 self._protocol.command('differential_output', locals())
00245
00246 def set_ackermann_output(self, steering = 0.0, throttle = 0.0, brake = 0.0):
00247 self._protocol.command('ackermann_output', locals())
00248
00249 def set_velocity(self, trans = 0.0, rot = 0.0, accel = 0.0):
00250 self._protocol.command('velocity', locals())
00251
00252 def set_turn(self, trans = 0.0, rad = 0.0, accel = 0.0):
00253 self._protocol.command('turn', locals())
00254
00255 def set_max_speed(self, forward = 0.0, reverse = 0.0):
00256 self._protocol.command('max_speed', locals())
00257
00258 def set_max_accel(self, forward = 0.0, reverse = 0.0):
00259 self._protocol.command('max_accel', locals())
00260
00261 def set_gear(self, gear = 0):
00262 self._protocol.command('gear', locals())
00263
00264 def set_gpadc_output(self, values = {0:0}):
00265 self._protocol.command('gpadc_output', locals())
00266
00267 def set_gpio_direction(self, mask = 0, direction = 0):
00268 self._protocol.command('gpio_direction', locals())
00269
00270 def set_gpio_output(self, mask = 0, output = 0):
00271 self._protocol.command('gpio_output', locals())
00272
00273 def set_pan_tilt_zoom(self, mount = 0, pan = 0.0, tilt = 0.0, zoom = 1.0):
00274 self._protocol.command('pan_tilt_zoom', locals())
00275
00276 def set_absolute_joint_position(self, angles = {0:0.0}):
00277 self._protocol.command('absolute_joint_position', locals())
00278
00279 def set_relative_joint_position(self, angles = {0:0.0}):
00280 self._protocol.command('relative_joint_position', locals())
00281
00282 def set_joint_control(self, joint = 0, p = 0.0, i = 0.0, d = 0.0,
00283 feed = 0.0, stiction = 0.0, limit = 0.0):
00284 self._protocol.command('joint_control', locals())
00285
00286 def set_joint_homing(self, joint = 0):
00287 self._protocol.command('joint_homing', locals())
00288
00289 def set_end_effector_position(self, x = 0.0, y = 0.0, z = 0.0):
00290 self._protocol.command('end_effector_position', locals())
00291
00292 def set_end_effector_pose(self, x = 0.0, y = 0.0, z = 0.0, roll = 0.0, pitch = 0.0, yaw = 0.0):
00293 self._protocol.command('end_effector_pose', locals())
00294
00295 def set_reset(self):
00296 self._protocol.command('reset', locals())
00297
00298 def restore_system_config(self, passcode = 0x3A18, flags = 0x1):
00299 self._protocol.command('restore_system_config', locals())
00300
00301 def store_system_config(self, passcode = 0x3A18):
00302 self._protocol.command('store_system_config', locals())
00303
00304 def set_current_sensor_config(self, passcode = 0, offsets = [ 0.0 ], scales = [ 0.0 ]):
00305 self._protocol.command('current_sensor_config', locals())
00306
00307 def set_voltage_sensor_config(self, passcode = 0, offsets = [ 0.0 ], scales = [ 0.0 ]):
00308 self._protocol.command('voltage_sensor_config', locals())
00309
00310 def set_temperature_sensor_config(self, passcode = 0, offsets = [ 0.0 ], scales = [ 0.0 ]):
00311 self._protocol.command('temperature_sensor_config', locals())
00312
00313 def set_orientation_sensor_config(self, passcode = 0,
00314 roll_offset = 0.0, roll_scale = 0.0,
00315 pitch_offset = 0.0, pitch_scale = 0.0,
00316 yaw_offset = 0.0, yaw_scale = 0.0):
00317 self._protocol.command('orientation_sensor_config', locals())
00318
00319 def set_magnetometer_config(self, passcode = 0,
00320 x_offset = 0.0, x_scale = 0.0,
00321 y_offset = 0.0, y_scale = 0.0,
00322 z_offset = 0.0, z_scale = 0.0):
00323 self._protocol.command('magnetometer_config', locals())
00324
00325 def set_gyro_config(self, passcode = 0,
00326 roll_offset = 0.0, roll_scale = 0.0,
00327 pitch_offset = 0.0, pitch_scale = 0.0,
00328 yaw_offset = 0.0, yaw_scale = 0.0):
00329 self._protocol.command('gyro_config', locals())
00330
00331 def set_accelerometer_config(self, passcode = 0,
00332 x_offset = 0.0, x_scale = 0.0,
00333 y_offset = 0.0, y_scale = 0.0,
00334 z_offset = 0.0, z_scale = 0.0):
00335 self._protocol.command('accelerometer_config', locals())
00336
00337 def set_encoders_config(self, ppr = [ 0.0 ], scales = [ 0.0 ]):
00338 self._protocol.command('encoders_config', locals())
00339
00340 def set_battery_estimation_config(self, passcode = 0.0, offsets = [ 0.0 ], scales = [ 0.0 ]):
00341 self._protocol.command('battery_estimation_config', locals())
00342
00343
00344
00345
00346 def request_echo(self, subscription = 0):
00347 return self._protocol.request('echo', locals())
00348
00349 def request_platform_info(self, subscription = 0):
00350 return self._protocol.request('platform_info', locals())
00351
00352 def request_platform_name(self, subscription = 0):
00353 return self._protocol.request('platform_name', locals())
00354
00355 def request_platform_kinematics(self, subscription = 0):
00356 return self._protocol.request('platform_kinematics', locals())
00357
00358 def request_platform_kinematics(self, subscription = 0):
00359 return self._protocol.request('platform_kinematics', locals())
00360
00361 def request_firmware_info(self, subscription = 0):
00362 return self._protocol.request('firmware_info', locals())
00363
00364 def request_control_flags(self, subscription = 0):
00365 return self._protocol.request('control_flags', locals())
00366
00367 def request_system_status(self, subscription = 0):
00368 return self._protocol.request('system_status', locals())
00369
00370 def request_processor_status(self, subscription = 0):
00371 return self._protocol.request('processor_status', locals())
00372
00373 def request_power_status(self, subscription = 0):
00374 return self._protocol.request('power_status', locals())
00375
00376 def request_safety_status(self, subscription = 0):
00377 return self._protocol.request('safety_status', locals())
00378
00379 def request_config(self, index=0):
00380 return self._protocol.request('config', locals())
00381
00382 def request_differential_speed(self, subscription = 0):
00383 return self._protocol.request('differential_speed', locals())
00384
00385 def request_differential_control(self, subscription = 0):
00386 return self._protocol.request('differential_control', locals())
00387
00388 def request_differential_current(self, subscription = 0):
00389 return self._protocol.request('differential_current', locals())
00390
00391 def request_differential_current_control(self, subscription = 0):
00392 return self._protocol.request('differential_current_control', locals())
00393
00394 def request_differential_output(self, subscription = 0):
00395 return self._protocol.request('differential_output', locals())
00396
00397 def request_ackermann_output(self, subscription = 0):
00398 return self._protocol.request('ackermann_output', locals())
00399
00400 def request_velocity(self, subscription = 0):
00401 return self._protocol.request('velocity', locals())
00402
00403 def request_turn(self, subscription = 0):
00404 return self._protocol.request('turn', locals())
00405
00406 def request_max_speed(self, subscription = 0):
00407 return self._protocol.request('max_speed', locals())
00408
00409 def request_max_accel(self, subscription = 0):
00410 return self._protocol.request('max_accel', locals())
00411
00412 def request_gear_status(self, subscription = 0):
00413 return self._protocol.request('gear_status', locals())
00414
00415 def request_gpadc_output(self, subscription = 0, channel=0):
00416 return self._protocol.request('gpadc_output', locals())
00417
00418 def request_gpio(self, subscription = 0):
00419 return self._protocol.request('gpio', locals())
00420
00421 def request_gpadc_input(self, subscription = 0):
00422 return self._protocol.request('gpadc_input', locals())
00423
00424 def request_pan_tilt_zoom(self, mount = 0, subscription = 0):
00425 return self._protocol.request('pan_tilt_zoom', locals())
00426
00427 def request_distance(self, subscription = 0):
00428 return self._protocol.request('distance', locals())
00429
00430 def request_distance_timing(self, subscription = 0):
00431 return self._protocol.request('distance_timing', locals())
00432
00433 def request_platform_orientation(self, subscription = 0):
00434 return self._protocol.request('platform_orientation', locals())
00435
00436 def request_platform_rotation(self, subscription = 0):
00437 return self._protocol.request('platform_rotation', locals())
00438
00439 def request_platform_acceleration(self, subscription = 0):
00440 return self._protocol.request('platform_acceleration', locals())
00441
00442 def request_platform_6axis(self, subscription = 0):
00443 return self._protocol.request('platform_6axis', locals())
00444
00445 def request_platform_6axis_orientation(self, subscription = 0):
00446 return self._protocol.request('platform_6axis_orientation', locals())
00447
00448 def request_platform_magnetometer(self, subscription = 0):
00449 return self._protocol.request('platform_magnetometer', locals())
00450
00451 def request_encoders(self, subscription = 0):
00452 return self._protocol.request('encoders', locals())
00453
00454 def request_raw_encoders(self, subscription = 0):
00455 return self._protocol.request('raw_encoders', locals())
00456
00457 def request_encoders_config(self, subscription = 0):
00458 return self._protocol.request('encoders_config', locals())
00459
00460 def request_absolute_joint_position(self, subscription = 0):
00461 return self._protocol.request('absolute_joint_position', locals())
00462
00463 def request_relative_joint_position(self, subscription = 0):
00464 return self._protocol.request('relative_joint_position', locals())
00465
00466 def request_joint_control(self, joint = 0, subscription = 0):
00467 return self._protocol.request('joint_control', locals())
00468
00469 def request_joint_homing_status(self, subscription = 0):
00470 return self._protocol.request('joint_homing_status', locals())
00471
00472 def request_joint_torques(self, subscription = 0):
00473 return self._protocol.request('joint_torques', locals())
00474
00475 def request_end_effector_position(self, subscription = 0):
00476 return self._protocol.request('end_effector_position', locals())
00477
00478 def request_end_effector_pose(self, subscription = 0):
00479 return self._protocol.request('end_effector_pose', locals())
00480
00481 def request_end_effector_orientation(self, subscription = 0):
00482 return self._protocol.request('end_effector_orientation', locals())
00483
00484 def request_current_sensor_config(self, subscription = 0):
00485 return self._protocol.request('current_sensor_config', locals())
00486
00487 def request_voltage_sensor_config(self, subscription = 0):
00488 return self._protocol.request('voltage_sensor_config', locals())
00489
00490 def request_temperature_sensor_config(self, subscription = 0):
00491 return self._protocol.request('temperature_sensor_config', locals())
00492
00493 def request_orientation_sensor_config(self, subscription = 0):
00494 return self._protocol.request('orientation_sensor_config', locals())
00495
00496 def request_magnetometer_config(self, subscription = 0):
00497 return self._protocol.request('magnetometer_config', locals())
00498
00499 def request_gyro_config(self, subscription = 0):
00500 return self._protocol.request('gyro_config', locals())
00501
00502 def request_battery_estimation_config(self, subscription = 0):
00503 return self._protocol.request('battery_estimation_config', locals())
00504
00505 def request_accelerometer_config(self, subscription = 0):
00506 return self._protocol.request('accelerometer_config', locals())
00507
00508 def request_raw_current_sensor(self, subscription = 0):
00509 return self._protocol.request('raw_current_sensor', locals())
00510
00511 def request_raw_voltage_sensor(self, subscription = 0):
00512 return self._protocol.request('raw_voltage_sensor', locals())
00513
00514 def request_raw_temperature_sensor(self, subscription = 0):
00515 return self._protocol.request('raw_temperature_sensor', locals())
00516
00517 def request_raw_orientation_sensor(self, subscription = 0):
00518 return self._protocol.request('raw_orientation_sensor', locals())
00519
00520 def request_raw_magnetometer(self, subscription = 0):
00521 return self._protocol.request('raw_magnetometer', locals())
00522
00523 def request_raw_gyro(self, subscription = 0):
00524 return self._protocol.request('raw_gyro', locals())
00525
00526 def request_raw_accelerometer(self, subscription = 0):
00527 return self._protocol.request('raw_accelerometer', locals())
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 def add_handler(self, handler, backtrack = False, request = None):
00548 self._protocol.add_handler(handler, backtrack, request)
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 def remove_handler(self, handler = None, request = None):
00560 self._protocol.remove_handler(handler, request)
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 def get_waiting_data(self, request = None):
00574 return self._protocol.get_waiting(request)
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 def is_open(self):
00585 if self._protocol.is_open() == False:
00586 self.close()
00587 return False
00588 return True
00589
00590
00591
00592
00593
00594
00595 def is_alive(self):
00596
00597 try:
00598 self.request_echo()
00599 return True
00600 except Exception:
00601 return False
00602
00603
00604
00605
00606
00607
00608
00609
00610 def get_device_time(self):
00611
00612
00613 self.request_echo()
00614 return self._protocol._received[2]
00615
00616
00617
00618
00619
00620
00621 def get_start_time(self):
00622 return self._protocol.start_time
00623
00624
00625
00626 alive = property(fget=is_alive, doc="Horizon Device Alive")
00627 device_time = property(fget=get_device_time, doc="Horizon Device Time")
00628 opened = property(fget=is_open, doc="Horizon Device Open")
00629 start_time = property(fget=get_start_time, doc="Horizon Start Time")