46 from puck_properties_consts
import*
59 FORCE_DATA_GROUP = 0x400
65 SPREAD_POSITION = 0x5C3
76 SPREAD_MOTOR_TEMP = 0x5C6
79 F1_MOTOR_THERM = 0x566
80 F2_MOTOR_THERM = 0x586
81 F3_MOTOR_THERM = 0x5A6
82 SPREAD_MOTOR_THERM = 0x5C6
91 FT_SENSOR_FORCE = 0x50A
92 FT_SENSOR_TORQUE = 0x50B
104 Creates a PCANBasic object 106 @param port: CAN port used to communicate with the hand 107 @type connection: string 112 self.
motor_positions = {FINGER1: {
'encoder': [0, 0],
'position': [0.0, 0.0]}, FINGER2: {
'encoder': [0, 0],
'position': [0.0, 0.0]}, FINGER3: {
'encoder': [0, 0],
'position': [0.0, 0.0]},
113 SPREAD: {
'encoder': [0, 0],
'position': [0.0, 0.0]}}
114 self.
strain = {FINGER1: 0, FINGER2: 0, FINGER3: 0, SPREAD: 0}
115 self.
temp = {FINGER1:{
'temp': 0.0,
'therm': 0.0}, FINGER2: {
'temp': 0.0,
'therm': 0.0}, FINGER3: {
'temp': 0.0,
'therm': 0.0},
116 SPREAD: {
'temp': 0.0,
'therm': 0.0}}
117 self.
tactile_sensor = {FINGER1: {
'values': range(0,24),
'data': range(0,5)}, FINGER2: {
'values': range(0,24),
'data': range(0,5)},
118 FINGER3: {
'values': range(0,24),
'data': range(0,5)}, SPREAD: {
'values': range(0,24),
'data': range(0,5)}}
120 self.
ft_sensor = {
'force': [0.0, 0.0, 0.0],
'torque': [0.0, 0.0, 0.0]}
124 Checks error on the CAN Bus. 126 @param connection: The connection on which the CAN is talking. For example, PCANBasic() 127 @type connection: PCANBasic 128 @param result: The number corresponding to the error returned. 130 @param location_of_error: A description of where the error occurred. 131 @type location_of_error: str 133 if result == PCAN_ERROR_OK:
136 raise Exception(
"Error Number: " + hex(result) +
" while attempting to " + str(location_of_error) +
"\n" + connection.GetErrorText(result)[1])
140 Finds and returns all of the pucks that are attached to the bus. 143 @return: An array containing the pucks attached to the bus. 156 Resets the CAN connection. 157 Note that this may cause a loss of data, but may also clear unwanted data. Utilize as needed. 159 reset_result=self.PCAN.Reset(PCAN_USBBUS1)
163 rospy.logerr(
'pyHand: can_reset: error: %s', e)
165 time.sleep(CAN_DELAY)
170 Returns the status of the CAN connection as specified in PCANBasic's GetStatus method. 172 status_result=self.PCAN.GetStatus(PCAN_USBBUS1)
173 time.sleep(CAN_DELAY)
178 Initializes the CAN connection. Note that this does not initialize the hand itself. 181 init_result=self.PCAN.Initialize(PCAN_USBBUS1, PCAN_BAUD_1M)
183 time.sleep(CAN_DELAY)
187 Uninitializes the CAN connection. Rarely used. 189 uninit_result=self.PCAN.Uninitialize(PCAN_USBBUS1)
196 Wakes up pucks and initializes the CAN. 197 This function must be implemented at the beginning of a program for this library to properly work. 200 @return: First finger's ROLE property if initialization is successful. Otherwise it returns False. 206 time.sleep(CAN_DELAY)
214 rospy.logerr(
'pyHand: Initialize: Error: %s', e)
219 Initialize all pucks in the hand. 222 @return: Succesfully Initialized Hand? 234 rospy.logerr(
'pyHand: init_hand: error: %s', e)
240 while attempts < INIT_ATTEMPTS:
245 rospy.logerr(
'pyHand: init_hand: error: (%d) %s', attempts, e)
253 Sends a command to the puck to wake up the motor attatched to the puck. 255 @param msgID: The id of the finger to initialize. 263 Wake pucks and tare sensor. 272 Read a general message from PCAN_USBBUS1 273 Typically, msg[1] (where msg is the thing returned), contains the pertinent information. 275 @rtype: (TPCANStatus, TPCANMsg, TPCANTimestamp) 276 @return: A tuple containing the status, message, and timestamp. 278 return self.PCAN.Read(PCAN_USBBUS1)
284 Send a general message to PCAN_USBBUS1. This can be a get, set, or even garbage. 286 @param msgID: The puck or group to which the message will be sent. 288 @param data: The array containing the data for the TPCANMsg. 290 @param delay: The time delay to wait for the message to be written. 293 @return: Status of the self.PCAN bus. 298 msg.MSGTYPE = PCAN_MESSAGE_STANDARD
299 for j
in range(0, len(data)):
300 msg.DATA[j] = data[j]
301 stat = self.PCAN.Write(PCAN_USBBUS1, msg)
309 Send a general message to PCAN_USBBUS1. This can be a get, set, or even garbage. 310 It does not apply any sleep 312 @param msgID: The puck or group to which the message will be sent. 314 @param data: The array containing the data for the TPCANMsg. 317 @return the return status after writing in the bus 322 msg.MSGTYPE = PCAN_MESSAGE_STANDARD
323 for j
in range(0, len(data)):
324 msg.DATA[j] = data[j]
325 stat = self.PCAN.Write(PCAN_USBBUS1, msg)
332 Set property to a given value. 334 @param msgID: The puck or group whose property will be set. 336 @param propID: The number corresponding to the property to be set. 338 @param value: The value to which the property will be set. 341 is32bits = [48, 50, 52, 54, 56, 58, 66, 68, 74, 88, 96, 98]
342 if propID
in is32bits:
343 self.
set_32(msgID, propID, value)
345 self.
set_16(msgID, propID, value)
349 Set property to a given value for a 32 bit property. 350 Avoid usage of this method. Use self.set_property instead. 352 @param msgID: The puck or group whose property will be set. 354 @param propID: The number corresponding to the property to be set. 356 @param value: The value to which the property will be set. 359 data = [0x80+propID, 0, value%0x100, int(value/0x100)%0x100, int(value/0x10000)%0x100, int(value/0x1000000)]
365 Set property to a given value for a 16 bit property. 366 Avoid usage of this method. Use self.set_property instead. 368 @param msgID: The puck or group whose property will be set. 370 @param propID: The number corresponding to the property to be set. 372 @param value: The value to which the property will be set. 375 data = [0x80+propID, 0, value%256, int(value/256)]
383 Get property from pucks in msgID. 385 @param msgID: The puck whose property will be read from. 387 @param propID: The property be read from. 390 @return: The value held in the property. 392 is32bits = [48, 50, 52, 54, 56, 58, 66, 68, 74, 88, 96, 98]
393 if propID
in is32bits:
394 return self.
get_32(msgID, propID)
398 return self.
get_16(msgID, propID)
403 Gets a 32 bit property. Please use get_property instead of this method where applicable. 405 @param msgID: The puck whose property will be read from. 407 @param propID: The property be read from. 410 @return: The value held in the property. 414 read_result = self.PCAN.Read(PCAN_USBBUS1)
416 data = read_result[1].DATA
417 value = (0x1000000 * data[5]) + (0x0010000 * data[4]) + (0x0000100 * data[3]) + (0x0000001 * data[2])
423 Gets a 16 bit property. Please use get_property instead of this method where applicable. 425 @param msgID: The puck whose property will be read from. 427 @param propID: The property be read from. 430 @return: The value held in the property. 435 read_result = self.PCAN.Read(PCAN_USBBUS1)
437 data = read_result[1].DATA
438 value =(0x0000100 * data[3]) + (0x0000001 * data[2])
447 @param msgID: The puck or group to have its property saved. 449 @param propID: The property to be saved. 457 Load a property's value for puck's flash memory. 459 @param msgID: The puck or group to have its property loaded. 461 @param propID: The property to be loaded. 468 Gets a property timed at a certain rate. 470 @param msgID: The puck or group to have its property gotten. 472 @param propID: The property to be saved. 474 @param speed: The time delay for the get. 480 data = read_result[1].DATA
481 value = (0x1000000 * data[5]) + (0x0010000 * data[4]) + (0x0000100 * data[3]) + (0x0000001 * data[2])
486 Reads message given the puckID and the propertyID. 487 It will read as normal, until it gets some expected output from the puck. 489 @param expect_puck: The puck to read from. 490 @type expect_puck: int 491 @param expect_prop: The property read from. 492 @type expect_prop: int 493 @param max_recurse: The most number of times to repeat the get. 494 @type max_recurse: int 495 @param counter: Used internally. Do not set. 498 @return: The value held in the property of the given puck. 501 response=self.PCAN.Read(PCAN_USBBUS1)
502 received_prop=response[1].DATA[0]-128
503 received_puck=(response[1].ID-1024)>>5
505 if (received_prop==expect_prop)
and (received_puck==expect_puck):
509 if counter<max_recurse:
512 raise Exception(
"Missed message")
516 Read from ROLE property and return something that makes sense. 517 Returns an array of holding the following data: 519 [4-bit Product Identifier, 525 IMU for Force-Torque Sensor, 526 Optical Motor Encoder] 528 @param msgID: The puck to get the ROLE from. 530 @rtype: Array[int,bool,bool,bool,bool,bool,bool,bool] 531 @return: An array holding the above values. 534 data= [0,0,0,0,0,0,0,0,0]
536 data[1] = int(role/2**6)%2==1
537 data[2] = int(role/2**7)%2==1
538 data[3] = int(role/2**8)%2==1
539 data[4] = int(role/2**9)%2==1
540 data[5] = int(role/2**10)%2==1
541 data[6] = int(role/2**11)%2==1
542 data[7] = int(role/2**12)%2==1
543 data[8] = int(role/2**13)%2==1
548 Read from MODE property, and return a tuple with the number corresponding to the mode, along with 549 the string name of the mode. 551 @param msgID: The puck from which to get the mode. 553 @rtype: Tuple(int, str) 554 @return: A tuple with the number and name of the mode. 558 return (MODE_IDLE,
"IDLE")
560 return (MODE_TORQUE,
"TORQUE")
562 return (MODE_PID,
"PID")
564 return (MODE_VEL,
"VEL")
566 return (MODE_TRAP,
"TRAP")
568 print "Invalid get_mode() operation: "+str(m)
573 Set the mode property using either strings or numbers. 575 @param msgID: The puck or group to set the mode. 577 @param value: The value to which the mode should be set. 580 modes = {
"IDLE":MODE_IDLE,
"TORQUE":MODE_TORQUE,
"PID":MODE_PID,
"VEL":MODE_VEL,
"TRAP":MODE_TRAP}
589 Set the puck to have all the default properties of the indicated puck ID. 591 @param puckID: The original puck to change. 593 @param virtID: The ID of the puck to load defaults from. 622 if virtID
in [FINGER1, FINGER2, FINGER3, SPREAD]:
710 print "Invalid Puck Id for Hand" 716 Given fingers and spread target values, move the hand to that position. 717 Will mainly be used to load user-defined hand positions. 718 Takes Barrett Units as inputs. 720 @param f1_target: The position (in encoder ticks) for finger 1 to move to. 722 @param f2_target: The position for finger 2 to move to. 724 @param f3_target: The position for finger 3 to move to. 726 @param sp_target: The position for spread to move to. 740 def move_to(self, puckID, target, autowait=True):
742 Move the motor to a specific position. 744 @param puckID: The puck to move. 746 @param target: The end position to move to. 748 @param autowait: Does the program wait until the motor is done moving? 757 Checks a given list of motors once to see if they have stopped moving, and if so, it returns true 759 @param motors_to_check: A list of motors to check. 760 @type motors_to_check: Array[*int] 762 @return: Whether or not the motors are done moving. 764 for FINGER
in motors_to_check:
772 Waits until the given list of motors have all stopped moving. 774 @param motors_to_check: A list of motors to wait for. 775 @type motors_to_check: Array[*int] 778 time.sleep(CAN_DELAY)
783 @return: True if the finger has broken away, False if it hasn't 786 ratio = tup[0]/tup[1]
791 Opens all fingers to the position encoded by Open Target (OT) 813 Closes all fingers to the position encoded by Close Target (CT). 835 Open spread to position determined by Open Target (OT). 843 Close spread to position determined by Close Target (CT). 850 Open finger and wait for completion. 852 @param puckID: Finger to be opened. 854 @param autowait: calls wait_done_moving if True. Defaults to True. 857 if puckID
in [FINGER1, FINGER2, FINGER3]:
867 Close finger and wait for completion. 869 @param puckID: Finger to be closed. 871 @param autowait: calls wait_done_moving if True. Defaults to True. 874 if puckID
in [FINGER1, FINGER2, FINGER3]:
884 Moves all fingers to input argument or default position (50). 886 @param position: position of fingers. Defaults to -1. Valid position range is from 0-195,000 encoder counts. 899 Moves all fingers/spread to their default. 906 Opens every fingers at once. Mainly used in DEMO. WARNING: can be dangerous because it may cause fingers to collide if the hand is in an unknown position. 920 Closes every finger at once. Mainly for use in DEMO. WARNING: can be dangerous because it may cause fingers to collide if the hand is in an unknown position. 936 Open grasp by input increment. 938 @param step: size of increment in encoder counts. Defaults to 0. 948 Close grasp by input decrement. 950 @param step: size of decrement in encoder counts. Defaults to 0. 960 Open spread by input increment. 962 @param step: size of increment in encoder counts. Defaults to -1. 971 Close spread by input decrement. 973 @param step: size of decrement in encoder counts. Defaults to -1. 982 Open finger by input increment. 984 @param puckID: Finger to be opened. 986 @param step: size of increment in encoder counts. Defaults to -1. 988 @param autowait: calls wait_done_moving if True. Defaults to True. 1000 Close finger by input decrement. 1002 @param puckID: Finger to be closed. 1004 @param step: size of decrement in encoder counts. Defaults to -1. 1006 @param autowait: calls wait_done_moving if True. Defaults to True. 1007 @type autowait: bool 1019 read_result=self.PCAN.Read(PCAN_USBBUS1)
1024 Returns velocity values of finger when in motion. Mostly returns garbage. It's used to help tell when finger is stopped or near to it. 1026 @param msgID: The puck or group to get velocity. 1029 @return: A (garbage) value representing the approximate velocity of the finger. 1046 stamp1=time1.micros + 1000 * time1.millis + 0xFFFFFFFF * 1000 * time1.millis_overflow
1047 stamp2=time2.micros + 1000 * time2.millis + 0xFFFFFFFF * 1000 * time2.millis_overflow
1049 delta=(stamp2-stamp1)/1000000.0
1051 self.
check_error(self.
PCAN,error1,
"reading position for fake get_velocity")
1052 self.
check_error(self.
PCAN,error2,
"reading position for fake get_velocity")
1054 val1=(0x0000100 * data1[3]) + (0x0000001 * data1[2])
1055 val2=(0x0000100 * data2[3]) + (0x0000001 * data2[2])
1057 return (val2-val1)/delta
1061 Gets temperature value for all pucks in msgID. 1063 @param msgID: The puck or group to get temp. 1066 @return: The value of the TEMP property. 1068 return self.
temp[msgID][
'temp']
1073 Sends a message to get the temperature value for all pucks in msgID. 1075 @param msgID: The puck or group to get temp. 1078 @return: The value of the TEMP property. 1080 return self.
send_msg(msgID, [TEMP])
1084 Gets motor temperature value for all pucks in msgID. 1086 @param msgID: The puck or group to get motor temperature. 1089 @return: The value of the THERM property. 1091 return self.
temp[msgID][
'therm']
1095 Gets motor temperature value for all pucks in msgID. 1097 @param msgID: The puck or group to get motor temperature. 1100 @return: The value of the THERM property. 1102 return self.
send_msg(msgID, [THERM])
1106 Unpack the top10 values from TACT. 1107 Returns a dictionary with 10 items like (sensor number):(tact value). 1109 @param msgID: The puck or group to get top 10 tactile data. 1111 @rtype: Dictionary{sensorID:value} 1112 @return topVals: Dictionary of the top 10 tactile array sensor values. 1117 read_result=self.PCAN.Read(PCAN_USBBUS1)
1118 self.
check_error(self.
PCAN,read_result[0],
"reading top ten tactile values")
1120 output = read_result[1].DATA
1122 top10 = output[0] * 0x10000 + output[1] * 0x100 + output[2] * 0x1
1124 data = [output[3]/(0x10), output[3]%(0x10), output[4]/(0x10), output[4]%(0x10), output[5]/(0x10), output[5]%(0x10)]
1126 for sensor
in range(0, 24):
1129 topVals[sensor] = data[count]
1137 Read all tactile sensors 1143 Unpack all tactile sensor values in an array. 1145 @param msgID: The puck or group to get full tactile array sensor data. 1147 @rtype: Array[*data] 1148 @return: An array containing the tactile data from a given puck. 1151 '''self.set_property(msgID, TACT, TACT_FULL) 1152 #self.write_msg(msgID, [TACT]) 1153 output = [0,0,0,0,0] 1154 read_result = self.PCAN.Read(PCAN_USBBUS1) 1155 self.check_error(self.PCAN,read_result[0],"reading full tactile data") 1156 read_result2 = self.PCAN.Read(PCAN_USBBUS1) 1157 self.check_error(self.PCAN,read_result2[0],"reading full tactile data") 1158 read_result3 = self.PCAN.Read(PCAN_USBBUS1) 1159 self.check_error(self.PCAN,read_result3[0],"reading full tactile data") 1160 read_result4 = self.PCAN.Read(PCAN_USBBUS1) 1161 self.check_error(self.PCAN,read_result4[0],"reading full tactile data") 1162 read_result5 = self.PCAN.Read(PCAN_USBBUS1) 1163 self.check_error(self.PCAN,read_result5[0],"reading full tactile data") 1165 output[0] = read_result[1].DATA 1166 output[1] = read_result2[1].DATA 1167 output[2] = read_result3[1].DATA 1168 output[3] = read_result4[1].DATA 1169 output[4] = read_result5[1].DATA 1171 #print 'Init: ID1 = %x, ID2 = %x, ID3 = %x, ID4 = %x, ID5 = %x'%(read_result[1].ID, read_result2[1].ID, read_result3[1].ID, read_result4[1].ID, read_result5[1].ID) 1172 tactileVals = range(0,24) 1175 index_ = int(data[0]/16) * 5 1176 #print 'index = %d, data[0] = %x'%(index_, data[0]) 1177 # Get the bits and then unpack them. 1178 tactileVals[index_ + 0] = round(((data[0]%0x10)*0x100 + data[1])/256.0,2) 1179 tactileVals[index_ + 1] = round((data[2]*0x10 + int(data[3]/0x10))/256.0,2) 1180 tactileVals[index_ + 2] = round(((data[3]%0x10)*0x100 + data[4])/256.0,2) 1181 tactileVals[index_ + 3] = round((data[5]*0x10 + int(data[6]/0x10))/256.0,2) 1183 tactileVals[index_ + 4] = round(((data[6]%0x10)*0x100 + data[7])/256.0,2) 1184 #print 'Return OK : %s'%(tactileVals) 1185 return tactileVals''' 1192 Obtain and interpret tactile sensor data. 1194 @param msgID: The puck or group to get full or top 10 tactile array sensor data. 1196 @param topOrFull: To get full data, enter "FULL". To get the top 10 values, enter "TOP10". Or anything else, really. 1197 @type topOrFull: str 1200 if topOrFull ==
"FULL":
1207 Set the velocity and make the motor move. 1209 @param puckID: The ID of the puck to set the velocity of. 1211 @param velocity: The velocity (in cts/ms) of the motor. 1224 Gets the fingertip torque sensor value. 1226 @param msgID: The puck or group to get fingertip torque sensor data. 1229 @return: Strain Gauge Reading 1231 return self.
strain[msgID]
1236 Sends the message to get the fingertip torque sensor value. 1238 @param msgID: The puck or group to get fingertip torque sensor data. 1248 return ''.join(
'1' if b==
'0' else '0' for b
in binstr)
1251 binstr= bin(number)[2:]
1252 a= bin(int(self.
onescomp(binstr),2)+1)[2:]
1257 Returns the two's complement of a number with a certain amount of bits. 1259 @param number: The number to take the two's complement of. 1261 @param bits: The size of the integer in bits. 1264 return -(1<<bits) + number
1269 Get packed position data and return it. 1271 @param msgID: The puck or group to get position data. 1275 @param depth: number of times get message was retried. 1277 @return: The position of the finger in encoder counts. 1281 read_result=self.PCAN.Read(PCAN_USBBUS1)
1284 received_puck=(read_result[1].ID-1024)>>5
1285 if received_puck!=msgID:
1286 raise Exception(
"Did not read expected MSGID")
1289 raise Exception(
"Failure to get position data.")
1293 output = read_result[1].DATA
1294 temp=(output[0]-0x80)*0x10000 + output[1] * 0x100 + output[2]
1296 if (temp & 0b1000000000000000000000):
1303 Get packed position data and return both P and JP. 1305 @param msgID: The puck or group to get position data. 1309 @return: The position and joint position of the finger in encoder counts. 1318 Get packed position data and return both P and JP. 1320 @param msgID: The puck or group to get position data. 1324 @return: sends a msg to read the position. 1332 Reads and process all the msgs in the bus 1333 Depending on the CAN id, it'll use different methods 1340 if msg[0] != PCAN_ERROR_OK:
1343 while msg[0] == PCAN_ERROR_OK:
1348 if can_id
in [F1_POSITION, F2_POSITION, F3_POSITION, SPREAD_POSITION]:
1350 elif can_id
in [F1_STRAIN, F2_STRAIN, F3_STRAIN, SPREAD_STRAIN]
and msg[1].DATA[0] == STRAIN_ID:
1352 elif can_id
in [F1_MOTOR_TEMP, F2_MOTOR_TEMP, F3_MOTOR_TEMP, SPREAD_MOTOR_TEMP]
and msg[1].DATA[0] == MOTOR_TEMP_ID:
1354 elif can_id
in [F1_MOTOR_THERM, F2_MOTOR_THERM, F3_MOTOR_THERM, SPREAD_MOTOR_THERM]
and msg[1].DATA[0] == MOTOR_THERM_ID:
1356 elif can_id
in [F1_TACT, F2_TACT, F3_TACT, PALM_TACT]:
1358 elif can_id == FT_SENSOR_FORCE:
1360 elif can_id == FT_SENSOR_TORQUE:
1363 rospy.logwarn(
'pyHand:process_can_messages: unknown message %x:[%d %d %d %d %d %d %d %d]', can_id, msg[1].DATA[0], msg[1].DATA[1],
1364 msg[1].DATA[2], msg[1].DATA[3], msg[1].DATA[4], msg[1].DATA[5], msg[1].DATA[6], msg[1].DATA[7])
1372 Process the CAN msgs and saves the position depending on the MSG ID 1375 pos = (data[0]-0x80)*0x10000 + data[1]*0x100 + data[2]
1376 jpos= (data[3]-0x80)*0x10000 + data[4]*0x100 + data[5]
1377 pos = self.
twoscomp(pos)
if pos & 0b1000000000000000000000
else pos
1378 jpos= self.
twoscomp(jpos)
if jpos & 0b1000000000000000000000
else jpos
1380 if msg.ID == F1_POSITION:
1387 elif msg.ID == F2_POSITION:
1394 elif msg.ID == F3_POSITION:
1402 elif msg.ID == SPREAD_POSITION:
1412 Process the msg and extract the strain value depending on the CAN ID 1415 value =(0x0000100 * data[3]) + (0x0000001 * data[2])
1417 if msg.ID == F1_STRAIN:
1418 self.
strain[FINGER1] = value
1419 if msg.ID == F2_STRAIN:
1420 self.
strain[FINGER2] = value
1421 if msg.ID == F3_STRAIN:
1422 self.
strain[FINGER3] = value
1423 if msg.ID == SPREAD_STRAIN:
1424 self.
strain[SPREAD] = value
1428 Process the msg and extract the temperature of the motor puck on the CAN ID 1431 value =(0x0000100 * data[3]) + (0x0000001 * data[2])
1433 if msg.ID == F1_MOTOR_TEMP:
1434 self.
temp[FINGER1][
'temp'] = value
1436 if msg.ID == F2_MOTOR_TEMP:
1437 self.
temp[FINGER2][
'temp'] = value
1439 if msg.ID == F3_MOTOR_TEMP:
1440 self.
temp[FINGER3][
'temp'] = value
1442 if msg.ID == SPREAD_MOTOR_TEMP:
1443 self.
temp[SPREAD][
'temp'] = value
1448 Process the msg and extract the temperature of the motor on the CAN ID 1451 value =(0x0000100 * data[3]) + (0x0000001 * data[2])
1453 if msg.ID == F1_MOTOR_THERM:
1454 self.
temp[FINGER1][
'therm'] = value
1456 if msg.ID == F2_MOTOR_THERM:
1457 self.
temp[FINGER2][
'therm'] = value
1459 if msg.ID == F3_MOTOR_THERM:
1460 self.
temp[FINGER3][
'therm'] = value
1462 if msg.ID == SPREAD_MOTOR_THERM:
1463 self.
temp[SPREAD][
'therm'] = value
1468 Process and saves all the messages containing the tactile information 1473 if msg.ID == F1_TACT:
1474 if data[0] >= 0x00
and data[0] < 0x10:
1476 if data[0] >= 0x10
and data[0] < 0x20:
1478 if data[0] >= 0x20
and data[0] < 0x30:
1480 if data[0] >= 0x30
and data[0] < 0x40:
1485 if msg.ID == F2_TACT:
1486 if data[0] >= 0x00
and data[0] < 0x10:
1488 if data[0] >= 0x10
and data[0] < 0x20:
1490 if data[0] >= 0x20
and data[0] < 0x30:
1492 if data[0] >= 0x30
and data[0] < 0x40:
1497 if msg.ID == F3_TACT:
1498 if data[0] >= 0x00
and data[0] < 0x10:
1500 if data[0] >= 0x10
and data[0] < 0x20:
1502 if data[0] >= 0x20
and data[0] < 0x30:
1504 if data[0] >= 0x30
and data[0] < 0x40:
1509 if msg.ID == PALM_TACT:
1510 if data[0] >= 0x00
and data[0] < 0x10:
1512 if data[0] >= 0x10
and data[0] < 0x20:
1514 if data[0] >= 0x20
and data[0] < 0x30:
1516 if data[0] >= 0x30
and data[0] < 0x40:
1524 Process the array of data and returns a tactile array 1526 tactileVals = range(0,24)
1528 for data
in data_array:
1529 index_ = int(data[0]/16) * 5
1532 tactileVals[index_ + 0] = round(((data[0]%0x10)*0x100 + data[1])/256.0,2)
1533 tactileVals[index_ + 1] = round((data[2]*0x10 + int(data[3]/0x10))/256.0,2)
1534 tactileVals[index_ + 2] = round(((data[3]%0x10)*0x100 + data[4])/256.0,2)
1535 tactileVals[index_ + 3] = round((data[5]*0x10 + int(data[6]/0x10))/256.0,2)
1537 tactileVals[index_ + 4] = round(((data[6]%0x10)*0x100 + data[7])/256.0,2)
1543 Process the CAN msgs and saves the position depending on the MSG ID 1547 val = data[1] * 0x100 + data[0]
1548 val = val
if val < 0x8000
else self.
twoscomp2(val, 16)
1549 self.
ft_sensor[
'force'][0] = round(val/256.0, 2)
1551 val = data[3] * 0x100 + data[2]
1552 val = val
if val < 0x8000
else self.
twoscomp2(val, 16)
1553 self.
ft_sensor[
'force'][1] = round(val/256.0, 2)
1555 val = data[5] + 0x100 + data[4] - 0x100
1556 val = val
if val < 0x8000
else self.
twoscomp2(val, 16)
1557 self.
ft_sensor[
'force'][2] = round(val/256.0, 2)
1562 Process the CAN msgs and saves the position depending on the MSG ID 1566 val = data[1] * 0x100 + data[0]
1567 val = val
if val < 0x8000
else self.
twoscomp2(val, 16)
1568 self.
ft_sensor[
'torque'][0] = round(val/4096.0, 3)
1570 val = data[3] * 0x100 + data[2]
1571 val = val
if val < 0x8000
else self.
twoscomp2(val, 16)
1572 self.
ft_sensor[
'torque'][1] = round(val/4096.0, 3)
1574 val = data[5] + 0x100 + data[4] - 0x100
1575 val = val
if val < 0x8000
else self.
twoscomp2(val, 16)
1576 self.
ft_sensor[
'torque'][2] = round(val/4096.0, 3)
1581 Tare the FTS sensor. 1587 Returns the FTS values 1593 for finger
in fingers_to_change:
1594 former_mailbox_c[finger]=self.
get_property(finger,GRPC)
1596 return former_mailbox_c
1599 for finger
in fingers_to_change:
1600 former_mailbox_value=former[finger]
1606 Given an angle in encoder counts, return the percentage of the angle that represents. 1608 @param enc: Encoder counts. 1614 return round(per, 2)
1618 Given an angle in encoder counts, return the radian measure of the angle that represents. 1620 @param enc: Encoder counts. 1625 motion_limit = BASE_LIMIT
1626 tics = MAX_ENCODER_TICKS
1628 if type == TIP_TYPE:
1629 motion_limit = TIP_LIMIT
1630 tics = MAX_FINGERTIP_TICKS
1631 elif type == SPREAD_TYPE:
1632 motion_limit = SPREAD_LIMIT
1633 tics = MAX_SPREAD_TICKS
1636 rad = enc * (motion_limit*PI/180)/tics
1641 Given an angle in encoder counts, return the degree measure of the angle that represents. 1643 @param enc: Encoder counts. 1648 deg = enc * 140/MAX_ENCODER_TICKS
1653 Given a percentage of an angle, return it in encoder counts. 1655 @param per: Percentage 1657 @return: Encoder counts 1665 Given the readian measure of an angle, return it in encoder counts. 1669 @return: Encoder counts 1672 motion_limit = BASE_LIMIT
1673 tics = MAX_ENCODER_TICKS
1675 if type == TIP_TYPE:
1676 motion_limit = TIP_LIMIT
1677 tics = MAX_FINGERTIP_TICKS
1678 elif type == SPREAD_TYPE:
1679 motion_limit = SPREAD_LIMIT
1680 tics = MAX_SPREAD_TICKS
1683 enc = rad / ((motion_limit*PI/180)/tics)
1689 Given a degree measure of an angle, return it in encoder counts. 1693 @return: Encoder counts 1696 enc = deg * 195000.0/140
1703 while result_[0] == 0:
1708 Read all tactile sensors 1710 return self.
send_msg(FTS, [FTS_FT])
def enc_to_rad(self, enc, type=BASE_TYPE)
def send_msg(self, msgID, data)
def process_packed_position(self, msg)
def read_packed_position(self, msgID)
def twoscomp2(self, number, bits)
def get_packed_position(self, msgID)
def move_to(self, puckID, target, autowait=True)
def open_spread_step(self, step=-1)
def read_msg_resilient(self, expect_puck, expect_prop, max_recurse=10, counter=0)
def get_prop_quick(self, msgID, propID, speed)
def move_grasp(self, position=-1)
def get_tact(self, msgID, topOrFull="TOP10")
def set_velocity(self, puckID, velocity)
def get_full_pos_packet(msgID)
def close_finger_step(self, puckID, step=-1, autowait=True)
def init_finger(self, msgID)
def get_property(self, msgID, propID)
def detect_breakaway(self, finger)
def process_tactile_data(self, data_array)
def load_property(self, msgID, propID)
def set_puck_like(self, puckID, virtID)
def rad_to_enc(self, rad, type=BASE_TYPE)
def process_full_tact(self, msg)
def read_strain(self, msgID)
def get_mode(self, msgID)
def per_to_enc(self, per)
def get_therm(self, msgID)
def get_strain(self, msgID)
def process_motor_temp(self, msg)
def close_spread_step(self, step=-1)
def save_property(self, msgID, propID)
def read_full_force_torque(self)
def get_role(self, msgID)
def process_strain(self, msg)
def read_therm(self, msgID)
def enc_to_per(self, enc)
def clean_read_buffer(self)
def process_torque(self, msg)
def set_16(self, msgID, propID, value)
def process_motor_therm(self, msg)
def close_finger(self, puckID, autowait=True)
def new_temp_mail(self, fingers_to_change)
def get_position(self, msgID, depth=0)
def check_error(self, connection, result, location_of_error)
def open_finger_step(self, puckID, step=-1, autowait=True)
def close_grasp_step(self, step=0)
def open_finger(self, puckID, autowait=True)
def open_grasp_step(self, step=0)
def onescomp(self, binstr)
def set_property(self, msgID, propID, value)
def get_temp(self, msgID)
def enc_to_deg(self, enc)
def process_can_messages(self)
def read_full_tact(self, msgID)
def twoscomp(self, number)
def get_32(self, msgID, propID)
def process_force(self, msg)
def get_16(self, msgID, propID)
def get_full_tact(self, msgID)
def get_velocity(self, msgID)
def write_msg(self, msgID, data, delay=.002)
def read_temp(self, msgID)
def set_hand_targets(self, f1_target, f2_target, f3_target, sp_target)
def wait_done_moving(self, motors_to_check=ALL_FINGERS)
def __init__(self, port='/dev/pcan32')
def deg_to_enc(self, deg)
def set_mode(self, msgID, value)
def done_moving(self, motors_to_check=ALL_FINGERS)
def get_top_tact(self, msgID)
def set_32(self, msgID, propID, value)
def revert_temp_mail(self, fingers_to_change, former)