def __init__(self, player: str): self.player = player if self.player == "b": self.robot = Mirobot(portname='/dev/ttyUSB0', debug=False) self.chessPickupZ = 37 else: # self.player == "r" self.robot = Mirobot(portname='/dev/ttyUSB1', debug=False) self.chessPickupZ = 31 self.mapTable = [[[0, 0, self.chessPickupZ] for i in range(1001)] for j in range(1101)] self.CalculateMapTable() self.RobotInit()
from mirobot import Mirobot from time import sleep api = Mirobot(portname='COM5', debug=False) api.home_simultaneous() sleep(1) # above block target_angles = {1: 49.0, 2: 9.5, 3: -3.0, 4: 0.0, 5: 0.0, 6: 0.0} api.set_joint_angle(target_angles, wait=True) # attach block target_angles = {1: 49.0, 2: 54.5, 3: -3.0, 4: 0.0, 5: -51.0, 6: 0.0} api.set_joint_angle(target_angles, wait=True) # suction ON api.pump_on() # above block target_angles = {1: 49.0, 2: 9.5, 3: -3.0, 4: 0.0, 5: 0.0, 6: 0.0} api.set_joint_angle(target_angles, wait=True) # back to zero pos api.go_to_zero() # over chuck target_angles = {1: 0.0, 2: 35.0, 3: 0.0, 4: 0.0, 5: -40.0, 6: 0.0} api.set_joint_angle(target_angles, wait=True) # suction Blow #api.pump_blow() api.pump_off() # back to zero pos ( fin ) api.go_to_zero() #api.pump_off()
''' 气泵控制 ''' from mirobot import Mirobot import time arm = Mirobot(portname='COM7', debug=False) arm.home_simultaneous() # 气泵开启 arm.pump_on() # 等待5s time.sleep(5) # 气泵关闭 arm.pump_off()
#!/usr/bin/env python3 from mirobot import Mirobot # Default for `wait=` is `True`, but explicitly state it here to showcase this. with Mirobot(wait=True) as m: # Mirobot will by default wait for any command because we specified `wait=True` for the class above. m.home_simultaneous() # print our dataclass maintained by Mirobot. Shows the x,y,z,a,b,c coordinates. print(m.cartesian) # increment arm's position using a for-loop for count in range(5): mx = 180.00 my = 0.00 + count * 5 mz = 170 + count * 5 print(f"************Count {count}************") # notice how we don't need any "wait" or "sleep" commands! # the following command will only return when the Mirobot returns 'Ok' and when Mirobot is 'Idle' m.go_to_cartesian_ptp(mx, my, mz) # print our cartesian coordinates again print(m.cartesian)
datas.append(round(data.position[2] * 52.297, 2)) datas.append(round(data.position[3] * 52.297, 2)) datas.append(round(data.position[4] * 52.297, 2)) datas.append(round(data.position[5] * 52.297, 2)) # move when postion change if cmp(self.postion, datas) != 0: self.postion = datas print "change postion to:", self.postion self.m.go_to_axis(self.postion[0], self.postion[1], self.postion[2], self.postion[3], self.postion[4], self.postion[5], 2000) if __name__ == '__main__': m = Mirobot(debug=True) m.connect('/dev/ttyUSB0') # set mirobot to init postion m.home_simultaneous() sleep(15) try: #mirobot control init mirobot_control_node(m) except rospy.ROSInterruptException: pass while True: rospy.spin() sleep(0.1)
from mirobot import Mirobot with Mirobot(portname='COM3', debug=True) as m: m.home_individual() m.go_to_zero()
from mirobot import Mirobot with Mirobot() as m: m.home_simultaneous()
#!/usr/bin/env python3 from mirobot import Mirobot with Mirobot(portname='COM5', debug=False) as m: # Mirobot will by default wait for any command because we specified `wait=True` for the class above. m.home_simultaneous() # print our dataclass maintained by Mirobot. Shows the x,y,z,a,b,c coordinates. print(m.cartesian) # increment arm's position using a for-loop for count in range(5): mx = 180.00 my = 0.00 + count * 5 mz = 170 + count * 5 print(f"************Count {count}************") # notice how we don't need any "wait" or "sleep" commands! # the following command will only return when the Mirobot returns 'Ok' and when Mirobot is 'Idle' m.go_to_cartesian_ptp(mx, my, mz) # print our cartesian coordinates again print(m.cartesian)
Python is more powerful than javascript with the Mirbot, because we have access to more commands, can use multiple Mirobots simultaneously, and even access them from the command line without using the web app at all. We always need to import the Mirobot module in Python before using it! We always need to create the Mirobot object in Python before using it! Basics # Setup in the web app from mirobot import Mirobot # Import the module m = Mirobot() # Create the object to use # Movement m.forward(100) # Move forward by 100 mm m.back(100) m.left(45) # Turn left by 45 degrees m.right(90) # Pen Control m.penup() # Move the pen up m.pendown() # Sensors
''' 机械臂腕关节的位置控制, 点控 point to point ''' from mirobot import Mirobot import time arm = Mirobot(portname='COM7', debug=True) arm.home_simultaneous() print("运动到目标点 A") arm.set_wrist_pose(200, 20, 230) print(f"当前末端在机械臂坐标系下的位姿 {arm.pose}") time.sleep(1) print("运动到目标点 B") arm.set_wrist_pose(200, 20, 150) print(f"当前末端在机械臂坐标系下的位姿 {arm.pose}") time.sleep(1) print("运动到目标点 C, 指定末端的姿态角") arm.set_wrist_pose(150, -20, 230, roll=30.0, pitch=0, yaw=45.0) print(f"当前末端在机械臂坐标系下的位姿 {arm.pose}")
#!/usr/bin/env python3 from mirobot import Mirobot # Default for `wait=` is `True`, but explicitly state it here to showcase this. with Mirobot(wait=True, debug=True) as m: # Mirobot will by default wait for any command because we specified `wait=True` for the class above. m.home_simultaneous() # print our dataclass maintained by Mirobot. Shows the x,y,z,a,b,c coordinates. print(m.cartesian) # increment arm's position using a for-loop for count in range(5): mx = 180.00 my = 0.00 + count * 5 mz = 170 + count * 5 print(f"************Count {count}************") # notice how we don't need any "wait" or "sleep" commands! # the following command will only return when the Mirobot returns 'Ok' and when Mirobot is 'Idle' m.go_to_cartesian_ptp(mx, my, mz) # print our cartesian coordinates again print(m.cartesian)
#!/usr/bin/env python3 from mirobot import Mirobot # Default for `wait=` is `True`, but explicitly state it here to showcase this. with Mirobot(wait=True, debug=True, connection_type='bt') as m: # Mirobot will by default wait for any command because we specified `wait=True` for the class above. m.home_simultaneous() # print our dataclass maintained by Mirobot. Shows the x,y,z,a,b,c coordinates. print(m.cartesian) # increment arm's position using a for-loop for count in range(5): mx = 180.00 my = 0.00 + count * 5 mz = 170 + count * 5 print(f"************Count {count}************") # notice how we don't need any "wait" or "sleep" commands! # the following command will only return when the Mirobot returns 'Ok' and when Mirobot is 'Idle' m.go_to_cartesian_ptp(mx, my, mz) # print our cartesian coordinates again print(m.cartesian)