更新 servo 库
This commit is contained in:
parent
575b6cefaf
commit
a61ce72cd0
@ -71,16 +71,17 @@ void Servo::StopActionGroup(void)
|
|||||||
* Return: 无返回
|
* Return: 无返回
|
||||||
* Others:
|
* Others:
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
void Servo::SetActionGroupSpeed(uint8_t action_num, uint16_t speed)
|
void Servo::SetActionGroupSpeed(uint8_t action_num, double speed)
|
||||||
{
|
{
|
||||||
|
uint16_t speed_int = (uint16_t)speed;
|
||||||
uint8_t buf[7];
|
uint8_t buf[7];
|
||||||
buf[0] = FRAME_HEADER; //填充帧头
|
buf[0] = FRAME_HEADER; //填充帧头
|
||||||
buf[1] = FRAME_HEADER;
|
buf[1] = FRAME_HEADER;
|
||||||
buf[2] = 5; //数据长度,数据帧除帧头部分数据字节数,此命令固定为5
|
buf[2] = 5; //数据长度,数据帧除帧头部分数据字节数,此命令固定为5
|
||||||
buf[3] = CMD_ACTION_GROUP_SPEED; //填充设置动作组速度命令
|
buf[3] = CMD_ACTION_GROUP_SPEED; //填充设置动作组速度命令
|
||||||
buf[4] = action_num; //填充要设置的动作组号
|
buf[4] = action_num; //填充要设置的动作组号
|
||||||
buf[5] = GET_LOW_BYTE(speed); //获得目标速度的低八位
|
buf[5] = GET_LOW_BYTE(speed_int); //获得目标速度的低八位
|
||||||
buf[6] = GET_HIGH_BYTE(speed); //获得目标熟读的高八位
|
buf[6] = GET_HIGH_BYTE(speed_int); //获得目标熟读的高八位
|
||||||
|
|
||||||
SerialX->write(buf, 7); //发送数据帧
|
SerialX->write(buf, 7); //发送数据帧
|
||||||
}
|
}
|
||||||
@ -93,14 +94,14 @@ void Servo::SetActionGroupSpeed(uint8_t action_num, uint16_t speed)
|
|||||||
* Return: 无返回
|
* Return: 无返回
|
||||||
* Others:
|
* Others:
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
void Servo::SetAllActionGroupSpeed(uint16_t speed)
|
void Servo::SetAllActionGroupSpeed(double speed)
|
||||||
{
|
{
|
||||||
SetActionGroupSpeed(0xFF, speed); //调用动作组速度设定,组号为0xFF时设置所有组的速度
|
SetActionGroupSpeed(0xFF, speed); //调用动作组速度设定,组号为0xFF时设置所有组的速度
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//恢复初始状态,指定速度
|
//恢复初始状态,指定速度
|
||||||
void Servo::Reset(uint16_t speed)
|
void Servo::Reset(double speed)
|
||||||
{
|
{
|
||||||
SetActionGroupSpeed(ACTION_RESET_NUM, speed);
|
SetActionGroupSpeed(ACTION_RESET_NUM, speed);
|
||||||
RunActionGroup(ACTION_RESET_NUM, 1);
|
RunActionGroup(ACTION_RESET_NUM, 1);
|
||||||
@ -109,7 +110,7 @@ void Servo::Reset(uint16_t speed)
|
|||||||
|
|
||||||
|
|
||||||
//抓取,指定速度
|
//抓取,指定速度
|
||||||
void Servo::Catch(uint16_t speed)
|
void Servo::Catch(double speed)
|
||||||
{
|
{
|
||||||
SetActionGroupSpeed(ACTION_CATCH_NUM, speed);
|
SetActionGroupSpeed(ACTION_CATCH_NUM, speed);
|
||||||
RunActionGroup(ACTION_CATCH_NUM, 1);
|
RunActionGroup(ACTION_CATCH_NUM, 1);
|
||||||
@ -118,7 +119,7 @@ void Servo::Catch(uint16_t speed)
|
|||||||
|
|
||||||
|
|
||||||
//释放,指定速度
|
//释放,指定速度
|
||||||
void Servo::Release(uint16_t speed)
|
void Servo::Release(double speed)
|
||||||
{
|
{
|
||||||
SetActionGroupSpeed(ACTION_RELEASE_NUM, speed);
|
SetActionGroupSpeed(ACTION_RELEASE_NUM, speed);
|
||||||
RunActionGroup(ACTION_RELEASE_NUM, 1);
|
RunActionGroup(ACTION_RELEASE_NUM, 1);
|
||||||
@ -127,7 +128,7 @@ void Servo::Release(uint16_t speed)
|
|||||||
|
|
||||||
|
|
||||||
//停止舵机并恢复初始状态,指定速度
|
//停止舵机并恢复初始状态,指定速度
|
||||||
void Servo::StopAndReset(uint16_t speed)
|
void Servo::StopAndReset(double speed)
|
||||||
{
|
{
|
||||||
StopActionGroup();
|
StopActionGroup();
|
||||||
Reset(speed);
|
Reset(speed);
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
|
|
||||||
//默认动作组速度
|
//默认动作组速度
|
||||||
#define SERVO_NORMAL_SPEED 100
|
#define SERVO_NORMAL_SPEED 1.0
|
||||||
|
|
||||||
|
|
||||||
class Servo
|
class Servo
|
||||||
@ -33,13 +33,13 @@ public:
|
|||||||
|
|
||||||
void RunActionGroup(uint8_t action_num, uint16_t times);
|
void RunActionGroup(uint8_t action_num, uint16_t times);
|
||||||
void StopActionGroup(void);
|
void StopActionGroup(void);
|
||||||
void SetActionGroupSpeed(uint8_t action_num, uint16_t speed);
|
void SetActionGroupSpeed(uint8_t action_num, double speed);
|
||||||
void SetAllActionGroupSpeed(uint16_t speed);
|
void SetAllActionGroupSpeed(double speed);
|
||||||
|
|
||||||
void Reset(uint16_t speed = SERVO_NORMAL_SPEED); //恢复初始状态,指定速度
|
void Reset(double speed = SERVO_NORMAL_SPEED); //恢复初始状态,指定速度
|
||||||
void Catch(uint16_t speed = SERVO_NORMAL_SPEED); //抓取,指定速度
|
void Catch(double speed = SERVO_NORMAL_SPEED); //抓取,指定速度
|
||||||
void Release(uint16_t speed = SERVO_NORMAL_SPEED); //释放,指定速度
|
void Release(double speed = SERVO_NORMAL_SPEED); //释放,指定速度
|
||||||
void StopAndReset(uint16_t speed = SERVO_NORMAL_SPEED); //停止舵机并恢复初始状态,指定速度
|
void StopAndReset(double speed = SERVO_NORMAL_SPEED); //停止舵机并恢复初始状态,指定速度
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HardwareSerial *SerialX;
|
HardwareSerial *SerialX;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user