bdmc
This lib is especially designed to control the BDMC drivers, which is under the sales of TechStar.
TODO
Install
Install use pdm
# install pdm
python -m pip install pdm
# config pdm
pdm config pypi.url https://pypi.tuna.tsinghua.edu.cn/simple
# for stable version
pdm add bdmc
# for unstable version
pdm add bdmc -pre
QuickStart
The minimal example is as below.
from bdmc import CloseLoopController, MotorInfo, CMD
motor_seq = (MotorInfo(code_sign=1, direction=1),
MotorInfo(3, 1),
MotorInfo(4, -1),
MotorInfo(2, -1))
port = "tty0"
con = (CloseLoopController(motor_infos=motor_seq, port=port)
.start_msg_sending()
.send_cmd(CMD.RESET))
con.set_motors_speed([100, 200, 300, 400])
(con
.set_motors_speed([100, 200, 300, 400])
.set_motors_speed([1000] * 4)
.set_motors_speed([0] * 4))
(con
.set_motors_speed([100, 200, 300, 400])
.delay(1.2)
.set_motors_speed([1000] * 4)
.delay(3)
.set_motors_speed([0] * 4))
from random import random
(con
.set_motors_speed([100, 200, 300, 400])
.delay_b(delay_sec=1.2, breaker=lambda: random() > 0.8,
check_interval=0.01)
.set_motors_speed([1000] * 4)
.delay_b(3, breaker=lambda: random() > 0.5,
check_interval=0.02)
.set_motors_speed([0] * 4))
match (con
.set_motors_speed([100] * 4)
.delay_b_match(1.2, breaker=lambda: random() > 0.8)):
case True:
con.send_cmd(CMD.FULL_STOP)
case False:
con.set_motors_speed([500] * 4)
case _:
raise ValueError("should never be here")
from random import choice
match (con
.set_motors_speed([100] * 4)
.delay_b_match(1.2, breaker=lambda: choice([0, 0, 1, 2, 3]), check_interval=0.1)):
case 1:
con.send_cmd(CMD.FULL_STOP)
case 2:
con.set_motors_speed([666] * 4)
case 3:
con.set_motors_speed([777] * 4)
case 0:
con.set_motors_speed([555] * 4)
case _:
raise ValueError("should never be here")
use set_log_level
to silent the console to improve the performance in high pressure conditions
from bdmc import set_log_level
"""
Logging DEBUG - Debugging information, used for detailed development phase logs, typically with a value of 10.
Logging INFO - Information message, used to inform the general program running status, with a value of 20.
Logging WARN - A warning message indicating that there may be a problem but the program is still running, with a value of 30.
Logging Error - Error message indicating an issue preventing the program from executing properly, with a value of 40.
Logging CRITICAL - Fatal error message indicating a serious system failure with a value of 50.
"""
set_log_level(50)
from logging import CRITICAL
set_log_level(CRITICAL)