Skip to content

Commit 9dcec60

Browse files
committed
switched the servo driver to FTServo_Arduino
1 parent ae18836 commit 9dcec60

26 files changed

Lines changed: 1896 additions & 1766 deletions

src/M5StackChan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#include "M5StackChan.h"
77
#include "drivers/PY32IOExpander/PY32IOExpander.hpp"
8-
#include "drivers/SCServo_lib/src/SCSCL.h"
8+
#include "drivers/FTServo_Arduino/src/SCSCL.h"
99
#include "utils/compat/make_unique.h"
1010
#include "utils/settings/settings.h"
1111
#include "utility/power/INA226_Class.hpp"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 ftservo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# FEETECH BUS Servo
2+
3+
> FEETECH BUS Servo library for Arduino and ESP32
4+
5+
## Table of Contents
6+
7+
<!-- TOC -->
8+
* [FEETECH BUS Servo](#ft-series-servo)
9+
* [Table of Contents](#table-of-contents)
10+
* [Requirements](#requirements)
11+
* [Usage](#usage)
12+
* [Notes](#notes)
13+
* [Release](#release)
14+
<!-- TOC -->
15+
16+
## Requirements
17+
18+
* arduino-1.6.10 or newer(https://www.arduino.cc/).
19+
20+
## Usage
21+
22+
For usage examples, see the [examples](./examples) directory.
23+
24+
## Notes
25+
26+
The code for the `SCServo` library is divided into the following
27+
parts:
28+
29+
* communication layer: [src/SCS.cpp](src/SCS.cpp)
30+
* hardware interface layer: [src/SCSerial.cpp](src/SCSerial.cpp)
31+
* application layer:
32+
* corresponds to the three series of FEETECH BUS Servo
33+
* `SCSCL` application layer program: [src/SCSCL.h](src/SCSCL.h) and [src/SCSCL.cpp](src/SCSCL.cpp)
34+
* `SMS` and `STS` application layer program: [src/SMS_STS.h](src/SMS_STS.h) and [src/SMS_STS.cpp](src/SMS_STS.cpp)
35+
* `HLS` application layer program: [src/HLSCL.h](src/HLSCL.h) and [src/HLSCL.cpp](src/HLSCL.cpp)
36+
* instruction definition header file: [src/INST.h](src/INST.h)
37+
* communication layer program: [src/SCS.h](src/SCS.h) and [src/SCS.cpp](src/SCS.cpp)
38+
* hardware interface program: [src/SCSerial.h](src/SCSerial.h) and [src/SCSerial.cpp](src/SCSerial.cpp)
39+
40+
Note that there are differences in the memory table definitions of different series of FEETECH BUS servos.
41+
42+
## Release
43+
44+
New (GitHub) releases of this library are automatically ingressed by the Arduino Library Manager.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# see https://arduino.github.io/arduino-cli/1.0/library-specification/#library-metadata
2+
3+
name=FTServo
4+
version=2.0.0
5+
author=ftservo
6+
maintainer=FEETECH <github.com/ftservo>
7+
sentence=FEETECH BUS Servo library for Arduino and ESP32
8+
paragraph=This library is compatible with all series of FEETECH BUS Servo
9+
category=Other
10+
url=https://github.com/ftservo/FTServo_Arduino
11+
architectures=*
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/*
2+
* HLSCL.cpp
3+
* 飞特HTS/HLS系列串行舵机应用层程序
4+
* 日期: 2024.11.21
5+
* 作者: txl
6+
*/
7+
8+
#include "HLSCL.h"
9+
10+
HLSCL::HLSCL()
11+
{
12+
End = 0;
13+
}
14+
15+
HLSCL::HLSCL(u8 End):SCSerial(End)
16+
{
17+
}
18+
19+
HLSCL::HLSCL(u8 End, u8 Level):SCSerial(End, Level)
20+
{
21+
}
22+
23+
int HLSCL::WritePosEx(u8 ID, s16 Position, u16 Speed, u8 ACC, u16 Torque)
24+
{
25+
if(Position<0){
26+
Position = -Position;
27+
Position |= (1<<15);
28+
}
29+
u8 bBuf[7];
30+
bBuf[0] = ACC;
31+
Host2SCS(bBuf+1, bBuf+2, Position);
32+
Host2SCS(bBuf+3, bBuf+4, Torque);
33+
Host2SCS(bBuf+5, bBuf+6, Speed);
34+
35+
return genWrite(ID, HLSCL_ACC, bBuf, 7);
36+
}
37+
38+
int HLSCL::RegWritePosEx(u8 ID, s16 Position, u16 Speed, u8 ACC, u16 Torque)
39+
{
40+
if(Position<0){
41+
Position = -Position;
42+
Position |= (1<<15);
43+
}
44+
u8 bBuf[7];
45+
bBuf[0] = ACC;
46+
Host2SCS(bBuf+1, bBuf+2, Position);
47+
Host2SCS(bBuf+3, bBuf+4, Torque);
48+
Host2SCS(bBuf+5, bBuf+6, Speed);
49+
50+
return regWrite(ID, HLSCL_ACC, bBuf, 7);
51+
}
52+
53+
void HLSCL::SyncWritePosEx(u8 ID[], u8 IDN, s16 Position[], u16 Speed[], u8 ACC[], u16 Torque[])
54+
{
55+
u8 offbuf[7*IDN];
56+
for(u8 i = 0; i<IDN; i++){
57+
if(Position[i]<0){
58+
Position[i] = -Position[i];
59+
Position[i] |= (1<<15);
60+
}
61+
if(ACC){
62+
offbuf[i*7] = ACC[i];
63+
}else{
64+
offbuf[i*7] = 0;
65+
}
66+
Host2SCS(offbuf+i*7+1, offbuf+i*7+2, Position[i]);
67+
Host2SCS(offbuf+i*7+3, offbuf+i*7+4, Torque[i]);
68+
Host2SCS(offbuf+i*7+5, offbuf+i*7+6, Speed[i]);
69+
}
70+
syncWrite(ID, IDN, HLSCL_ACC, offbuf, 7);
71+
}
72+
73+
void HLSCL::SyncWriteSpe(u8 ID[], u8 IDN, s16 Speed[], u8 ACC[], u16 Torque[])
74+
{
75+
u8 offbuf[7*IDN];
76+
for(u8 i = 0; i<IDN; i++){
77+
if(Speed[i]<0){
78+
Speed[i] = -Speed[i];
79+
Speed[i] |= (1<<15);
80+
}
81+
if(ACC){
82+
offbuf[i*7] = ACC[i];
83+
}else{
84+
offbuf[i*7] = 0;
85+
}
86+
Host2SCS(offbuf+i*7+1, offbuf+i*7+2, 0);
87+
Host2SCS(offbuf+i*7+3, offbuf+i*7+4, Torque[i]);
88+
Host2SCS(offbuf+i*7+5, offbuf+i*7+6, Speed[i]);
89+
}
90+
syncWrite(ID, IDN, HLSCL_ACC, offbuf, 7);
91+
}
92+
93+
int HLSCL::WheelMode(u8 ID)
94+
{
95+
return writeByte(ID, HLSCL_MODE, 1);
96+
}
97+
98+
int HLSCL::EleMode(u8 ID)
99+
{
100+
return writeByte(ID, HLSCL_MODE, 2);
101+
}
102+
103+
int HLSCL::WriteSpe(u8 ID, s16 Speed, u8 ACC, u16 Torque)
104+
{
105+
if(Speed<0){
106+
Speed = -Speed;
107+
Speed |= (1<<15);
108+
}
109+
u8 bBuf[7];
110+
bBuf[0] = ACC;
111+
Host2SCS(bBuf+1, bBuf+2, 0);
112+
Host2SCS(bBuf+3, bBuf+4, Torque);
113+
Host2SCS(bBuf+5, bBuf+6, Speed);
114+
115+
return genWrite(ID, HLSCL_ACC, bBuf, 7);
116+
}
117+
118+
int HLSCL::WriteEle(u8 ID, s16 Torque)
119+
{
120+
if(Torque<0){
121+
Torque = -Torque;
122+
Torque |= (1<<15);
123+
}
124+
return writeWord(ID, HLSCL_GOAL_TORQUE_L, Torque);
125+
}
126+
127+
int HLSCL::EnableTorque(u8 ID, u8 Enable)
128+
{
129+
return writeByte(ID, HLSCL_TORQUE_ENABLE, Enable);
130+
}
131+
132+
int HLSCL::unLockEprom(u8 ID)
133+
{
134+
EnableTorque(ID, 0);
135+
return writeByte(ID, HLSCL_LOCK, 0);
136+
}
137+
138+
int HLSCL::LockEprom(u8 ID)
139+
{
140+
return writeByte(ID, HLSCL_LOCK, 1);
141+
}
142+
143+
int HLSCL::CalibrationOfs(u8 ID)
144+
{
145+
EnableTorque(ID, 0);
146+
unLockEprom(ID);
147+
return Recal(ID);
148+
}
149+
150+
int HLSCL::FeedBack(int ID)
151+
{
152+
int nLen = Read(ID, HLSCL_PRESENT_POSITION_L, Mem, sizeof(Mem));
153+
if(nLen!=sizeof(Mem)){
154+
return -1;
155+
}
156+
return nLen;
157+
}
158+
159+
int HLSCL::ReadPos(int ID)
160+
{
161+
int Pos = -1;
162+
if(ID==-1){
163+
Pos = Mem[HLSCL_PRESENT_POSITION_H-HLSCL_PRESENT_POSITION_L];
164+
Pos <<= 8;
165+
Pos |= Mem[HLSCL_PRESENT_POSITION_L-HLSCL_PRESENT_POSITION_L];
166+
}else{
167+
Pos = readWord(ID, HLSCL_PRESENT_POSITION_L);
168+
}
169+
if(Pos&(1<<15)){
170+
Pos = -(Pos&~(1<<15));
171+
}
172+
173+
return Pos;
174+
}
175+
176+
int HLSCL::ReadSpeed(int ID)
177+
{
178+
int Speed = -1;
179+
if(ID==-1){
180+
Speed = Mem[HLSCL_PRESENT_SPEED_H-HLSCL_PRESENT_POSITION_L];
181+
Speed <<= 8;
182+
Speed |= Mem[HLSCL_PRESENT_SPEED_L-HLSCL_PRESENT_POSITION_L];
183+
}else{
184+
Speed = readWord(ID, HLSCL_PRESENT_SPEED_L);
185+
}
186+
if(Speed&(1<<15)){
187+
Speed = -(Speed&~(1<<15));
188+
}
189+
return Speed;
190+
}
191+
192+
int HLSCL::ReadLoad(int ID)
193+
{
194+
int Load = -1;
195+
if(ID==-1){
196+
Load = Mem[HLSCL_PRESENT_LOAD_H-HLSCL_PRESENT_POSITION_L];
197+
Load <<= 8;
198+
Load |= Mem[HLSCL_PRESENT_LOAD_L-HLSCL_PRESENT_POSITION_L];
199+
}else{
200+
Load = readWord(ID, HLSCL_PRESENT_LOAD_L);
201+
}
202+
if(Load&(1<<10)){
203+
Load = -(Load&~(1<<10));
204+
}
205+
return Load;
206+
}
207+
208+
int HLSCL::ReadVoltage(int ID)
209+
{
210+
int Voltage = -1;
211+
if(ID==-1){
212+
Voltage = Mem[HLSCL_PRESENT_VOLTAGE-HLSCL_PRESENT_POSITION_L];
213+
}else{
214+
Voltage = readByte(ID, HLSCL_PRESENT_VOLTAGE);
215+
}
216+
return Voltage;
217+
}
218+
219+
int HLSCL::ReadTemper(int ID)
220+
{
221+
int Temper = -1;
222+
if(ID==-1){
223+
Temper = Mem[HLSCL_PRESENT_TEMPERATURE-HLSCL_PRESENT_POSITION_L];
224+
}else{
225+
Temper = readByte(ID, HLSCL_PRESENT_TEMPERATURE);
226+
}
227+
return Temper;
228+
}
229+
230+
int HLSCL::ReadMove(int ID)
231+
{
232+
int Move = -1;
233+
if(ID==-1){
234+
Move = Mem[HLSCL_MOVING-HLSCL_PRESENT_POSITION_L];
235+
}else{
236+
Move = readByte(ID, HLSCL_MOVING);
237+
}
238+
return Move;
239+
}
240+
241+
int HLSCL::ReadCurrent(int ID)
242+
{
243+
int Current = -1;
244+
if(ID==-1){
245+
Current = Mem[HLSCL_PRESENT_CURRENT_H-HLSCL_PRESENT_POSITION_L];
246+
Current <<= 8;
247+
Current |= Mem[HLSCL_PRESENT_CURRENT_L-HLSCL_PRESENT_POSITION_L];
248+
}else{
249+
Current = readWord(ID, HLSCL_PRESENT_CURRENT_L);
250+
}
251+
if(Current&(1<<15)){
252+
Current = -(Current&~(1<<15));
253+
}
254+
return Current;
255+
}
256+
257+
int HLSCL::ServoMode(u8 ID)
258+
{
259+
return writeByte(ID, HLSCL_MODE, 0);
260+
}

0 commit comments

Comments
 (0)