通过串口通讯协议、拖拽积木、Python、C+STM32多种编程方式实现PWM舵机的控制。
PWM模块在开发板的位置图
通过位置图,你可以快速找到PWM模块在开发板的位置。
PWM模块的串口通讯协议
通过串口调试工具发送串口通讯协议实现PWM控制舵机运动。
参数 | 数据类型 | 可用值 | 参数说明 |
---|---|---|---|
channel | int | 0-16 | 通道ID,0为全部 |
start_channel | int | 1-16 | 范围开始通道ID |
end_channel | int | 1-16 | 范围结束通道ID |
rate | int | 50、100、150、200 | 频率,一般为50 |
width | int | 500-2500 | 脉宽,对应运动角度或者正反转 |
// 示例:控制通道1舵机频率为50并转到1500的位置
{"type":"pwm-servo-motion","channel":1,"rate":50,"width":1500}
// 示例:控制通道1-6通道舵机频率为50并转到1500的位置
{"type":"pwm-servo-motion","start_channel":1,"end_channel":6,"rate":50,"width":1500}
PWM模块的拖拽积木
通过拖拽积木调用Python API函数接口实现PWM控制舵机运动。
PWM模块的Python API函数接口
通过Python语言调用Python API函数接口实现PWM控制舵机运动。
参数 | 数据类型 | 可用值 | 参数说明 |
---|---|---|---|
channel | int | 0-16 | 通道ID,0为全部 |
start_channel | int | 1-16 | 范围开始通道ID |
end_channel | int | 1-16 | 范围结束通道ID |
rate | int | 50、100、150、200 | 频率,一般为50 |
width | int | 500-2500 | 脉宽,对应运动角度或者正反转 |
// Python API函数 单个或全部舵机运动控制
robot.board.module.servo.set_servo_motion(channel, rate, width).send()
// 示例:控制通道1舵机频率为50并转到1500的位置
robot.board.module.servo.set_servo_motion(1, 50, 1500).send()
// Python API函数 范围内多个舵机运动控制
robot.board.module.servo.set_servo_range_motion(start_channel, end_channel, rate, width).send()
// 示例:控制通道1-6通道舵机频率为50并转到2000的位置
robot.board.module.servo.set_servo_range_motion(1, 6, 50, 2000).send()
PWM模块的C+STM32函数接口
通过C语言调用开发板SDK函数接口实现PWM控制舵机运动。
参数 | 数据类型 | 可用值 | 参数说明 |
---|---|---|---|
channel | int | 1-16 | 通道ID |
rate | double | 50、100、150、200 | 频率,一般为50 |
width | int | 500-2500 | 脉宽,对应运动角度或者正反转 |
// C API函数 控制单个舵机运动
Pwm_Servo_Motion(int channel, double rate, int width)
// 示例:控制通道1舵机频率为50并转到1500的位置
Pwm_Servo_Motion(1, 50, 1500);