Theme
Tier 5 · lesson 2 of 9 · 35 min

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.

In this lesson

  1. Open Inspect, then servo bus. Find the broadcast id FE, the instruction 83 and the goal register 2A.
  2. Home the arm with h and read servo 1's two goal bytes. Before you look: count 2048 is 0x0800, so which byte comes first?
  3. 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.
  4. Take shoulder_lift past −90°, where its goal falls below 1024 and its high byte below 04.

Do it

  1. Read the wire format, as the header writes it down.

    sed -n 16,50p src/threevn_hardware/include/threevn_hardware/feetech_protocol.hpp
    
  2. Work 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.cpp
    

    Expect: FF FF 01 02 01 FB. The sum is 01 + 02 + 01 = 04, and its complement is FB.

  3. 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 -1
    

    Expect: [ PASSED ] 24 tests., [ PASSED ] 16 tests., [ PASSED ] 31 tests.

  4. Now misread the manual on purpose. On the host, in src/threevn_hardware/include/threevn_hardware/feetech_protocol.hpp, find checksum() and change ~sum & 0xFF to sum & 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 -1
    

    Expect: 13 FAILED TESTS in the first, every one a packet worked out by hand. Then PASSED 16 and PASSED 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.

  5. Put it back, rebuild, and confirm all three are green.

    git checkout src/threevn_hardware/include/threevn_hardware/feetech_protocol.hpp
    make test
    

    Expect: git checkout on the host. make test rebuilds and runs everything: 0 failures.

You will know it worked when: You watched 13 hand-worked packet tests fail while the simulated bus and 31 interface tests passed the same broken checksum, and you can say why.

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 as 00 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.

Going deeper