How to use _msg method in prospector

Best Python code snippet using prospector_python

test_modification.py

Source:test_modification.py Github

copy

Full Screen

...43 else:44 App.newDocument(self.doc_name)45 App.setActiveDocument(self.doc_name)46 self.doc = App.ActiveDocument47 _msg(" Temporary document '{}'".format(self.doc_name))48 def test_move(self):49 """Create a line and move it."""50 operation = "Draft Move"51 _msg(" Test '{}'".format(operation))52 a = Vector(0, 2, 0)53 b = Vector(2, 2, 0)54 _msg(" Line")55 _msg(" a={0}, b={1}".format(a, b))56 obj = Draft.make_line(a, b)57 c = Vector(3, 1, 0)58 _msg(" Translation vector")59 _msg(" c={}".format(c))60 Draft.move(obj, c)61 self.assertTrue(obj.Start == Vector(3, 3, 0),62 "'{}' failed".format(operation))63 def test_copy(self):64 """Create a line, then copy and move it."""65 operation = "Draft Move with copy"66 _msg(" Test '{}'".format(operation))67 a = Vector(0, 3, 0)68 b = Vector(2, 3, 0)69 _msg(" Line")70 _msg(" a={0}, b={1}".format(a, b))71 line = Draft.make_line(a, b)72 c = Vector(2, 2, 0)73 _msg(" Translation vector (copy)")74 _msg(" c={}".format(c))75 obj = Draft.move(line, c, copy=True)76 self.assertTrue(obj, "'{}' failed".format(operation))77 def test_rotate(self):78 """Create a line, then rotate it."""79 operation = "Draft Rotate"80 _msg(" Test '{}'".format(operation))81 a = Vector(1, 1, 0)82 b = Vector(3, 1, 0)83 _msg(" Line")84 _msg(" a={0}, b={1}".format(a, b))85 obj = Draft.make_line(a, b)86 App.ActiveDocument.recompute()87 c = Vector(-1, 1, 0)88 rot = 9089 _msg(" Rotation")90 _msg(" angle={} degrees".format(rot))91 Draft.rotate(obj, rot)92 self.assertTrue(obj.Start.isEqual(c, 1e-12),93 "'{}' failed".format(operation))94 def test_offset_open(self):95 """Create a wire, then produce an offset copy."""96 operation = "Draft Offset"97 _msg(" Test '{}'".format(operation))98 a = Vector(0, 2, 0)99 b = Vector(2, 4, 0)100 c = Vector(5, 2, 0)101 _msg(" Wire")102 _msg(" a={0}, b={1}".format(a, b))103 _msg(" c={0}".format(c))104 wire = Draft.make_wire([a, b, c])105 App.ActiveDocument.recompute()106 offset = Vector(-1, 1, 0)107 _msg(" Offset")108 _msg(" vector={}".format(offset))109 obj = Draft.offset(wire, offset, copy=True)110 self.assertTrue(obj, "'{}' failed".format(operation))111 def test_offset_closed(self):112 """Create a rectangle, then produce an offset copy."""113 operation = "Draft Offset"114 _msg(" Test '{}'".format(operation))115 length = 4116 width = 2117 _msg(" Rectangle")118 _msg(" length={0}, width={1}".format(length, width))119 rect = Draft.make_rectangle(length, width)120 App.ActiveDocument.recompute()121 offset = Vector(-1, -1, 0)122 _msg(" Offset")123 _msg(" vector={}".format(offset))124 obj = Draft.offset(rect, offset, copy=True)125 self.assertTrue(obj, "'{}' failed".format(operation))126 def test_trim(self):127 """Trim a line. NOT IMPLEMENTED."""128 operation = "Draft Trimex trim"129 _msg(" Test '{}'".format(operation))130 a = Vector(0, 0, 0)131 b = Vector(3, 3, 0)132 _msg(" Line")133 _msg(" a={0}, b={1}".format(a, b))134 line = Draft.make_line(a, b)135 c = Vector(2, 2, 0)136 d = Vector(4, 2, 0)137 _msg(" Line 2")138 _msg(" c={0}, d={1}".format(c, d))139 line2 = Draft.make_line(c, d)140 App.ActiveDocument.recompute()141 Draft.trim_objects = aux.fake_function142 obj = Draft.trim_objects(line, line2)143 self.assertTrue(obj, "'{}' failed".format(operation))144 def test_extend(self):145 """Extend a line. NOT IMPLEMENTED."""146 operation = "Draft Trimex extend"147 _msg(" Test '{}'".format(operation))148 a = Vector(0, 0, 0)149 b = Vector(1, 1, 0)150 _msg(" Line")151 _msg(" a={0}, b={1}".format(a, b))152 line = Draft.make_line(a, b)153 c = Vector(2, 2, 0)154 d = Vector(4, 2, 0)155 _msg(" Line 2")156 _msg(" c={0}, d={1}".format(c, d))157 line2 = Draft.make_line(c, d)158 App.ActiveDocument.recompute()159 Draft.extrude = aux.fake_function160 obj = Draft.extrude(line, line2)161 self.assertTrue(obj, "'{}' failed".format(operation))162 def test_join(self):163 """Join two lines into a single Draft Wire."""164 operation = "Draft Join"165 _msg(" Test '{}'".format(operation))166 a = Vector(0, 0, 0)167 b = Vector(2, 2, 0)168 c = Vector(2, 4, 0)169 _msg(" Line 1")170 _msg(" a={0}, b={1}".format(a, b))171 _msg(" Line 2")172 _msg(" b={0}, c={1}".format(b, c))173 line_1 = Draft.make_line(a, b)174 line_2 = Draft.make_line(b, c)175 # obj = Draft.join_wires([line_1, line_2]) # Multiple wires176 obj = Draft.join_two_wires(line_1, line_2)177 self.assertTrue(obj, "'{}' failed".format(operation))178 def test_split(self):179 """Split a Draft Wire into two Draft Wires."""180 operation = "Draft_Split"181 _msg(" Test '{}'".format(operation))182 a = Vector(0, 0, 0)183 b = Vector(2, 2, 0)184 c = Vector(2, 4, 0)185 d = Vector(6, 4, 0)186 _msg(" Wire")187 _msg(" a={0}, b={1}".format(a, b))188 _msg(" c={0}, d={1}".format(c, d))189 wire = Draft.make_wire([a, b, c, d])190 index = 1191 _msg(" Split at")192 _msg(" p={0}, index={1}".format(b, index))193 obj = Draft.split(wire, b, index)194 # TODO: split needs to be modified so that it returns True or False.195 # Then checking for Wire001 is not needed196 if App.ActiveDocument.Wire001:197 obj = True198 self.assertTrue(obj, "'{}' failed".format(operation))199 def test_upgrade(self):200 """Upgrade two Draft Lines into a closed Draft Wire."""201 operation = "Draft Upgrade"202 _msg(" Test '{}'".format(operation))203 a = Vector(0, 0, 0)204 b = Vector(2, 2, 0)205 c = Vector(2, 4, 0)206 _msg(" Line 1")207 _msg(" a={0}, b={1}".format(a, b))208 _msg(" Line 2")209 _msg(" b={0}, c={1}".format(b, c))210 line_1 = Draft.make_line(a, b)211 line_2 = Draft.make_line(b, c)212 App.ActiveDocument.recompute()213 obj = Draft.upgrade([line_1, line_2], delete=True)214 App.ActiveDocument.recompute()215 s = obj[0][0]216 _msg(" 1: Result '{0}' ({1})".format(s.Shape.ShapeType, s.TypeId))217 self.assertTrue(bool(obj[0]), "'{}' failed".format(operation))218 obj2 = Draft.upgrade(obj[0], delete=True)219 App.ActiveDocument.recompute()220 s2 = obj2[0][0]221 _msg(" 2: Result '{0}' ({1})".format(s2.Shape.ShapeType,222 s2.TypeId))223 self.assertTrue(bool(obj2[0]), "'{}' failed".format(operation))224 obj3 = Draft.upgrade(obj2[0], delete=True)225 App.ActiveDocument.recompute()226 s3 = obj3[0][0]227 _msg(" 3: Result '{0}' ({1})".format(s3.Shape.ShapeType, s3.TypeId))228 self.assertTrue(bool(obj3[0]), "'{}' failed".format(operation))229 obj4 = Draft.upgrade(obj3[0], delete=True)230 App.ActiveDocument.recompute()231 wire = App.ActiveDocument.Wire232 _msg(" 4: Result '{0}' ({1})".format(wire.Proxy.Type, wire.TypeId))233 _msg(" The last object cannot be upgraded further")234 self.assertFalse(bool(obj4[0]), "'{}' failed".format(operation))235 def test_downgrade(self):236 """Downgrade a closed Draft Wire into three simple Part Edges."""237 operation = "Draft Downgrade"238 _msg(" Test '{}'".format(operation))239 a = Vector(0, 0, 0)240 b = Vector(2, 2, 0)241 c = Vector(2, 4, 0)242 _msg(" Closed wire")243 _msg(" a={0}, b={1}".format(a, b))244 _msg(" c={0}, a={1}".format(c, a))245 wire = Draft.make_wire([a, b, c, a])246 App.ActiveDocument.recompute()247 obj = Draft.downgrade(wire, delete=True)248 App.ActiveDocument.recompute()249 s = obj[0][0]250 _msg(" 1: Result '{0}' ({1})".format(s.Shape.ShapeType, s.TypeId))251 self.assertTrue(bool(obj[0]), "'{}' failed".format(operation))252 obj2 = Draft.downgrade(obj[0], delete=True)253 App.ActiveDocument.recompute()254 s2 = obj2[0][0]255 _msg(" 2: Result '{0}' ({1})".format(s2.Shape.ShapeType, s2.TypeId))256 self.assertTrue(bool(obj2[0]), "'{}' failed".format(operation))257 obj3 = Draft.downgrade(obj2[0], delete=True)258 App.ActiveDocument.recompute()259 s3 = obj3[0][0]260 _msg(" 3: Result 3 x '{0}' ({1})".format(s3.Shape.ShapeType,261 s3.TypeId))262 self.assertTrue(len(obj3[0]) == 3, "'{}' failed".format(operation))263 obj4 = Draft.downgrade(obj3[0], delete=True)264 App.ActiveDocument.recompute()265 s4 = obj4[0]266 _msg(" 4: Result '{}'".format(s4))267 _msg(" The last objects cannot be downgraded further")268 self.assertFalse(bool(obj4[0]), "'{}' failed".format(operation))269 def test_wire_to_bspline(self):270 """Convert a polyline to BSpline and back."""271 operation = "Draft WireToBSpline"272 _msg(" Test '{}'".format(operation))273 a = Vector(0, 0, 0)274 b = Vector(2, 2, 0)275 c = Vector(2, 4, 0)276 _msg(" Wire")277 _msg(" a={0}, b={1}".format(a, b))278 _msg(" c={}".format(c))279 wire = Draft.make_wire([a, b, c])280 obj = Draft.make_bspline(wire.Points)281 App.ActiveDocument.recompute()282 _msg(" 1: Result '{0}' ({1})".format(obj.Proxy.Type, obj.TypeId))283 self.assertTrue(obj, "'{}' failed".format(operation))284 obj2 = Draft.make_wire(obj.Points)285 _msg(" 2: Result '{0}' ({1})".format(obj2.Proxy.Type, obj2.TypeId))286 self.assertTrue(obj2, "'{}' failed".format(operation))287 def test_shape_2d_view(self):288 """Create a prism and then a 2D projection of it."""289 operation = "Draft Shape2DView"290 _msg(" Test '{}'".format(operation))291 prism = App.ActiveDocument.addObject("Part::Prism")292 prism.Polygon = 5293 # Rotate the prism 45 degrees around the Y axis294 prism.Placement.Rotation.Axis = Vector(0, 1, 0)295 prism.Placement.Rotation.Angle = 45 * (3.14159/180)296 _msg(" Prism")297 _msg(" n_sides={}".format(prism.Polygon))298 _msg(" placement={}".format(prism.Placement))299 direction = Vector(0, 0, 1)300 _msg(" Projection 2D view")301 _msg(" direction={}".format(direction))302 obj = Draft.make_shape2dview(prism, direction)303 self.assertTrue(obj, "'{}' failed".format(operation))304 def test_draft_to_sketch(self):305 """Convert a Draft object to a Sketch and back."""306 operation = "Draft Draft2Sketch"307 _msg(" Test '{}'".format(operation))308 a = Vector(0, 0, 0)309 b = Vector(2, 2, 0)310 c = Vector(2, 4, 0)311 _msg(" Wire")312 _msg(" a={0}, b={1}".format(a, b))313 _msg(" c={}".format(c))314 wire = Draft.make_wire([a, b, c])315 App.ActiveDocument.recompute()316 obj = Draft.make_sketch(wire, autoconstraints=True)317 App.ActiveDocument.recompute()318 _msg(" 1: Result '{0}' ({1})".format(obj.Shape.ShapeType,319 obj.TypeId))320 self.assertTrue(obj, "'{}' failed".format(operation))321 obj2 = Draft.draftify(obj, delete=False)322 App.ActiveDocument.recompute()323 _msg(" 2: Result '{0}' ({1})".format(obj2.Proxy.Type,324 obj2.TypeId))325 self.assertTrue(obj2, "'{}' failed".format(operation))326 def test_rectangular_array(self):327 """Create a rectangle, and a rectangular array."""328 operation = "Draft OrthoArray"329 _msg(" Test '{}'".format(operation))330 length = 4331 width = 2332 _msg(" Rectangle")333 _msg(" length={0}, width={1}".format(length, width))334 rect = Draft.make_rectangle(length, width)335 App.ActiveDocument.recompute()336 dir_x = Vector(5, 0, 0)337 dir_y = Vector(0, 4, 0)338 dir_z = Vector(0, 0, 6)339 number_x = 3340 number_y = 4341 number_z = 6342 _msg(" Array")343 _msg(" direction_x={}".format(dir_x))344 _msg(" direction_y={}".format(dir_y))345 _msg(" direction_z={}".format(dir_z))346 _msg(" number_x={0}, number_y={1}, number_z={2}".format(number_x,347 number_y,348 number_z))349 obj = Draft.make_ortho_array(rect,350 dir_x, dir_y, dir_z,351 number_x, number_y, number_z)352 self.assertTrue(obj, "'{}' failed".format(operation))353 def test_polar_array(self):354 """Create a rectangle, and a polar array."""355 operation = "Draft PolarArray"356 _msg(" Test '{}'".format(operation))357 length = 4358 width = 2359 _msg(" Rectangle")360 _msg(" length={0}, width={1}".format(length, width))361 rect = Draft.make_rectangle(length, width)362 App.ActiveDocument.recompute()363 center = Vector(-4, 0, 0)364 angle = 180365 number = 5366 _msg(" Array")367 _msg(" number={0}, polar_angle={1}".format(number, angle))368 _msg(" center={}".format(center))369 obj = Draft.make_polar_array(rect,370 number, angle, center)371 self.assertTrue(obj, "'{}' failed".format(operation))372 def test_circular_array(self):373 """Create a rectangle, and a circular array."""374 operation = "Draft CircularArray"375 _msg(" Test '{}'".format(operation))376 length = 4377 width = 2378 _msg(" Rectangle")379 _msg(" length={0}, width={1}".format(length, width))380 rect = Draft.make_rectangle(length, width)381 App.ActiveDocument.recompute()382 rad_distance = 10383 tan_distance = 8384 axis = Vector(0, 0, 1)385 center = Vector(0, 0, 0)386 number = 3387 symmetry = 1388 _msg(" Array")389 _msg(" radial_distance={0}, "390 "tangential_distance={1}".format(rad_distance, tan_distance))391 _msg(" number={0}, symmetry={1}".format(number, symmetry))392 _msg(" axis={}".format(axis))393 _msg(" center={}".format(center))394 obj = Draft.make_circular_array(rect,395 rad_distance, tan_distance,396 number, symmetry,397 axis, center)398 self.assertTrue(obj, "'{}' failed".format(operation))399 def test_path_array(self):400 """Create a wire, a polygon, and a path array."""401 operation = "Draft PathArray"402 _msg(" Test '{}'".format(operation))403 a = Vector(0, 0, 0)404 b = Vector(2, 2, 0)405 c = Vector(2, 4, 0)406 d = Vector(8, 4, 0)407 _msg(" Wire")408 _msg(" a={0}, b={1}".format(a, b))409 _msg(" c={0}, d={1}".format(c, d))410 wire = Draft.make_wire([a, b, c, d])411 n_faces = 3412 radius = 1413 _msg(" Polygon")414 _msg(" n_faces={0}, radius={1}".format(n_faces, radius))415 poly = Draft.make_polygon(n_faces, radius)416 number = 4417 translation = Vector(0, 1, 0)418 align = False419 _msg(" Path Array")420 _msg(" number={}, translation={}".format(number, translation))421 _msg(" align={}".format(align))422 obj = Draft.make_path_array(poly, wire, number, translation, align)423 self.assertTrue(obj, "'{}' failed".format(operation))424 def test_point_array(self):425 """Create a polygon, various point, and a point array."""426 operation = "Draft PointArray"427 _msg(" Test '{}'".format(operation))428 a = Vector(0, 0, 0)429 b = Vector(2, 2, 0)430 c = Vector(2, 4, 0)431 d = Vector(8, 4, 0)432 _msg(" Points")433 _msg(" a={0}, b={1}".format(a, b))434 _msg(" c={0}, d={1}".format(c, d))435 points = [Draft.make_point(a),436 Draft.make_point(b),437 Draft.make_point(c),438 Draft.make_point(d)]439 _msg(" Upgrade")440 add, delete = Draft.upgrade(points)441 compound = add[0]442 n_faces = 3443 radius = 1444 _msg(" Polygon")445 _msg(" n_faces={0}, radius={1}".format(n_faces, radius))446 poly = Draft.make_polygon(n_faces, radius)447 _msg(" Point Array")448 obj = Draft.make_point_array(poly, compound)449 self.assertTrue(obj, "'{}' failed".format(operation))450 def test_clone(self):451 """Create a box, then create a clone of it.452 Test for a bug introduced by changes in attachment code.453 """454 operation = "Draft Clone"455 _msg(" Test '{}'".format(operation))456 box = App.ActiveDocument.addObject("Part::Box")457 App.ActiveDocument.recompute()458 _msg(" object: '{0}' ({1})".format(box.Shape.ShapeType, box.TypeId))459 obj = Draft.make_clone(box)460 _msg(" clone: '{0}' ({1})".format(obj.Proxy.Type, obj.TypeId))461 self.assertTrue(obj, "'{}' failed".format(operation))462 self.assertTrue(obj.hasExtension("Part::AttachExtension"),463 "'{}' failed".format(operation))464 def test_draft_to_drawing(self):465 """Create a solid, and then a projected view in a Drawing page."""466 operation = "Draft Drawing"467 _msg(" Test '{}'".format(operation))468 _wrn(" The Drawing Workbench is obsolete since 0.17,")469 _wrn(" consider using the TechDraw Workbench instead")470 prism = App.ActiveDocument.addObject("Part::Prism")471 prism.Polygon = 5472 # Rotate the prism 45 degrees around the Y axis473 prism.Placement.Rotation.Axis = Vector(0, 1, 0)474 prism.Placement.Rotation.Angle = 45 * (3.14159/180)475 _msg(" Prism")476 _msg(" n_sides={}".format(prism.Polygon))477 _msg(" placement={}".format(prism.Placement))478 svg_template = 'Mod/Drawing/Templates/A3_Landscape.svg'479 template = Draft.get_param("template",480 App.getResourceDir() + svg_template)481 page = App.ActiveDocument.addObject('Drawing::FeaturePage')482 page.Template = template483 _msg(" Drawing view")484 _msg(" page={}".format(page.TypeId))485 _msg(" template={}".format(page.Template))486 obj = Draft.makeDrawingView(prism, page, otherProjection=None)487 self.assertTrue(obj, "'{}' failed".format(operation))488 def test_mirror(self):489 """Create a rectangle, then a mirrored shape."""490 operation = "Draft Mirror"491 _msg(" Test '{}'".format(operation))492 length = 4493 width = 2494 _msg(" Rectangle")495 _msg(" length={0}, width={1}".format(length, width))496 rect = Draft.make_rectangle(length, width)497 # App.ActiveDocument.recompute()498 p1 = Vector(6, -2, 0)499 p2 = Vector(6, 2, 0)500 _msg(" Mirror axis")501 _msg(" p1={}".format(p1))502 _msg(" p2={}".format(p2))503 obj = Draft.mirror(rect, p1, p2)504 self.assertTrue(obj, "'{}' failed".format(operation))505 def test_stretch(self):506 """Stretch a line. NOT IMPLEMENTED."""507 operation = "Draft Stretch"508 _msg(" Test '{}'".format(operation))509 _msg(" This test requires an object and a selection")510 a = Vector(0, 0, 0)511 b = Vector(1, 1, 0)512 _msg(" Line")513 _msg(" a={0}, b={1}".format(a, b))514 line = Draft.make_line(a, b)515 direction = Vector(4, 1, 0)516 Draft.stretch = aux.fake_function517 obj = Draft.stretch(line, direction)518 self.assertTrue(obj, "'{}' failed".format(operation))519 def tearDown(self):520 """Finish the test.521 This is executed after each test, so we close the document.522 """...

Full Screen

Full Screen

allegroCtrl.py

Source:allegroCtrl.py Github

copy

Full Screen

1#%%2import sys3sys.path.append("/Users/user/Downloads/PCAN-Basic API/samples/python")4from PCANBasic import *5from math import pi, degrees, radians6import threading, time, struct7import numpy as np89# CAN Comm. Instance10pcan = PCANBasic()1112# Define CAN Channel13PCAN_CH = PCAN_USBBUS114CAN_ID = 01516# Define Baud-Rate17PCAN_BAUD = PCAN_BAUD_1M1819# Define ID20SET_TORQUE_1 = 0x60+021SET_TORQUE_2 = 0x60+122SET_TORQUE_3 = 0x60+223SET_TORQUE_4 = 0x60+324SET_PERIOD = 0x8125SET_POSE_1 = 0xE0+026SET_POSE_2 = 0xE0+127SET_POSE_3 = 0xE0+228SET_POSE_4 = 0xE0+329CMD_SYS_ON = 0x4030CMD_SYS_OFF = 0x4131FINGER_POS_1 = 0x20+032FINGER_POS_2 = 0x20+133FINGER_POS_3 = 0x20+234FINGER_POS_4 = 0x20+335# ID List36FINGER_IDS = [FINGER_POS_1, FINGER_POS_2, FINGER_POS_3, FINGER_POS_4]37POSE_IDS = [SET_POSE_1, SET_POSE_2, SET_POSE_3, SET_POSE_4]38TORQUE_IDS = [SET_TORQUE_1, SET_TORQUE_2, SET_TORQUE_3, SET_TORQUE_4]3940# Define MSG Type41RTR_MSG = PCAN_MESSAGE_RTR42STD_MSG = PCAN_MESSAGE_STANDARD4344# Define Constant45MAX_BUS = 256 # 25646MAX_DOF = 16 # 1647HZ = 333.348RESOL = 65536.04950# Define PWM Limit for Fingers except Thumb51PWM_LIMIT_ROLL = 250.0 * 1.552PWM_LIMIT_NEAR = 450.0 * 1.553PWM_LIMIT_MID = 300.0 * 1.554PWM_LIMIT_FAR = 190.0 * 1.55556# PWM Limit For Thumb57PWM_LIMIT_T_ROLL = 350.0 * 1.558PWM_LIMIT_T_NEAR = 270.0 * 1.559PWM_LIMIT_T_MID = 180.0 * 1.560PWM_LIMIT_T_FAR = 180.0 * 1.56162# Torque Conversion Constant63TAU_CONV_CONST = 1200.064PWM_ABS_LIMIT = 1200.0656667# Initializing CAN Comm.68res = pcan.Initialize(PCAN_CH, PCAN_BAUD)6970homePos = [ 0, 10, 45, 45,71 0, -10, 45, 45,72 5, -5, 50, 45,73 60, 25, 15, 45]7475""" Define Function """76def cmd_req_finger_pose(_ch, _ind) :77 if _ind == "a" :78 _j = np.zeros((4, 4))79 else :80 _j = np.zeros((1, 4))81 if _ind == "a" :82 for _i, _ID in enumerate(FINGER_IDS) :83 _msg = TPCANMsg()84 _msg.ID = (_ID << 2) | CAN_ID85 _msg.LEN = 086 _msg.MSGTYPE = RTR_MSG87 _res = pcan.Write(_ch, _msg)88 _res = pcan.Read(_ch)89 # if _res[0] != PCAN_ERROR_QRCVEMPTY :90 if _res[1].LEN > 0 :91 # print("LENGTH", _res[1].LEN)92 _data1 = round((_res[1].DATA[0] | (_res[1].DATA[1] << 8))*HZ/RESOL, 2)93 _data2 = round((_res[1].DATA[2] | (_res[1].DATA[3] << 8))*HZ/RESOL, 2)94 _data3 = round((_res[1].DATA[4] | (_res[1].DATA[5] << 8))*HZ/RESOL, 2)95 _data4 = round((_res[1].DATA[6] | (_res[1].DATA[7] << 8))*HZ/RESOL, 2)96 print("FINGER_%s" %(_ID-31), "%6.2f deg" %(_data1), 97 "%6.2f deg" %(_data2), "%6.2f deg" %(_data3), "%6.2f deg" %(_data4))98 _j[_i, 0] = _data199 _j[_i, 1] = _data2100 _j[_i, 2] = _data3101 _j[_i, 3] = _data4102 else :103 _msg = TPCANMsg()104 _ID = FINGER_POS_1105 _msg.ID = (_ID << 2) | CAN_ID106 _msg.LEN = 0107 _msg.MSGTYPE = RTR_MSG108 _res = pcan.Write(_ch, _msg)109 _res = pcan.Read(_ch)110 # if _res[0] != PCAN_ERROR_QRCVEMPTY :111 if _res[1].LEN > 0 :112 # print("LENGTH", _res[1].LEN)113 _data1 = round((_res[1].DATA[0] | (_res[1].DATA[1] << 8))*HZ/RESOL, 2)114 _data2 = round((_res[1].DATA[2] | (_res[1].DATA[3] << 8))*HZ/RESOL, 2)115 _data3 = round((_res[1].DATA[4] | (_res[1].DATA[5] << 8))*HZ/RESOL, 2)116 _data4 = round((_res[1].DATA[6] | (_res[1].DATA[7] << 8))*HZ/RESOL, 2)117 # print("FINGER_%s" %(_ID-31), "%6.2f deg" %(_data1), 118 # "%6.2f deg" %(_data2), "%6.2f deg" %(_data3), "%6.2f deg" %(_data4))119 _j[0, 0] = _data1120 _j[0, 1] = _data2121 _j[0, 2] = _data3122 _j[0, 3] = _data4123 # _j.append(_tmp)124 return _j125126def cmd_set_finger_pose(_ch, _fP) :127 # _fP : Finger Pose Vector128 for _ID in POSE_IDS :129 # MSG Structure130 _msg = TPCANMsg()131 _msg.ID = (_ID << 2) | CAN_ID132 _msg.LEN = 8133 _msg.MSGTYPE = STD_MSG134135 # Finger Pose Set136 _msg.DATA[0] = ((_fP[0]) & 0x00ff)137 _msg.DATA[1] = ((_fP[0] >> 8) & 0x00ff)138139 _msg.DATA[2] = ((_fP[1]) & 0x00ff)140 _msg.DATA[3] = ((_fP[1] >> 8) & 0x00ff)141142 _msg.DATA[4] = ((_fP[2]) & 0x00ff)143 _msg.DATA[5] = ((_fP[2] >> 8) & 0x00ff)144145 _msg.DATA[6] = ((_fP[3]) & 0x00ff)146 _msg.DATA[7] = ((_fP[3] >> 8) & 0x00ff)147148 _ = pcan.Write(_ch, _msg)149150def cmd_set_finger_torque(_ch, _tq, _ind) :151 if _ind == "a" :152 for _ID in TORQUE_IDS :153 # MSG Structure154 _msg = TPCANMsg()155 _msg.ID = (_ID << 2) | CAN_ID156 _msg.LEN = 8157 _msg.MSGTYPE = STD_MSG158159 # Finger Pose Set160 _msg.DATA[0] = ((_tq[0]) & 0x00ff)161 _msg.DATA[1] = ((_tq[0] >> 8) & 0x00ff)162163 _msg.DATA[2] = ((_tq[1]) & 0x00ff)164 _msg.DATA[3] = ((_tq[1] >> 8) & 0x00ff)165166 _msg.DATA[4] = ((_tq[2]) & 0x00ff)167 _msg.DATA[5] = ((_tq[2] >> 8) & 0x00ff)168169 _msg.DATA[6] = ((_tq[3]) & 0x00ff)170 _msg.DATA[7] = ((_tq[3] >> 8) & 0x00ff)171172 _ = pcan.Write(_ch, _msg)173 else :174 # Set 1 Finger175 _msg = TPCANMsg()176 _ID = SET_TORQUE_1177 _msg.ID = (_ID << 2) | CAN_ID178 _msg.LEN = 8179 _msg.MSGTYPE = STD_MSG180181 _msg.DATA[0] = ((_tq[0]) & 0x00ff)182 _msg.DATA[1] = ((_tq[0] >> 8) & 0x00ff)183184 _msg.DATA[2] = ((_tq[1]) & 0x00ff)185 _msg.DATA[3] = ((_tq[1] >> 8) & 0x00ff)186187 _msg.DATA[4] = ((_tq[2]) & 0x00ff)188 _msg.DATA[5] = ((_tq[2] >> 8) & 0x00ff)189190 _msg.DATA[6] = ((_tq[3]) & 0x00ff)191 _msg.DATA[7] = ((_tq[3] >> 8) & 0x00ff)192193 _ = pcan.Write(_ch, _msg)194195def cmd_set_period(_ch) :196 _ID = SET_PERIOD197 _msg = TPCANMsg()198 _msg.ID = (_ID << 2) | CAN_ID199 _msg.LEN = 6200 _period = [3, 0, 0]201 _msg.MSGTYPE = STD_MSG202 _msg.DATA[0] = ((_period[0]) & 0x00ff)203 _msg.DATA[1] = ((_period[0] >> 8) & 0x00ff)204 _msg.DATA[2] = ((_period[1]) & 0x00ff)205 _msg.DATA[3] = ((_period[1] >> 8) & 0x00ff)206 _msg.DATA[4] = ((_period[2]) & 0x00ff)207 _msg.DATA[5] = ((_period[2] >> 8) & 0x00ff)208 _ = pcan.Write(_ch, _msg)209 print("Period Set - Done", _period)210211def cmd_servo_on(_ch) :212 _ID = CMD_SYS_ON213 _msg = TPCANMsg()214 _msg.ID = (_ID << 2) | CAN_ID215 _msg.LEN = 0216 _msg.MSGTYPE = STD_MSG217 _ = pcan.Write(_ch, _msg)218 print("Servo On - Done")219220def cmd_servo_off(_ch) :221 _ID = CMD_SYS_OFF222 _msg = TPCANMsg()223 _msg.ID = (_ID << 2) | CAN_ID224 _msg.LEN = 0225 _msg.MSGTYPE = STD_MSG226 _ = pcan.Write(_ch, _msg)227 print("Servo Off - Done")228229def cmd_hand_preprocess(_ch) :230 cmd_servo_on(_ch)231 print("Hand Ready")232233try :234 # cmd_hand_preprocess(PCAN_CH)235 cmd_set_period(PCAN_CH)236 prev_pos = np.zeros((1, 4))237 cur_pos_filtered = np.zeros((1, 4))238 prev_pos_filtered = np.zeros((1, 4))239 prev_vel = np.zeros((1, 4))240 cur_vel = np.zeros((1, 4))241242 counter = 0243 while abs(prev_pos[0][0]) < 0.01 :244 prev_pos = np.radians(cmd_req_finger_pose(PCAN_CH, "b"))245 counter += 1246 t1 = time.time()247 print(prev_pos, counter)248 while True :249 cur_pos = np.radians(cmd_req_finger_pose(PCAN_CH, "b"))250 if len(cur_pose) > 0 :251 t2 = time.time()252 elapsed = t2 - t1253 if elapsed > 0.005 :254 t1 = t2255 print(cur_pos, prev_pos, elapsed)256 for i in range(len(cur_pos_filtered.shape[1])) :257 cur_pos_filtered[0, i] = 0.6 * cur_pos_filtered[0, i] \258 + 0.198 * prev_pos[0, i] + 0.198 * cur_pos[0, i]259 cur_vel[0, i] = (cur_pos_filtered[0, i] - prev_pos_filtered[0, i])/elapsed260 cur_vel_filtered[0, i] = (0.6 * cur_vel_filtered[0, i]) + \261 + (0.198 * prev_vel[0, i]) + (0.198 * cur_vel[0, i])262 cur_vel[0, i] = (cur_pos[0, i] - prev_pos[0, i])/elapsed263264 # previous attribute update265 prev_pos[0, i] = cur_pos[0, i]266 prev_pos_filtered[0, i] = cur_pos_filtered[0, i]267 prev_vel[0, i] = cur_vel[0, i]268 else :269 pass270 """271 key = input()272 if key == "1" :273 st = time.time()274 cmd_servo_on(PCAN_CH)275 while time.time() - st < 10 :276 desired_torque = [100, -250, 250, 50]277 cmd_set_finger_torque(PCAN_CH, desired_torque, "a")278 elif key == "2" :279 desried_torque = [0, 0, 0, 0]280 cmd_set_finger_torque(PCAN_CH, desired_torque, "a")281 """282except :283 print("Closed")284 cmd_servo_off(PCAN_CH) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful