This repository has been archived on 2025-04-02. You can view files and clone it, but cannot push or open issues or pull requests.
controller-hart/Tests/test.py

47 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
import matplotlib.pyplot as plt
class SCurveGenerator:
def __init__(self, start, end):
self.start = start
self.end = end
self.current = start
self.t = np.linspace(0, 1, 100) # 用于生成S曲线的参数
self.index = 0
def generate_point(self):
if self.current >= self.end:
return None
# 修改后的S曲线公式使中间部分陡峭两边较慢
s_curve_value = self.start + (self.end - self.start) * (10 * self.t**3 - 15 * self.t**4 + 6 * self.t**5)
point = s_curve_value[self.index]
self.index += 1
self.current = self.start + (self.end - self.start) * (self.index / 100)
return point
# 初始化起点和终点
start = 25
end = 50
# 创建S曲线生成器
s_curve_generator = SCurveGenerator(start, end)
# 保存数据点的数组
data_points = []
# 外部周期调用生成数据点
while True:
point = s_curve_generator.generate_point()
if point is None:
break
data_points.append(point)
# 生成图表
plt.plot(data_points)
plt.title('S Curve')
plt.xlabel('Step')
plt.ylabel('Value')
plt.show()