python数据插补_python 直线插补、圆弧插补、树莓派+步进电机

1 #!usr/bin/env/ python

2 #-*- coding:utf-8 -*-

3 #Author: XiaoFeng

4 importRPi.GPIO as GPIO5 importtime6 importmatplotlib.pyplot as plt7 importnumpy as np8 importthreading9

10

11 #选区GPIO引脚(物理编号pin)

12 PUL_X = 38

13 DIR_X = 40

14 PUL_Y = 35

15 DIR_Y = 33

16 C_X = 3 #1 触碰 X轴接近开关

17 C_Y = 15 #1 触碰 Y轴接近开关

18 #取消异常报错

19 GPIO.setwarnings(False)20 #设置引脚编码方式位物理引脚

21 GPIO.setmode(GPIO.BOARD)22 #设置引脚为输出模式

23 GPIO.setup(PUL_X, GPIO.OUT)24 GPIO.setup(DIR_X, GPIO.OUT)25 GPIO.setup(PUL_Y, GPIO.OUT)26 GPIO.setup(DIR_Y, GPIO.OUT)27 #设置引脚为输入模式

28 GPIO.setup(C_X, GPIO.IN)29 GPIO.setup(C_Y, GPIO.IN)30

31 #方向

32 dir_x = 1

33 dir_y = 1

34 #脉冲频率

35 delay_high = 0.00005

36 delay_low = 0.00005

37 #脉冲数

38 times = 1

39 #工动点

40 Xs =041 Ys =042 #点痕迹

43 point_x =[]44 point_y =[]45 #放大系数

46 k = 3200

47 #限位标志

48 init_x = 1

49 init_y = 1

50 #单边最大行程

51 max_travel = 25

52

53

54 defplot_point():55 """

56 画图57 :return:58 """

59 fig, ax =plt.subplots()60 x =np.divide(point_x, k)61 y =np.divide(point_y, k)62 ax.plot(x, y) #绘制曲线 y1

63 ax.set(xlabel='Distance_X (mm)', ylabel='Distance_Y (mm)',64 title='The trail of the point')65 ax.grid()66 #Move the left and bottom spines to x = 0 and y = 0, respectively.

67 ax.spines["left"].set_position(("data", 0))68 ax.spines["bottom"].set_position(("data", 0))69 #Hide the top and right spines.

70 ax.spines["top"].set_visible(False)71 ax.spines["right"].set_visible(False)72 #坐标轴上加箭头

73 ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False)74 ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False)75 plt.show()76

77

78 defpuls_maker_x():79 """

80 产生脉冲81 :return:82 """

83 #print("xxxxxxx")

84 GPIO.output(DIR_X, dir_x)85 for i inrange(times):86 GPIO.output(PUL_X, 0)87 time.sleep(delay_low)88 GPIO.output(PUL_X, 1)89 time.sleep(delay_high)90

91

92

93 defpuls_maker_y():94 """

95 产生脉冲96 :return:97 """

98 #print("yyyyyy")

99 GPIO.output(DIR_Y, dir_y)100 for i inrange(times):101 GPIO.output(PUL_Y, 0)102 time.sleep(delay_low)103 GPIO.output(PUL_Y, 1)104 time.sleep(delay_high)105

106

107 defline_interpolation(x_e, y_e):108 """

109 直线插补110 :param x_e: 目标X111 :param y_e: 目标Y112 :return:113 """

114 globalXs, Ys115 globaldir_x, dir_y116 globalpoint_x, point_y117 f_line =0118 x =0119 y =0120 delta_x = x_e -Xs121 delta_y = y_e -Ys122 cnt = abs(delta_x) +abs(delta_y)123 if delta_x >0:124 dir_x = 1

125 x = 1

126 #print("右")

127 elif delta_x <0:128 dir_x =0129 x = -1

130 #print("左")

131 elif delta_x == 0 and delta_y >0:132 dir_y = 1<

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值