- ep_chassis.drive_wheels(w1=60, w2=0, w3=0, w4=60)
- time.sleep(16)
- #以下為教學程式
- from robomaster import robot
- import time
-
- ep_robot = robot.Robot()
- ep_robot.initialize(conn_type="ap") #ap , sta兩種連線模式,都要有無線能力
-
- ep_robot.set_robot_mode(mode=robot.CHASSIS_LEAD)
- print('雲台跟隨底盤模式')
-
- ep_chassis = ep_robot.chassis
-
- xx=[]
- yy=[]
- def sub_position_handler(position_info):
- x, y, z = position_info
- xx.append(x)
- yy.append(-y) #符合數學座標方向
-
- ep_chassis.sub_position(freq=10, callback=sub_position_handler)
- print('訂閱position')
-
- print('w1 右前、w2左前、w3左後、w4右後')
- ep_chassis.drive_wheels(w1=60, w2=0, w3=0, w4=60)
- time.sleep(16)
- ep_chassis.drive_wheels(w1=0, w2=0, w3=0, w4=0)
-
- ep_chassis.unsub_position()
- print('停止訂閱position')
-
- ep_chassis.drive_wheels(w1=0, w2=0, w3=0, w4=0)
- ep_robot.close()
-
-
- # 用pyplot繪出行進的軌跡
- import matplotlib.pyplot as plt
-
- plt.plot(xx, yy, 'r+')
- ax = plt.gca() # gets the active axis
- ax.set_aspect(1)
- plt.savefig('trace.png', dpi=300)
- plt.show()
-
沒有留言:
張貼留言