调试更改+挡板电机添加线程和配置文件
This commit is contained in:
@ -33,6 +33,7 @@ custom_config = {
|
||||
'acc': ACC,
|
||||
}
|
||||
|
||||
|
||||
class ServoInterface:
|
||||
def __init__(self, config=None):
|
||||
self.servo_controller = ServoController(config)
|
||||
@ -46,9 +47,11 @@ class ServoInterface:
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"舵机初始化失败:{str(e)}") from e
|
||||
|
||||
|
||||
# 全局变量
|
||||
_Servo = ServoInterface(custom_config)
|
||||
|
||||
|
||||
def _degree_to_raw(degree: int) -> int:
|
||||
"""
|
||||
角度转原始值
|
||||
@ -61,6 +64,7 @@ def _degree_to_raw(degree: int) -> int:
|
||||
|
||||
return max(0, min(raw_value, 4095))
|
||||
|
||||
|
||||
def _raw_to_degree(raw: int) -> float:
|
||||
"""
|
||||
原始值转角度
|
||||
@ -69,6 +73,7 @@ def _raw_to_degree(raw: int) -> float:
|
||||
"""
|
||||
return round(raw * RAW_TO_DEGREE_RATIO, 2)
|
||||
|
||||
|
||||
def set_servo_speed(value: int):
|
||||
"""
|
||||
设置舵机速度
|
||||
@ -82,6 +87,7 @@ def set_servo_speed(value: int):
|
||||
else:
|
||||
raise ValueError("速度值超出限定范围")
|
||||
|
||||
|
||||
def set_servo_acceleration(value: int):
|
||||
"""
|
||||
设置舵机加速度
|
||||
@ -94,6 +100,7 @@ def set_servo_acceleration(value: int):
|
||||
else:
|
||||
raise ValueError("加速度值超出限定范围")
|
||||
|
||||
|
||||
def set_servo_ori_position(ori_position: int):
|
||||
"""
|
||||
设置舵机原点位
|
||||
@ -103,6 +110,7 @@ def set_servo_ori_position(ori_position: int):
|
||||
POS_START = _degree_to_raw(ori_position)
|
||||
print(f"舵机原点位置已设置为:{ori_position}度(对应原始值:{POS_START})")
|
||||
|
||||
|
||||
def set_servo_rot_position(rot_position: int):
|
||||
"""
|
||||
设置舵机翻转位置
|
||||
@ -112,6 +120,7 @@ def set_servo_rot_position(rot_position: int):
|
||||
POS_END = _degree_to_raw(rot_position)
|
||||
print(f"舵机翻转位置已设置为:{rot_position}度(对应原始值:{POS_END})")
|
||||
|
||||
|
||||
def move_to_rot_position():
|
||||
"""舵机旋转到翻转位置"""
|
||||
try:
|
||||
@ -123,6 +132,7 @@ def move_to_rot_position():
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"舵机移动到翻转位置失败:{str(e)}") from e
|
||||
|
||||
|
||||
def move_to_ori_position():
|
||||
"""舵机旋转到原点"""
|
||||
try:
|
||||
@ -134,6 +144,7 @@ def move_to_ori_position():
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"舵机移动到原点位置失败:{str(e)}") from e
|
||||
|
||||
|
||||
# ----------调试接口----------
|
||||
if __name__ == '__main__':
|
||||
set_servo_speed(1500)
|
||||
@ -143,9 +154,9 @@ if __name__ == '__main__':
|
||||
|
||||
move_to_rot_position() # 旋转180度
|
||||
time.sleep(1)
|
||||
move_to_ori_position() # 旋转0度
|
||||
time.sleep(1)
|
||||
# move_to_ori_position() # 旋转0度
|
||||
# time.sleep(1)
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user