Somebody else's protocol, tested on your laptop
You will: Test framing, checksums and failure handling of the servo bus with no servo attached.
Builds on The servo is the driver.
The SO-101's servos speak Feetech's protocol, not one this project designed:
instruction FF FF ID LEN INSTR PARAM... CHK
status FF FF ID LEN ERROR PARAM... CHK
LEN = number of PARAM bytes + 2
CHK = ~(ID + LEN + INSTR + PARAM...) & 0xFF
Somebody else's protocol is the normal case in robotics, and it changes what testing means. You cannot change the other end, and you cannot compile your code into it. The only way to be wrong is to have misread the manual. So the job is to read it once, carefully, write down what you understood as tests, and make the code agree with them.
Two kinds of test, for two different mistakes. Packets worked out by hand: a ping to servo 1, a read of its position, a synchronised write to two servos, each written out byte by byte from the published layout and compared with what the code builds. Those catch the code disagreeing with the reading. A simulated bus: six STS3215s in software, which the hardware interface can be run against in every test and in the whole stack. Those catch the interface mishandling a servo: a missing one, a slow one, a reply split across two reads.
Be precise about what the second kind proves. The simulated bus was written from the same reading of the protocol as the driver, and it includes the same header: it frames, checks and parses with the same functions. Where the reading is wrong, both are wrong the same way, and they agree. This lesson has you plant exactly that — the checksum's complement, forgotten — and watch the simulated bus and every interface test stay green while the hand-worked packets go red. A real servo would reject every packet.
So the hand-worked tests are the ones standing between a misreading and the bench, and even they only check the reading against itself. A register address read off the wrong row, or a sign bit in the wrong place, would pass everything here. The first session on the physical arm is planned to catch those: a wrong voltage register shows up as a servo claiming 200 V.
In the simulation
Work packets out by hand, then check them against the servo bus view, which builds the sync write from the profile: goal count = 2048 + radians × 651.9, little-endian, low byte first. This is the hand-worked test, done in the page.
Kinematic: joints move at their real speed limit, but there is no gravity, no load and no physics. That is what the steps below are for.
The SO-101 loads as you reach it.
make drive keysIn this lesson
- Open Inspect, then servo bus. Find the broadcast id
FE, the instruction83and the goal register2A. - Home the arm with
hand read servo 1's two goal bytes. Before you look: count 2048 is0x0800, so which byte comes first? - Work out
elbow_flex's goal at its lower limit, −1.69 rad, as a count and as two bytes. Then drive it there and check. - Take
shoulder_liftpast −90°, where its goal falls below 1024 and its high byte below04.
Joints · SO-101 follower
1–5 joint · , . jog · [ ] jaw · - + step · h home · f frames
the keys of make drive
The buttons do what the keys do: hold one to repeat.
Limits from the description; speed capped at 1.7434 rad/s, the servo's datasheet derated. Poses from the profile.
Inspector
Code
The repository's own code behind what you do here appears once you move the arm.
Do it
Read the wire format, as the header writes it down.
sed -n 16,50p src/threevn_hardware/include/threevn_hardware/feetech_protocol.hppWork out a ping to servo 1 by hand before you look: header, id, length, instruction
01, checksum. Then compare.grep -n -A6 "TEST(Encode, Ping)" src/threevn_hardware/test/test_feetech_protocol.cppExpect:
FF FF 01 02 01 FB. The sum is01 + 02 + 01 = 04, and its complement isFB.Run the three suites that cover the bus: the hand-worked packets, the simulated bus, and the interface against it.
make shell cd /ws/build/threevn_hardware ./test_feetech_protocol | tail -1 ./test_fake_feetech_bus | tail -1 ./test_feetech_system_interface | tail -1Expect:
[ PASSED ] 24 tests.,[ PASSED ] 16 tests.,[ PASSED ] 31 tests.Now misread the manual on purpose. On the host, in
src/threevn_hardware/include/threevn_hardware/feetech_protocol.hpp, findchecksum()and change~sum & 0xFFtosum & 0xFF: the complement, forgotten. Then rebuild that package and run all three again, in the shell.cd /ws && colcon build --packages-select threevn_hardware cd /ws/build/threevn_hardware ./test_feetech_protocol | tail -1 ./test_fake_feetech_bus | tail -1 ./test_feetech_system_interface | tail -1Expect:
13 FAILED TESTSin the first, every one a packet worked out by hand. ThenPASSED 16andPASSED 31: the simulated bus checks with the same wrong function, so it agrees with the wrong driver, and every interface test passes on top of it.Put it back, rebuild, and confirm all three are green.
git checkout src/threevn_hardware/include/threevn_hardware/feetech_protocol.hpp make testExpect:
git checkouton the host.make testrebuilds and runs everything:0 failures.
When it goes wrong
./test_feetech_protocol: No such file or directory.
Why: The test binaries are built into the build volume by make test, and you are in the wrong directory or have not built yet.
Fix: Run make test once, then cd /ws/build/threevn_hardware inside make shell.
You reverted the change and the tests still fail.
Why: The protocol is a header compiled into each test. Editing it changes nothing until the package is rebuilt.
Fix: colcon build --packages-select threevn_hardware in the shell, or make test from the host.
Every packet test fails, not thirteen.
Why: The edit changed more than the complement, or the file did not compile and an older binary is running.
Fix: git diff on the host should show exactly one changed line. Read the build output for errors.
Terms
- Framing
- How a receiver finds where one packet ends and the next begins in a stream of bytes. Here, the two-byte header and a length.
- Checksum
- A short value computed from a packet's bytes and sent with it, so the receiver can tell a corrupted packet from a good one. The Feetech protocol uses one byte, the complement of a sum.
- Agreement by construction
- Two pieces of code written from the same understanding, or sharing the same functions, which therefore agree whether or not the understanding is right. A simulator and a driver built from one reading of a datasheet.
- Little-endian
- Storing a multi-byte number low byte first. The STS3215 does, so count 2048 (
0x0800) goes on the wire as00 08.
Every term in the course: glossary.
Check yourself
Answer in your head first, then open it.
Why did the simulated bus accept packets with a checksum no real servo would?
It checks packets with the same checksum() the driver builds them with. A shared misreading is invisible to it, so it agrees with the driver by construction.
Then what is the simulated bus good for?
Everything that is not a misreading of the protocol: a missing servo, a quiet one, a reply split across two reads, the interface's behaviour over many cycles. It tests the interface's logic, not the reading.
What would check the reading itself, before a servo arrives?
An implementation nobody here wrote. Feetech's own SDK, or the one LeRobot uses, encoding the same packets, would be an independent reading to compare against. Short of that, a real servo.
Stretch
Write out, byte by byte, the sync write that sends servo 1 to count 2048 and servo 2 to count 1024 in one packet. The goal-position register is address 0x2A, two bytes wide. Then check your bytes against the encoder with a test of your own beside the existing ones.
Hint
Broadcast id FE, instruction 83, then the address, the width, and an id followed by its two bytes for each servo. Low byte first: 1024 is 00 04.
One way to do it
FF FF FE 0A 83 2A 02 01 00 08 02 00 04 39. Eight parameter bytes, so the length is 0A; the sum of everything after the header is 0x1C6, whose low byte C6 complemented is 39.