电机扩展模块
电机转接模块总共有5个端口:1个UART端口,2个外扩电机端口,2个外扩舵机端口;
注意:多主控通信模块不支持热拔插,使用时请保证可靠连接。
python 编程:
方法
servo_turn_percent(port,value)
设置外扩端口所连舵机的转动角度,port的取值为motor_extension.EX_SERVO_C
、motor_extension.EX_SERVO_D
,value的取值范围为-100 ~ 100
;servo_percent_set(max, min, zero)
设置舵机位置,分别指定最大位置max,最小位置min,零点位置zero 。control_motor_running(port,mode,parameter,left_speed,right_speed)
port可取motor_extension.EX_MOTOR_A`motor_extension.EX_MOTOR_B
如下表:
mode的取值 | parameter | left_speed取值范围 | right_speed取值范围 |
---|---|---|---|
DEFAULT_MODE | 默认模式,参数忽略 | -100~100 | -100~100 |
CONTROL_TIME_MODE | 运行的时间 | -100~100 | -100~100 |
CONTROL_ANGLE_MODE | 转动的角度 | -100~100 | -100~100 |
CONTROL_TURNS_MODE | 转动的圈数 | -100~100 | -100~100 |
motor_control_motor_turnning(mode,parameter,direction,speed)
如下表:
mode的取值 | parameter | direction取值范围 | speed取值范围 |
---|---|---|---|
DEFAULT_MODE | 默认模式,参数忽略 | -100~100 | -100~100 |
CONTROL_TIME_MODE | 运行的时间 | -100~100 | -100~100 |
CONTROL_ANGLE_MODE | 转动的角度 | -100~100 | -100~100 |
CONTROL_TURNS_MODE | 转动的圈数 | -100~100 | -100~100 |
brake(port)
电机刹车,port的取值为motor_extension.EX_MOTOR_A
motor_extension.EX_MOTOR_B
free(port)
电机惯性停止,port的取值为motor_extension.EX_MOTOR_A
motor_extension.EX_MOTOR_B
get_rotate_angle(port)
获取电机旋转角度,port的取值为motor_extension.EX_MOTOR_A
motor_extension.EX_MOTOR_B
clear_rotate_angle(port)
电机旋转角度清零,port的取值为motor_extension.EX_MOTOR_A
motor_extension.EX_MOTOR_B
get_speed(port)
获取电机速度,port的取值为motor_extension.EX_MOTOR_A
motor_extension.EX_MOTOR_B
编程示范
from thunbot import motor_extension
# 外扩舵机控制
motor_extension.servo_turn_percent(motor_extension.EX_SERVO_C,90)
motor_extension.servo_turn_percent(motor_extension.EX_SERVO_D,-80)
motor_extension.servo_turn_percent(motor_extension.EX_SERVO_C | motor_extension.EX_SERVO_D,90,-80)
motor_extension.servo_percent_set(motor_extension.EX_SERVO_C,90,-80,10)
# 外扩电机控制
motor_extension.control_motor_running(motor_extension.EX_MOTOR_A, motor_extension.DEFAULT_MODE, 0x00, 20)
motor_extension.control_motor_running(motor_extension.EX_MOTOR_A | motor_extension.EX_MOTOR_B, motor_extension.DEFAULT_MODE, 0x00, -100)
motor_extension.control_motor_turnning(motor_extension.CONTROL_TIME_MODE,10,0,-30)
motor_extension.free(motor_extension.EX_MOTOR_A)
motor_extension.brake(motor_extension.EX_MOTOR_A)
motor_extension.get_speed(motor_extension.EX_MOTOR_A)
motor_extension.get_rotate_angle(motor_extension.EX_MOTOR_A)
motor_extension.clear_rotate_angle(motor_extension.EX_MOTOR_A)
motor_extension.get_run_flag()