How to use _sync method in Playwright Python

Best Python code snippet using playwright-python

robot.py

Source:robot.py Github

copy

Full Screen

...28 try:29 return self.get_robot_mode() != RobotState.DISCONNECTED30 except grpc.RpcError:31 return False32 def _sync(self):33 if self._sync_flag:34 self.sync()35 def sync(self) -> None:36 """37 同步,等待指定命令执行完成38 """39 try:40 self.rcs.Sync(Empty())41 except grpc.RpcError:42 pass43 def sleep(self, time: int) -> None:44 """45 等待46 :param time: 等待时间,单位毫秒47 """48 try:49 self.rcs.Sleep(rc.SleepRequest(time=time))50 except grpc.RpcError:51 pass52 def start_sys(self) -> None:53 """54 启动55 """56 # self._sync()57 self.rcs.StartSys(Empty())58 def stop_sys(self) -> None:59 """60 关闭61 """62 # self._sync()63 self.rcs.StopSys(Empty())64 def powerdown(self) -> None:65 """66 关闭电源67 """68 # self._sync()69 self.rcs.PowerDown(Empty())70 def stop(self) -> None:71 """72 停止程序73 """74 # self._sync()75 self.rcs.Stop(Empty())76 def estop(self) -> None:77 """78 急停79 """80 # self._sync()81 self.rcs.EStop(Empty())82 def teach_mode(self) -> None:83 """84 开启示教模式85 """86 self._sync()87 self.rcs.TeachMode(Empty())88 def end_teach_mode(self) -> None:89 """90 关闭示教模式91 """92 self._sync()93 self.rcs.EndTeachMode(Empty())94 def resume(self) -> None:95 """96 恢复机器人97 """98 # self._sync()99 self.rcs.Resume(Empty())100 def pause(self) -> None:101 """102 暂停机器人103 """104 # self._sync()105 self.rcs.Pause(Empty())106 def get_robot_mode(self) -> RobotState:107 """108 获取机器人状态109 :return: 机器人状态110 """111 self._sync()112 res = self.rcs.GetRobotMode(Empty())113 return RobotState(res.mode)114 def get_velocity_factor(self) -> float:115 """116 获取速度因子117 :return: 速度因子118 """119 self._sync()120 res = self.rcs.GetVelocityFactor(Empty())121 return res.value122 def set_velocity_factor(self, factor: float) -> None:123 """124 设置速度因子125 :param factor: 速度因子126 """127 self._sync()128 self.rcs.SetVelocityFactor(rc.Factor(value=factor))129 self._sync()130 def set_gravity(self, x: float = 0, y: float = 0, z: float = -9.8) -> None:131 """132 设置重力133 :param x: 重力X134 :param y: 重力Y135 :param z: 重力Z136 """137 if type(x) is tuple or type(x) is list:138 y = x[1]139 z = x[2]140 x = x[0]141 self._sync()142 self.rcs.SetGravity(msg.Coordinate(x=x, y=y, z=z))143 def get_gravity(self) -> (float, float, float):144 """145 获取重力146 :return: 重力,类型:tuple,(x,y,z)147 """148 self._sync()149 res = self.rcs.GetGravity(Empty())150 return (res.x, res.y, res.z)151 def set_payload(self, x: float = 0, y: float = 0, z: float = -9.8, mass: float = 0) -> None:152 """153 设置负荷154 :param x: 负荷X155 :param y: 负荷Y156 :param z: 负荷Z157 :param mass: 负荷的质量158 """159 if type(x) is tuple:160 if type(y) is not tuple and type(x[0]) is tuple:161 y = x[1]162 x = x[0]163 mass = y164 z = x[2]165 y = x[1]166 x = x[0]167 self._sync()168 self.rcs.SetPayload(msg.Payload(169 mass=mass, cog=msg.Coordinate(x=x, y=y, z=z)))170 def get_payload(self) -> ((float, float, float), float):171 """172 获取负荷173 :return: 负荷信息,类型:tuple,((x, y, z), 负荷的质量)174 """175 self._sync()176 res = self.rcs.GetPayload(Empty())177 return ((res.cog.x, res.cog.y, res.cog.z), res.mass)178 def set_payload_mass(self, mass: float) -> None:179 """180 设置负荷的质量181 :param mass: 负荷的质量182 """183 self._sync()184 self.rcs.SetPayloadMass(msg.PayloadMass(mass=mass))185 def get_payload_mass(self) -> float:186 """187 获取负荷的质量188 :return: 负荷的质量189 """190 self._sync()191 res = self.rcs.GetPayloadMass(Empty())192 return res.mass193 def set_payload_cog(self, x: float = 0, y: float = 0, z: float = 0) -> None:194 """195 设置负荷的质心196 :param x: 质心X197 :param y: 质心Y198 :param z: 质心Z199 """200 if type(x) is tuple or type(x) is list:201 y = x[1]202 z = x[2]203 x = x[0]204 self._sync()205 self.rcs.SetPayloadCog(msg.PayloadCog(206 cog=msg.Coordinate(x=x, y=y, z=z)))207 def get_payload_cog(self) -> (float, float, float):208 """209 获取负荷的质心210 :return: 质心,类型:tuple,(x,y,z)211 """212 self._sync()213 res = self.rcs.GetPayloadCog(Empty())214 return res.cog.x, res.cog.y, res.cog.z215 def set_tcp(self, x: float = 0, y: float = 0, z: float = 0, rz: float = 0, ry: float = 0, rx: float = 0) -> None:216 """217 设置工具中心点(TCP)坐标,坐标值相对于工具坐标系。218 :param x: TCP 坐标 x219 :param y: TCP 坐标 y220 :param z: TCP 坐标 z221 :param rz: 旋转角度 rz222 :param ry: 旋转角度 ry223 :param rx: 旋转角度 rx224 """225 self._sync()226 tcp = CartesianPose(x, y, z, rz, ry, rx)227 self.rcs.SetTcp(tcp._to_PR())228 def get_tcp(self) -> CartesianPose:229 """230 获取TCP231 :return: TCP坐标232 """233 self._sync()234 res = self.rcs.GetTcp(Empty())235 return CartesianPose(res)236 def get_claw_aio(self, pin: str) -> float:237 """238 获取手爪参数239 :param pin: 'force':手爪力,'weight':手爪重量240 :return: 根据参数,获取手爪力或者重量241 示例:242 >>> claw_force = self.get_claw_aio("force")243 >>> claw_weight = self.get_claw_aio("weight")244 """245 self._sync()246 pin = pin.lower()247 if pin == 'force':248 res = self.rcs.GetClawHoldOn(Empty())249 return res.hold_on250 elif pin == 'weight':251 res = self.rcs.GetClawWeight(Empty())252 return res.weight253 else: # pin == 'amplitude':254 res = self.rcs.GetClawAmplitude(Empty())255 return res.amplitude256 def set_claw_aio(self, pin: str, value: float = 0) -> None:257 """258 设置手爪参数259 :param pin: 'force':手爪力,'weight':手爪重量260 :param value: 值261 示例:262 >>> self.set_claw_aio("force",0)263 >>> self.set_claw_aio("weight",1)264 """265 self._sync()266 pin = pin.lower()267 if pin == 'force':268 self.rcs.SetClawForce(rc.Force(force=value))269 else: # pin == 'amplitude':270 self.rcs.SetClawAmplitude(rc.Amplitude(amplitude=value))271 def set_claw(self, force: float = 0, amplitude: float = 0) -> None:272 """273 设置手爪274 :param force: 手爪力275 :param amplitude: 手爪重量276 """277 self._sync()278 self.rcs.SetClawForce(rc.Force(force=force))279 self.rcs.SetClawAmplitude(rc.Amplitude(amplitude=amplitude))280 def movej(self, p: object, a: int = 0, v: int = 0, t: int = 0, r: int = 0, is_joint=None) -> None:281 """282 线性移动(关节空间)283 :p: 传入JointPose或CartesianPose,JointPose` 关节位置,`CartesianPose` 空间位置(将通过运动学反解转为关节位置)284 :a: 主轴的关节加速度 (rad/s)285 :v: 主轴的关节速度 (rad/s)286 :t: 运动时间 (s)287 :r: 交融半径 (m)288 :is_joint: 已弃用289 示例:290 >>> self.movej(JointPose(0, -0.7853981633974483, 1.5707963267948966, -0.7853981633974483, 1.5707963267948966, 0),1.23,1.23)291 """292 if type(p) is not CartesianPose and type(p) is not JointPose:293 raise Exception("请传入 CartesianPose 或 JointPose")294 is_joint = getattr(p, 'is_joint', True)295 if not hasattr(p, 'pos'):296 p = JointPose(*p)297 req = rc.MoveJRequest(298 joint_pose_to=list(p.pos),299 pose_is_joint_angle=is_joint,300 acceleration=a,301 velocity=v,302 time=t,303 blend_radius=r304 )305 if type(p) is CartesianPose:306 p._base_set_PR(req.pose_base)307 self.rcs.MoveJ(req)308 def movel(self, p: object, a: int = 0, v: int = 0, t: int = 0, r: int = 0, is_joint: bool = None) -> None:309 """310 线性移动(工具空间)311 :p: 传入JointPose或CartesianPose,JointPose` 关节位置,`CartesianPose` 空间位置(将通过运动学反解转为关节位置)312 :a: 轴的关节加速度 (rad/s)313 :v: 主轴的关节速度 (rad/s)314 :t: 运动时间 (s)315 :r: 交融半径 (m)316 :is_joint: 已弃用317 示例:318 >>> self.movel(JointPose(0, -0.7853981633974483, 1.5707963267948966, -0.7853981633974483, 1.5707963267948966, 0),1.23,1.23)319 """320 if type(p) is not CartesianPose and type(p) is not JointPose:321 raise Exception("请传入 CartesianPose 或 JointPose")322 is_joint = getattr(p, 'is_joint', False)323 if not hasattr(p, 'pos'):324 p = CartesianPose(*p)325 req = rc.MoveLRequest(326 pose_to=list(p.pos),327 pose_is_joint_angle=is_joint,328 acceleration=a,329 velocity=v,330 time=t,331 blend_radius=r332 )333 if type(p) is CartesianPose:334 p._base_set_PR(req.pose_base)335 self.rcs.MoveL(req)336 def movec(self, via: object, p: object, rad: int = 0, a: int = 0, v: int = 0, t: int = 0, r: int = 0,337 is_joint: bool = None) -> None:338 """339 圆弧移动(工具空间)340 :param via: 途经位置。传入JointPose或CartesianPose,JointPose` 关节位置,`CartesianPose` 空间位置(将通过运动学反解转为关节位置)341 :param p: 目标位置。入JointPose或CartesianPose,JointPose` 关节位置,`CartesianPose` 空间位置(将通过运动学反解转为关节位置)342 :param rad: 路径圆弧的弧度 (rad)343 :param a: 工具空间加速度 (m/s2)344 :param v: 工具空间速度 (m/s)345 :param t: 运动时间 (s)346 :param r: 交融半径 (m)347 :param is_joint: 已弃用348 示例:349 >>> self.movec(JointPose(0.2, 0.5, 0.4, 0, 0, 1.57),CartesianPose(0.1,0.2,0.2,0.3,0.1,0.2),0,1,0.2,0)350 """351 if type(p) is not CartesianPose and type(p) is not JointPose:352 raise Exception("p参数必须是 CartesianPose 或 JointPose 类型")353 if type(via) is not CartesianPose and type(via) is not JointPose:354 raise Exception("via 参数 必须是 CartesianPose 或 JointPose类型")355 if not hasattr(p, 'pos'):356 p = CartesianPose(*p)357 if not hasattr(via, 'pos'):358 via = CartesianPose(*via)359 req = rc.MoveCRequest(360 pose_via=list(via.pos),361 pose_via_is_joint=getattr(via, 'is_joint', True),362 pose_to=list(p.pos),363 pose_to_is_joint=getattr(p, 'is_joint', True),364 acceleration=a,365 velocity=v,366 time=t,367 blend_radius=r,368 rad=rad369 )370 if type(p) is CartesianPose:371 p._base_set_PR(req.pose_base)372 self.rcs.MoveC(req)373 def stop_move(self) -> None:374 """375 停止当前移动376 """377 self.rcs.StopMove(Empty())378 def move_pvat(self, p: list, v: list, a: list, t: float) -> None:379 """380 指定位置、速度、加速度、时间的伺服移动381 :param p: 关节位置列表 (rad),类型:list[float]382 :param v: 关节速度列表 (rad/s),类型:list[float]383 :param a: 关节加速度列表 (rad/s^2),类型:list[float]384 :param t: 总运动时间 (s)385 """386 self.rcs.MovePVAT(rc.PVATRequest(duration=t, q=p, v=v, acc=a))387 def move_pvats(self, pvt_iter: list) -> None:388 """389 move_pvat的流版本390 @param pvt_iter: 类型:list[PVAT]391 @type pvt_iter: list[PVAT]392 """393 self.rcs.MovePVATStream(394 (rc.PVATRequest(duration=s.duration, q=s.q, v=s.v, acc=s.acc) for s in pvt_iter))395 def move_pvt(self, p: list, v: list, t: float) -> None:396 """397 指定位置、速度、时间的伺服移动, 加速度将自动计算。398 :param p: 关节位置列表 (rad),类型:list[float],399 :param v: 关节速度列表 (rad/s),类型:list[float],400 :param t: 总运动时间 (s)401 """402 self.rcs.MovePVT(rc.PVATRequest(duration=t, q=p, v=v))403 def move_pvts(self, pvt_iter: list):404 """405 指定位置、速度、时间的伺服移动, 加速度将自动计算。406 :param pvt_iter: 类型:list[PVAT]407 :return:408 """409 self.rcs.MovePVTStream(410 (rc.PVATRequest(duration=s.duration, q=s.q, v=s.v) for s in pvt_iter))411 def move_pt(self, p: list, t: float) -> None:412 """413 指定位置和时间的伺服移动,速度和加速度将自动计算。414 :param p: 关节位置列表 (rad),类型:list[float]415 :param t: 总运动时间 (s)416 """417 self.rcs.MovePT(rc.PVATRequest(duration=t, q=p))418 def move_pts(self, pt_iter: list) -> None:419 """420 指定位置和时间的伺服移动,速度和加速度将自动计算。421 :param pt_iter: 类型:list[PVAT]422 :return:423 """424 self.rcs.MovePTStream(425 (rc.PVATRequest(duration=s.duration, q=s.q) for s in pt_iter))426 def movej_until(self, p, a=0, v=0, t=0, cb=None) -> None:427 """428 todo: 待实现429 """430 pass431 def movej_until_rt(self, p, a=0, v=0, t=0, logic='AND', io={}, cb=None) -> None:432 """433 todo: 待实现434 """435 pass436 def movel_until(self, p, a=0, v=0, t=0, cb=None) -> None:437 """438 todo: 待实现439 """440 pass441 def movel_until_rt(self, p, a=0, v=0, t=0, logic='AND', io={}, cb=None) -> None:442 """443 todo: 待实现444 """445 pass446 def movec_until(self, via, p, rad=0, a=0, v=0, t=0, cb=None) -> None:447 """448 todo: 待实现449 """450 pass451 def movec_until_rt(self, via, p, rad=0, a=0, v=0, t=0, logic='AND', io={}, cb=None) -> None:452 """453 todo: 待实现454 """455 pass456 def kinematics_forward(self, *p: list) -> CartesianPose:457 """458 机器人正解459 :param p: 关节位置,类型:list[float]460 :return: 空间位置461 示例:462 >>> certesianPose = self.kinematics_forward(JointPose(0, -0.5, math.pi / 6, 0, 0, 0))463 """464 j = JointPose(*p)465 res = self.rcs.KinematicsForward(j._to_Joint())466 return CartesianPose(*res.vector)467 def kinematics_inverse(self, *p: list):468 """469 机器人反解470 :param p: 空间位置,类型:list[float]471 :return: 关节位置472 示例:473 >>> certesianPose = self.kinematics_forward(JointPose(0, -0.5, math.pi / 6, 0, 0, 0))474 >>> jointPose = self.kinematics_inverse(certesianPose)475 """476 j = CartesianPose(*p)477 res = self.rcs.KinematicsInverse(j._to_Vector())478 return JointPose(*res.joints)479 def pose_times(self) -> None:480 """481 todo: 待实现482 """483 pass484 def pose_inverse(self) -> None:485 """486 todo: 待实现487 """488 pass489 def get_actual_joint_positions(self) -> JointPose:490 """491 获取实际关节位置492 :returns: 关节位置493 """494 self._sync()495 res = self.rcs.GetActualJointPositions(Empty())496 return JointPose(*res.joints)497 def get_target_joint_positions(self) -> JointPose:498 """499 获得所有关节的期望角度位置500 :return: 所有关节的期望角度位置501 """502 self._sync()503 res = self.rcs.GetTargetJointPositions(Empty())504 return JointPose(*res.joints)505 def get_actual_joint_speeds(self) -> list:506 """507 获得所有关节的实际角速度508 :return: 所有关节的实际角速度509 """510 self._sync()511 res = self.rcs.GetActualJointSpeeds(Empty())512 return list(res.joints)513 def get_target_joint_speeds(self) -> list:514 """515 获得所有关节的期望角速度516 :return: 所有关节的期望角速度517 """518 self._sync()519 res = self.rcs.GetTargetJointSpeeds(Empty())520 return list(res.joints)521 def get_joint_torques(self) -> list:522 """523 获得每个关节的扭矩值524 :return: 每个关节的扭矩值525 """526 self._sync()527 res = self.rcs.GetJointTorques(Empty())528 return list(res.joints)529 def get_actual_joint_torques(self) -> list:530 """531 获取实际力矩532 :return: 实际力矩533 """534 self._sync()535 res = self.rcs.GetRobotData(Empty())536 return list(res.actualTorque.joints)537 def get_target_joint_torques(self) -> list:538 """539 获取理论力矩540 :return: 理论力矩541 """542 self._sync()543 res = self.rcs.GetRobotData(Empty())544 return list(res.targetTorque.joints)545 def get_joint_temperatures(self) -> list:546 """547 获取关节温度548 :return: 关节温度549 """550 self._sync()551 res = self.rcs.GetRobotData(Empty())552 return list(res.jointTemps.joints)553 def get_joint_temp(self, joint: int) -> float:554 """555 获取关节温度556 :param joint: 关节序号557 :returns: 关节当前温度 (℃)558 """559 self._sync()560 res = self.rcs.GetJointTemp(rc.IntRequest(index=joint))561 return res.degree562 def get_actual_tcp_pose(self) -> CartesianPose:563 """564 获取实际空间位置565 :returns: 空间位置566 """567 self._sync()568 res = self.rcs.GetActualTcpPose(Empty())569 return CartesianPose(*res.vector)570 def get_target_tcp_pose(self) -> CartesianPose:571 """572 获得TCP的期望的姿态/位置573 :return: TCP的期望的姿态/位置574 """575 self._sync()576 res = self.rcs.GetTargetTcpPose(Empty())577 return CartesianPose(*res.vector)578 def get_robot_poses(self) -> RobotPoseData:579 """580 获取机器人姿态信息581 :return: 机器人姿态信息582 """583 self._sync()584 res = self.rcs.GetRobotData(Empty())585 return RobotPoseData(res)586 def get_robot_data(self) -> RobotData:587 """588 获取机器人数据589 :return: 机器人数据590 """591 self._sync()592 res = self.rcs.GetRobotData(Empty())593 return RobotData(res)594 def _generate_robot_data_cmd(self, n=1):595 for i in range(0, n):596 yield rc.RobotDataCmd()597 def get_robot_io_data(self) -> Iterator[RobotIOData]:598 """599 获取机器人IO数据600 :return: 机器人IO数据601 """602 self._sync()603 res = self.rcs.GetRobotIOData(self._generate_robot_data_cmd())604 for io in res:605 yield RobotIOData(io)606 def set_do(self, pin: int, value: int) -> None:607 """608 设置数字输出609 :param pin: 针脚610 :param value: 值611 """612 self._sync()613 self.rcs.SetDIO(msg.DIO(pin=pin, value=value))614 def get_di(self, pin: int) -> int:615 """616 获取数字输入617 :param pin: 针脚618 :return: 数字输入值619 """620 self._sync()621 res = self.rcs.GetDIO(msg.IOPin(pin=pin))622 return res.value623 def set_ao(self, pin: int, value: float) -> None:624 """625 设置模拟输出626 :param pin: 针脚627 :param value: 值628 """629 self._sync()630 self.rcs.SetAIO(msg.AIO(pin=pin, value=value))631 def get_ai(self, pin: int) -> float:632 """633 获取模拟输入634 :param pin: 针脚635 :return: 模拟输入值636 """637 self._sync()638 res = self.rcs.GetAIO(msg.IOPin(pin=pin))639 return res.value640 def set_extra_do(self, pin: int, value: int) -> None:641 """642 设置扩展数字输出643 :param pin: 针脚644 :param value: 值645 """646 self._sync()647 self.rcs.SetExtraDIO(msg.DIO(pin=pin, value=value))648 def get_extra_di(self, pin: int) -> int:649 """650 获取扩展数字输入651 :param pin: 针脚652 :return: 数字输入值653 """654 self._sync()655 res = self.rcs.GetExtraDIO(msg.IOPin(pin=pin))656 return res.value657 def set_extra_ao(self, pin: int, value: float) -> None:658 """659 设置扩展模拟输出660 :param pin: 针脚661 :param value: 值662 """663 self._sync()664 self.rcs.SetExtraAIO(msg.AIO(pin=pin, value=value))665 def get_extra_ai(self, pin: int) -> float:666 """667 获取扩展模拟输入668 :param pin: 针脚669 :return: 模拟输入值670 """671 self._sync()672 res = self.rcs.GetExtraAIO(msg.IOPin(pin=pin))673 return res.value674 def set_ai_mode(self, pin: int, mode: int) -> None:675 """676 设置模拟输入端口工作模式677 :param pin: 针脚678 :param mode: 0:电压,1:电流679 """680 self._sync()681 self.rcs.SetAInMode(msg.AIO(pin=pin, mode=mode))682 def get_ai_mode(self, pin: int) -> int:683 """684 获取模拟输入端口工作模式685 :param pin: 针脚686 """687 self._sync()688 res = self.rcs.GetAInMode(msg.IOPin(pin=pin))689 return res.mode690 def set_ao_mode(self, pin: int, mode: int) -> None:691 """692 设置模拟输出端口工作模式693 :param pin: 针脚694 :param mode: 0:电压,1:电流695 """696 self._sync()697 self.rcs.SetAOutMode(msg.AIO(pin=pin, mode=mode))698 def get_ao_mode(self, pin: int) -> int:699 """700 获取模拟输出端口工作模式701 :param pin: 针脚702 :return: 0:电压,1:电流703 """704 self._sync()705 res = self.rcs.GetAOutMode(msg.IOPin(pin=pin))706 return res.mode707 def set_flange_do(self, pin: int, value: int) -> None:708 """709 设置法兰数字输出710 :param pin: 针脚711 :param value: 值712 """713 self._sync()714 self.rcs.SetTcpDIO(msg.DIO(pin=pin, value=value))715 def get_flange_di(self, pin: int) -> int:716 """717 获取法兰数字输出718 :param pin: 针脚719 :return: 值720 """721 self._sync()722 res = self.rcs.GetTcpDIO(msg.IOPin(pin=pin))723 return res.value724 def set_led(self, mode: int, speed: float, color: list) -> None:725 """726 设置LED灯状态727 :param mode: 1:关闭、2:常亮、3:呼吸、4:均分旋转、5:同色旋转、6:闪烁728 :param speed: 速度 分三个等级,1:快速、2:正常、3:慢速729 :param color: 颜色,最多包含4个 0 ~ 15 之间的整数,类型:list[int]730 """731 self._sync()732 self.rcs.SetLED(rc.LEDStatus(mode=mode, speed=speed, color=color))733 def set_voice(self, voice: int, volume: int) -> None:734 """735 设置声音736 :voice: 声音列表 0~10737 :volume: 音量 分四个等级,0:静音、1:低、2:正常、3:高738 """739 self._sync()740 self.rcs.SetVoice(rc.VoiceStatus(voice=voice, volume=volume))741 def set_fan(self, fan: int) -> None:742 """743 设置风扇744 :param fan: 1:关闭、 2:开启745 """746 self._sync()747 self.rcs.SetFan(rc.FanStatus(fan=fan))748 def set_signal(self, pin: int, value: int) -> None:749 """750 设置信号751 :param pin: 针脚752 :param value: 值753 """754 self._sync()755 self.rcs.SetSignal(rc.SignalValue(index=pin, value=value))756 def get_signal(self, pin: int) -> int:757 """758 获取信号759 :param pin: 针脚760 """761 self._sync()762 res = self.rcs.GetSignal(rc.SignalValue(index=pin))763 return res.value764 def add_signal(self, pin: int, value: int) -> None:765 """766 添加信号767 :pin: 针脚768 :value: 值769 """770 self._sync()771 self.rcs.AddSignal(rc.SignalValue(index=pin, value=value))772 def enable_joint_limits(self) -> None:773 """774 启用关节限位检测775 """776 self._sync()777 self.pcs.EnableJointLimit(pc.TrueOrFalse(val=True))778 def disable_joint_limits(self) -> None:779 """780 关闭关节限位检测781 """782 self._sync()783 self.pcs.EnableJointLimit(pc.TrueOrFalse(val=False))784 def run_scene(self, scene_id: int, execute_count: int = 1, clear: bool = True) -> int:785 """786 运行场景787 :param scene_id: 场景Id788 :param execute_count: 执行数量,0 表示一直循环运行789 :param clear: 是否强制关闭正在运行的任务790 :return: 任务Id791 """792 return self.http_service.run_scene(scene_id, execute_count, clear)['id']793 def rerun_task(self, task_id: int, execute_count: int = 1, clear: bool = True) -> int:794 """795 运行任务796 :param task_id: 任务Id797 :param execute_count: 执行数量,0 表示一直循环运行798 :param clear: 是否强制关闭正在运行的任务799 :return: 任务Id800 """801 return self.http_service.run_task(task_id, execute_count, clear)['id']802 def execute_lua_code(self, task_name: str, code: str, execute_count: int = 1, clear: bool = True) -> int:803 """804 :param task_name: 任务名称805 :param code: lua 代码806 :param execute_count: 执行数量,0 表示一直循环运行807 :param clear: 是否强制关闭正在运行的任务808 :return: 任务Id809 """810 return self.http_service.execute_lua_code(task_name, execute_count, clear, code)['id']811 def get_task(self, id: int) -> Optional[TaskInfo]:812 """813 获取任务信息814 :param id: 任务Id815 :return: 任务信息816 """817 return self.http_service.get_task(id)818 def get_tasks(self, pi: int, ps: int) -> Optional[TasksResult]:819 """820 获取任务列表821 :param pi: 页码822 :param ps: 页大小823 :return: 任务列表824 """825 return self.http_service.get_tasks(pi, ps)826 def record_pvat(self) -> Iterator[rc.PVATRequest]:827 """828 记录PVAT数据点829 """830 # self._sync()831 req = pc.RecordPVATRequest()832 req.type = pc.RecordPVATRequest.PVATType.PVAT833 req.duration = 200834 req.use_duration_ts = True835 req.save_file = False836 req.vZeroGap.remove_gap = False837 req.vZeroGap.threshold = 0.001838 res = self.pcs.RecordPVAT(req)839 for r in res:840 if r.end:841 return842 s = rc.PVATRequest(duration=r.t, q=r.p, v=r.v, acc=r.v)843 yield s844 def stop_record_pvat(self):...

Full Screen

Full Screen

variable.py

Source:variable.py Github

copy

Full Screen

...51 self._names = names or ['x']52 self._kwargs = kwargs or {}53 self._not = not_5455 def _sync(self, f, name, **kwargs):56 kw = {f"{name}.{k}":v for k, v in kwargs.items()}57 return Variable(lambda x: f(self._id(x)), self._names+[name], dict(self._kwargs, **kw), self._not)5859 @property60 def len(self):61 return self._sync(lambda x: len(x), 'len')6263 def in_(self, *v):64 return self._sync(lambda x: x in v, 'in', value=v)6566 def has(self, v):67 return self._sync(lambda x: v in x, 'has', value=v)6869 def inv(self):70 return self._sync(lambda x: not x, 'inv')7172 @property73 def not_(self):74 return Variable(self._id, self._names, self._kwargs, True)7576 @property77 def _verifier(self):78 func = lambda x: self(x)79 names = [n for n in self._names if n]80 if self._not:81 names[1:1] = ['not']82 return Verifier('.'.join(names), func, False, **self._kwargs)8384 def __call__(self, x, context:ValidationContext=None):85 b = bool(self._id(x)) 86 return not b if self._not else b8788 def __getattr__(self, key):89 if key == '__name__':90 return '.'.join(self._names)91 elif key == '__annotations__':92 return {}93 else:94 return self._sync(lambda x: getattr(x, key), f'@{key}')9596 def __getitem__(self, key):97 return self._sync(lambda x: x[key], f'[{key}]')9899 def __eq__(self, v):100 return self._sync(lambda x: x == v, 'eq', value=v)101102 def __ne__(self, v):103 return self._sync(lambda x: x != v, 'ne', value=v)104105 def __lt__(self, th):106 return self._sync(lambda x: x < th, 'lt', value=th)107108 def __le__(self, th):109 return self._sync(lambda x: x <= th, 'le', value=th)110111 def __gt__(self, th):112 return self._sync(lambda x: x > th, 'gt', value=th)113114 def __ge__(self, th):115 return self._sync(lambda x: x >= th, 'ge', value=th)116117 def __add__(self, v):118 return self._sync(lambda x: x + v, 'add', value=v)119120 def __sub__(self, v):121 return self._sync(lambda x: x - v, 'sub', value=v)122123 def __mul__(self, v):124 return self._sync(lambda x: x * v, 'mul', value=v)125126 def __matmul__(self, v):127 return self._sync(lambda x: x @ v, 'matmul', value=v)128129 def __truediv__(self, v):130 return self._sync(lambda x: x / v, 'truediv', value=v)131132 def __floordiv__(self, v):133 return self._sync(lambda x: x // v, 'floordiv', value=v)134135 def __mod__(self, v):136 return self._sync(lambda x: x % v, 'mod', value=v)137138 def __divmod__(self, v):139 return self._sync(lambda x: divmod(x, v), 'divmod', value=v)140141 def __pow__(self, v):142 return self._sync(lambda x: pow(x, v), 'pow', value=v)143144 def __lshift__(self, v):145 return self._sync(lambda x: x << v, 'lshift', value=v)146147 def __rshift__(self, v):148 return self._sync(lambda x: x >> v, 'rshift', value=v)149150 def __and__(self, v):151 return self._sync(lambda x: x & v, 'and', value=v)152153 def __xor__(self, v):154 return self._sync(lambda x: x ^ v, 'xor', value=v)155156 def __or__(self, v):157 return self._sync(lambda x: x | v, 'or', value=v)158159 def __neg__(self):160 return self._sync(lambda x: -x, 'neg')161162 def __pos__(self):163 return self._sync(lambda x: +x, 'pos')164165 def __abs__(self):166 return self._sync(lambda x: abs(x), 'abs')167168 def __invert__(self):169 return self._sync(lambda x: ~x, 'invert')170171 def __round__(self):172 return self._sync(lambda x: round(x), 'round')173174 def __trunc__(self):175 return self._sync(lambda x: math.trunc(x), 'trunc')176177 def __floor__(self):178 return self._sync(lambda x: math.floor(x), 'floor')179180 def __ceil__(self):181 return self._sync(lambda x: math.ceil(x), 'ceil')182183 ...

Full Screen

Full Screen

basic.py

Source:basic.py Github

copy

Full Screen

1from stormed.util import WithFields2properties = [3 ('content_type' , 'shortstr'),4 ('content_encoding' , 'shortstr'),5 ('headers' , 'table'),6 ('delivery_mode' , 'octet'),7 ('priority' , 'octet'),8 ('correlation_id' , 'shortstr'),9 ('reply_to' , 'shortstr'),10 ('expiration' , 'shortstr'),11 ('message_id' , 'shortstr'),12 ('timestamp' , 'timestamp'),13 ('type' , 'shortstr'),14 ('user_id' , 'shortstr'),15 ('app_id' , 'shortstr'),16 ('cluster_id' , 'shortstr'),17]18class Qos(WithFields):19 _name = "basic.qos"20 _class_id = 6021 _method_id = 1022 _sync = True23 _content = False24 _fields = [25 ('prefetch_size' , 'long'),26 ('prefetch_count' , 'short'),27 ('_global' , 'bit'),28 ]29class QosOk(WithFields):30 _name = "basic.qos-ok"31 _class_id = 6032 _method_id = 1133 _sync = False34 _content = False35 _fields = [36 ]37class Consume(WithFields):38 _name = "basic.consume"39 _class_id = 6040 _method_id = 2041 _sync = True42 _content = False43 _fields = [44 ('ticket' , 'short'),45 ('queue' , 'shortstr'),46 ('consumer_tag' , 'shortstr'),47 ('no_local' , 'bit'),48 ('no_ack' , 'bit'),49 ('exclusive' , 'bit'),50 ('nowait' , 'bit'),51 ('arguments' , 'table'),52 ]53class ConsumeOk(WithFields):54 _name = "basic.consume-ok"55 _class_id = 6056 _method_id = 2157 _sync = False58 _content = False59 _fields = [60 ('consumer_tag' , 'shortstr'),61 ]62class Cancel(WithFields):63 _name = "basic.cancel"64 _class_id = 6065 _method_id = 3066 _sync = True67 _content = False68 _fields = [69 ('consumer_tag' , 'shortstr'),70 ('nowait' , 'bit'),71 ]72class CancelOk(WithFields):73 _name = "basic.cancel-ok"74 _class_id = 6075 _method_id = 3176 _sync = False77 _content = False78 _fields = [79 ('consumer_tag' , 'shortstr'),80 ]81class Publish(WithFields):82 _name = "basic.publish"83 _class_id = 6084 _method_id = 4085 _sync = False86 _content = True87 _fields = [88 ('ticket' , 'short'),89 ('exchange' , 'shortstr'),90 ('routing_key' , 'shortstr'),91 ('mandatory' , 'bit'),92 ('immediate' , 'bit'),93 ]94class Return(WithFields):95 _name = "basic.return"96 _class_id = 6097 _method_id = 5098 _sync = False99 _content = True100 _fields = [101 ('reply_code' , 'short'),102 ('reply_text' , 'shortstr'),103 ('exchange' , 'shortstr'),104 ('routing_key' , 'shortstr'),105 ]106class Deliver(WithFields):107 _name = "basic.deliver"108 _class_id = 60109 _method_id = 60110 _sync = False111 _content = True112 _fields = [113 ('consumer_tag' , 'shortstr'),114 ('delivery_tag' , 'longlong'),115 ('redelivered' , 'bit'),116 ('exchange' , 'shortstr'),117 ('routing_key' , 'shortstr'),118 ]119class Get(WithFields):120 _name = "basic.get"121 _class_id = 60122 _method_id = 70123 _sync = True124 _content = False125 _fields = [126 ('ticket' , 'short'),127 ('queue' , 'shortstr'),128 ('no_ack' , 'bit'),129 ]130class GetOk(WithFields):131 _name = "basic.get-ok"132 _class_id = 60133 _method_id = 71134 _sync = False135 _content = True136 _fields = [137 ('delivery_tag' , 'longlong'),138 ('redelivered' , 'bit'),139 ('exchange' , 'shortstr'),140 ('routing_key' , 'shortstr'),141 ('message_count' , 'long'),142 ]143class GetEmpty(WithFields):144 _name = "basic.get-empty"145 _class_id = 60146 _method_id = 72147 _sync = False148 _content = False149 _fields = [150 ('cluster_id' , 'shortstr'),151 ]152class Ack(WithFields):153 _name = "basic.ack"154 _class_id = 60155 _method_id = 80156 _sync = False157 _content = False158 _fields = [159 ('delivery_tag' , 'longlong'),160 ('multiple' , 'bit'),161 ]162class Reject(WithFields):163 _name = "basic.reject"164 _class_id = 60165 _method_id = 90166 _sync = False167 _content = False168 _fields = [169 ('delivery_tag' , 'longlong'),170 ('requeue' , 'bit'),171 ]172class RecoverAsync(WithFields):173 _name = "basic.recover-async"174 _class_id = 60175 _method_id = 100176 _sync = False177 _content = False178 _fields = [179 ('requeue' , 'bit'),180 ]181class Recover(WithFields):182 _name = "basic.recover"183 _class_id = 60184 _method_id = 110185 _sync = True186 _content = False187 _fields = [188 ('requeue' , 'bit'),189 ]190class RecoverOk(WithFields):191 _name = "basic.recover-ok"192 _class_id = 60193 _method_id = 111194 _sync = False195 _content = False196 _fields = [197 ]198class Nack(WithFields):199 _name = "basic.nack"200 _class_id = 60201 _method_id = 120202 _sync = False203 _content = False204 _fields = [205 ('delivery_tag' , 'longlong'),206 ('multiple' , 'bit'),207 ('requeue' , 'bit'),208 ]209id2method = {210 10: Qos,211 11: QosOk,212 20: Consume,213 21: ConsumeOk,214 30: Cancel,215 31: CancelOk,216 40: Publish,217 50: Return,218 60: Deliver,219 70: Get,220 71: GetOk,221 72: GetEmpty,222 80: Ack,223 90: Reject,224 100: RecoverAsync,225 110: Recover,226 111: RecoverOk,227 120: Nack,...

Full Screen

Full Screen

memory.py

Source:memory.py Github

copy

Full Screen

...29 is a thin asynchronous wrapper around that version.30 """31 def __init__(self) -> None:32 self._sync = SyncMemoryBackend()33 def to_sync(self) -> SyncMemoryBackend:34 """Get a synchronous backend with the same underlying data."""35 return self._sync36 @staticmethod37 def from_sync(sync: SyncMemoryBackend) -> 'MemoryBackend':38 """Create an asynchronous backend that shares data with a synchronous one."""39 me = MemoryBackend()40 me._sync = sync41 return me42 async def exists(self, key: bytes) -> bool:43 return key in self._sync44 async def keys(self, filter: bytes) -> List[bytes]:45 return self._sync.keys(filter)46 async def delete(self, key: bytes) -> None:47 self._sync.delete(key)48 async def clear(self) -> None:49 self._sync.clear()50 async def key_type(self, key: bytes) -> Optional[utils.KeyType]:51 return self._sync.key_type(key)...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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